Skip to content

Commit b3ca280

Browse files
conorluddyclaude
andcommitted
fix(security): explicit JWT algorithm; body size limit
Restrict JWT sign/verify to HS256 explicitly β€” prevents algorithm confusion attacks if the library ever changes its default or an attacker crafts a token with alg:none. Add express.json({ limit: '10kb' }) to make the default body size limit explicit and prevent oversized payload abuse. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7391152 commit b3ca280

4 files changed

Lines changed: 5 additions & 4 deletions

File tree

β€Žpackage-lock.jsonβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žsrc/index.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if (process.env.NODE_ENV === 'development') {
4242
app.disable('x-powered-by')
4343
app.use(helmet())
4444
app.use(rateLimiter)
45-
app.use(express.json())
45+
app.use(express.json({ limit: '10kb' }))
4646

4747
// Health check
4848
app.get('/health', (_req, res) => {

β€Žsrc/middleware/auth/jsonWebTokens.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const authenticateToken = (req: ResidentRequest, _res: Response<ResidentR
2020
throw new InternalServerError(MESSAGES.JWT_SECRET_NOT_DEFINED)
2121
}
2222

23-
jwt.verify(token, secret, (err, user) => {
23+
jwt.verify(token, secret, { algorithms: ['HS256'] }, (err, user) => {
2424
if (err) {
2525
throw new UnauthorizedError(MESSAGES.TOKEN_INVALID)
2626
}

β€Žsrc/utils/generateJwt.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const generateJwtFromUser = (user: User | SafeUser | PublicUser, expiryOv
1212
throw new Error(MESSAGES.JWT_SECRET_NOT_FOUND)
1313
}
1414
return jwt.sign(userToPublicUser(user), JWT_TOKEN_SECRET, {
15+
algorithm: 'HS256',
1516
expiresIn: (expiryOverride ?? EXPIRATION_JWT_TOKEN ?? DEFAULT_EXPIRATION) as StringValue,
1617
})
1718
}

0 commit comments

Comments
Β (0)