mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-23 14:03:35 +03:00
Fix token validation on graphql IntrospectionQuery (#5255)
## Context We recently introduced a change that now throws a 401 if the token is invalid or expired. The first implementation is using an allow list and 'IntrospectionQuery' was missing so the playground was broken. The check has been updated and we now only check the excludedOperations list if a token is not present. This is because some operations can be both used as loggedIn and loggedOut so we want to validate the token for those sometimes (and set the workspace, user, cache version, etc). Still not a very clean solution imho.
This commit is contained in:
parent
1430a6745c
commit
30ffe0160e
@ -14,6 +14,7 @@ export class UserWorkspaceMiddleware implements NestMiddleware {
|
||||
|
||||
async use(req: Request, res: Response, next: NextFunction) {
|
||||
const body = req.body;
|
||||
|
||||
const excludedOperations = [
|
||||
'GetClientConfig',
|
||||
'GetCurrentUser',
|
||||
@ -24,12 +25,12 @@ export class UserWorkspaceMiddleware implements NestMiddleware {
|
||||
'Verify',
|
||||
'SignUp',
|
||||
'RenewToken',
|
||||
'IntrospectionQuery',
|
||||
];
|
||||
|
||||
if (
|
||||
body &&
|
||||
body.operationName &&
|
||||
excludedOperations.includes(body.operationName)
|
||||
!this.tokenService.isTokenPresent(req) &&
|
||||
(!body?.operationName || excludedOperations.includes(body.operationName))
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user