Skip to content

Commit

Permalink
Fix token validation on graphql IntrospectionQuery (twentyhq#5255)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
Weiko committed May 3, 2024
1 parent 1430a67 commit 30ffe01
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
}
Expand Down

0 comments on commit 30ffe01

Please sign in to comment.