Skip to content

Commit 99bb8f2

Browse files
committed
#375: required URL validation for origin
1 parent 856a9d5 commit 99bb8f2

File tree

8 files changed

+26
-16
lines changed

8 files changed

+26
-16
lines changed

docker/keycloak/comify-realm.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@
666666
"alwaysDisplayInConsole": false,
667667
"clientAuthenticatorType": "client-secret",
668668
"redirectUris": [
669-
"http://a.comify.local:3000/rpc/domain/authentication/login",
670669
"http://localhost:3000/rpc/domain/authentication/login",
671670
"http://localhost:5173/rpc/domain/authentication/login"
672671
],

src/domain/authentication/login/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getCreatorByEmail from '^/domain/creator/getByEmail';
55
import registerCreator from '^/domain/creator/register';
66
import { type Tenant } from '^/domain/tenant';
77

8-
import type { Requester } from '../types';
8+
import { type Requester } from '../types';
99

1010
export default async function login(identity: Identity, tenant: Tenant): Promise<Requester>
1111
{

src/domain/creator/create/validateData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { ValidationSchema } from '^/integrations/validation';
33
import validator from '^/integrations/validation';
44

5-
import { optionalIdValidation } from '^/domain/definitions';
5+
import { optionalIdValidation, requiredIdValidation } from '^/domain/definitions';
66

77
import InvalidCreator from '../InvalidCreator';
88
import { fullNameValidation } from '../definitions';
@@ -19,7 +19,7 @@ const schema: ValidationSchema =
1919
required: true
2020
}
2121
},
22-
tenantId: optionalIdValidation,
22+
tenantId: requiredIdValidation,
2323
portraitId: optionalIdValidation
2424
};
2525

src/domain/post/create/validateData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { ValidationModel } from './types';
1010
const schema: ValidationSchema =
1111
{
1212
creatorId: requiredIdValidation,
13-
tenantId: optionalIdValidation,
13+
tenantId: requiredIdValidation,
1414
comicId: optionalIdValidation,
1515
commentId: optionalIdValidation,
1616
parentId: optionalIdValidation

src/integrations/runtime/middlewares/OriginMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default class OriginMiddleware implements Middleware
7575

7676
#validateOriginValue(value: string | undefined): void
7777
{
78-
const result = validator.validate({ url: value }, schema);
78+
const result = validator.validate({ origin: value }, schema);
7979

8080
if (result.invalid)
8181
{

src/integrations/runtime/middlewares/RequesterMiddleware.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ export default class RequesterMiddleware implements Middleware
1717
request.setHeader('Authorization', this.#authorization);
1818
}
1919

20-
const response = await next();
21-
22-
if (response.hasHeader('Authorization'))
20+
try
2321
{
24-
this.#authorization = response.getHeader('Authorization')!;
22+
const response = await next();
23+
24+
if (response.hasHeader('Authorization'))
25+
{
26+
this.#authorization = response.getHeader('Authorization')!;
27+
}
28+
29+
return response;
2530
}
31+
catch (error)
32+
{
33+
if (error?.constructor?.name === 'Unauthorized')
34+
{
35+
this.#authorization = undefined;
36+
}
2637

27-
return response;
38+
throw error;
39+
}
2840
}
2941
}

src/webui/components/common/hooks/useTenant.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import { useCallback } from 'react';
33

4+
import { tenant } from '^/domain/tenant';
45
import getByOriginConverted from '^/domain/tenant/getByOriginConverted';
56

67
import { useLoadData } from '^/webui/hooks';
@@ -9,9 +10,7 @@ export function useTenant()
910
{
1011
const getTenant = useCallback(async () =>
1112
{
12-
const tenant = await getByOriginConverted('');
13-
14-
return tenant;
13+
return await getByOriginConverted(tenant.origin);
1514

1615
}, []);
1716

test/domain/tenant/fixtures/values.fixtures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export const VALUES =
55
TENANT1: 'example.com'
66
},
77
ORIGINS: {
8-
FIRST: 'alpha.example.com',
9-
SECOND: 'beta.example.com',
8+
FIRST: 'http://alpha.example.com',
9+
SECOND: 'http://beta.example.com',
1010
UNKNOWN: 'unknown'
1111
}
1212
};

0 commit comments

Comments
 (0)