Skip to content

Commit b94ac0e

Browse files
committed
fix(backend:auth): update token expiration and enforce no-store Cache-Control headers
1 parent 413dd45 commit b94ac0e

6 files changed

Lines changed: 15 additions & 5 deletions

File tree

backend/src/applications/links/links.controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Get, Param, Post, Req, Res, StreamableFile, UseGuards } from '@nestjs/common'
1+
import { Body, Controller, Get, Header, Param, Post, Req, Res, StreamableFile, UseGuards } from '@nestjs/common'
22
import { Throttle } from '@nestjs/throttler'
33
import { FastifyReply, FastifyRequest } from 'fastify'
44
import { AuthTokenOptional } from '../../authentication/decorators/auth-token-optional.decorator'
@@ -31,6 +31,7 @@ export class LinksController {
3131
}
3232

3333
@Get(`${PUBLIC_LINKS_ROUTE.ACCESS}/:uuid`)
34+
@Header('Cache-Control', 'no-store')
3435
@UseGuards(AuthRateLimitGuard)
3536
linkAccess(
3637
@GetUser() user: UserModel,
@@ -54,6 +55,7 @@ export class LinksController {
5455
}
5556

5657
@Post(`${PUBLIC_LINKS_ROUTE.AUTH}/:uuid`)
58+
@Header('Cache-Control', 'no-store')
5759
@UseGuards(AuthRateLimitGuard)
5860
linkAuthentication(
5961
@GetUser() user: UserModel,

backend/src/applications/sync/sync.controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Copy,
55
Delete,
66
Get,
7+
Header,
78
HttpException,
89
HttpStatus,
910
Move,
@@ -70,13 +71,15 @@ export class SyncController {
7071
}
7172

7273
@Post(SYNC_ROUTE.REGISTER)
74+
@Header('Cache-Control', 'no-store')
7375
@AuthTokenSkip()
7476
@UseGuards(AuthRateLimitGuard)
7577
register(@Body() syncClientRegistrationDto: SyncClientRegistrationDto, @Req() req: FastifyRequest): Promise<SyncClientAuthRegistration> {
7678
return this.syncClientsManager.register(syncClientRegistrationDto, req.ip)
7779
}
7880

7981
@Post(SYNC_ROUTE.REGISTER_AUTH)
82+
@Header('Cache-Control', 'no-store')
8083
@UserHavePermission(USER_PERMISSION.DESKTOP_APP)
8184
@UseGuards(UserPermissionsGuard)
8285
registerWithAuth(
@@ -101,6 +104,7 @@ export class SyncController {
101104
}
102105

103106
@Post(`${SYNC_ROUTE.AUTH}/:type`)
107+
@Header('Cache-Control', 'no-store')
104108
@AuthTokenSkip()
105109
@UseGuards(AuthRateLimitGuard)
106110
authenticate(

backend/src/applications/users/users.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ the password-attempt limit does not suspend the account.
3535
`isActive` is the durable administrative switch for a local user record:
3636

3737
- `isActive: false` is rejected by local password and app-password paths as well as by the LDAP and OIDC provider flows;
38-
- authenticated requests and token refreshes reload the local user record, so disabling the account also invalidates existing sessions;
38+
- new authentication and token refreshes reload the local user record and reject an inactive account. Already-issued access tokens and positive
39+
WebDAV authentication cache entries remain usable until they expire;
3940
- the account remains disabled until an administrator reactivates it; there is no automatic expiration;
4041
- reactivating the account resets `passwordAttempts` to zero.
4142

backend/src/authentication/auth.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class AuthTokenAccessConfig {
1717

1818
@IsString()
1919
@IsNotEmpty()
20-
expiration = '30m'
20+
expiration = '15m'
2121
}
2222

2323
export class AuthTokenRefreshConfig {

backend/src/authentication/auth.controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ export class AuthController {
5151
}
5252

5353
@Post(AUTH_ROUTE.TOKEN)
54+
@Header('Cache-Control', 'no-store')
5455
@AuthTokenSkip()
5556
@UseGuards(AuthRateLimitGuard, AuthLocalGuard, AuthTwoFaVerificationWithoutPasswordGuard)
5657
token(@GetUser() user: UserModel): Promise<TokenResponseDto> {
5758
return this.authManager.getTokens(user)
5859
}
5960

6061
@Post(AUTH_ROUTE.TOKEN_REFRESH)
62+
@Header('Cache-Control', 'no-store')
6163
@AuthTokenSkip()
6264
@UseGuards(AuthTokenRefreshGuard)
6365
refreshToken(@GetUser() user: UserModel): Promise<TokenResponseDto> {
@@ -81,6 +83,7 @@ export class AuthController {
8183
}
8284

8385
@Post(`${AUTH_ROUTE.TWO_FA_BASE}/${AUTH_ROUTE.TWO_FA_ENABLE}`)
86+
@Header('Cache-Control', 'no-store')
8487
@UseGuards(AuthRateLimitGuard, UserRolesGuard)
8588
@UserHaveRole(USER_ROLE.USER)
8689
twoFaEnable(@Body() body: TwoFaVerifyWithPasswordDto, @Req() req: FastifyAuthenticatedRequest): Promise<TwoFaVerifyResult> {

environment/environment.dist.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ auth:
100100
# required
101101
secret:
102102
# token expiration = cookie maxAge
103-
# default: `30m`
104-
expiration: 30m
103+
# default: `15m`
104+
expiration: 15m
105105
refresh:
106106
# Used for token and cookie signatures
107107
# required

0 commit comments

Comments
 (0)