Skip to content
This repository was archived by the owner on Jun 29, 2025. It is now read-only.

Commit 69752b8

Browse files
committed
fix: enable secure cookies if app url starts with https
1 parent ee73293 commit 69752b8

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

backend/src/auth/auth.controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,17 @@ export class AuthController {
173173
@Res({ passthrough: true }) response: Response,
174174
) {
175175
await this.authService.signOut(request.cookies.access_token);
176-
response.cookie("access_token", "accessToken", { maxAge: -1 });
176+
177+
const isSecure = this.config.get("general.appUrl").startsWith("https");
178+
response.cookie("access_token", "accessToken", {
179+
maxAge: -1,
180+
secure: isSecure,
181+
});
177182
response.cookie("refresh_token", "", {
178183
path: "/api/auth/token",
179184
httpOnly: true,
180185
maxAge: -1,
186+
secure: isSecure,
181187
});
182188
}
183189

backend/src/auth/auth.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,19 @@ export class AuthService {
272272
refreshToken?: string,
273273
accessToken?: string,
274274
) {
275+
const isSecure = this.config.get("general.appUrl").startsWith("https");
275276
if (accessToken)
276277
response.cookie("access_token", accessToken, {
277278
sameSite: "lax",
279+
secure: isSecure,
278280
maxAge: 1000 * 60 * 60 * 24 * 30 * 3, // 3 months
279281
});
280282
if (refreshToken)
281283
response.cookie("refresh_token", refreshToken, {
282284
path: "/api/auth/token",
283285
httpOnly: true,
284286
sameSite: "strict",
287+
secure: isSecure,
285288
maxAge: 1000 * 60 * 60 * this.config.get("general.sessionDuration"),
286289
});
287290
}

backend/src/user/user.controller.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ import { UpdateOwnUserDTO } from "./dto/updateOwnUser.dto";
1919
import { UpdateUserDto } from "./dto/updateUser.dto";
2020
import { UserDTO } from "./dto/user.dto";
2121
import { UserSevice } from "./user.service";
22+
import { ConfigService } from "../config/config.service";
2223

2324
@Controller("users")
2425
export class UserController {
25-
constructor(private userService: UserSevice) {}
26+
constructor(
27+
private userService: UserSevice,
28+
private config: ConfigService,
29+
) {}
2630

2731
// Own user operations
2832
@Get("me")
@@ -49,11 +53,17 @@ export class UserController {
4953
@GetUser() user: User,
5054
@Res({ passthrough: true }) response: Response,
5155
) {
52-
response.cookie("access_token", "accessToken", { maxAge: -1 });
56+
const isSecure = this.config.get("general.appUrl").startsWith("https");
57+
58+
response.cookie("access_token", "accessToken", {
59+
maxAge: -1,
60+
secure: isSecure,
61+
});
5362
response.cookie("refresh_token", "", {
5463
path: "/api/auth/token",
5564
httpOnly: true,
5665
maxAge: -1,
66+
secure: isSecure,
5767
});
5868
return new UserDTO().from(await this.userService.delete(user.id));
5969
}

0 commit comments

Comments
 (0)