Skip to content

Commit

Permalink
fix(core): Improve browserId checks, and add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Apr 18, 2024
1 parent 0ed4671 commit 4ad13ac
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/cli/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const skipBrowserIdCheckEndpoints = [
`/${restEndpoint}/push`,

// We need to exclude binary-data downloading endpoint because we can't send custom headers on `<embed>` tags
`/${restEndpoint}/binary-data`,
`/${restEndpoint}/binary-data/`,

// oAuth callback urls aren't called by the frontend. therefore we can't send custom header on these requests
`/${restEndpoint}/oauth1-credential/callback`,
Expand Down Expand Up @@ -131,15 +131,23 @@ export class AuthService {
// or, If the user has been deactivated (i.e. LDAP users)
user.disabled ||
// or, If the email or password has been updated
jwtPayload.hash !== this.createJWTHash(user) ||
// If the token was issued for another browser session
(!skipBrowserIdCheckEndpoints.includes(req.baseUrl) &&
jwtPayload.browserId &&
(!req.browserId || jwtPayload.browserId !== this.hash(req.browserId)))
jwtPayload.hash !== this.createJWTHash(user)
) {
throw new AuthError('Unauthorized');
}

// Check if the token was issued for another browser session, ignoring the endpoints that can't send custom headers
const endpoint = req.route ? `${req.baseUrl}${req.route.path}` : req.baseUrl;

Check failure on line 140 in packages/cli/src/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unsafe member access .path on an `any` value
if (req.method === 'GET' && skipBrowserIdCheckEndpoints.includes(endpoint)) {
this.logger.debug(`Skipped browserId check on ${endpoint}`);
} else if (
jwtPayload.browserId &&
(!req.browserId || jwtPayload.browserId !== this.hash(req.browserId))
) {
this.logger.warn(`browserId check failed on ${endpoint}`);
throw new AuthError('Unauthorized');
}

if (jwtPayload.exp * 1000 - Date.now() < this.jwtRefreshTimeout) {
this.logger.debug('JWT about to expire. Will be refreshed');
this.issueCookie(res, user, jwtPayload.browserId);
Expand Down

0 comments on commit 4ad13ac

Please sign in to comment.