Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issecure #664

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/routes/v2/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const CSRF_COOKIE_NAME = "isomer-csrf"
const COOKIE_NAME = "isomercms"

class AuthRouter {
constructor({ authService, authenticationMiddleware, apiLogger, rateLimiter }) {
constructor({
authService,
authenticationMiddleware,
apiLogger,
rateLimiter,
}) {
this.authService = authService
this.authenticationMiddleware = authenticationMiddleware
this.apiLogger = apiLogger
Expand Down Expand Up @@ -46,7 +51,7 @@ class AuthRouter {
const cookieSettings = {
expires: csrfTokenExpiry,
httpOnly: true,
secure: isSecure(),
secure: isSecure,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, this seems error prone, could we define CookieSettings interface for stricter type setting?
(I am assuming this is low effort, not sure in how many other places this object is being used in)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAHA just realised this JS file psps

}
res.cookie(CSRF_COOKIE_NAME, cookieToken, cookieSettings)
return res.redirect(redirectUrl)
Expand Down
4 changes: 1 addition & 3 deletions src/utils/auth-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ const { config } = require("@config/config")

const NODE_ENV = config.get("env")

function isSecure() {
return NODE_ENV !== "dev" && NODE_ENV !== "test"
}
const isSecure = NODE_ENV !== "dev" && NODE_ENV !== "test"

module.exports = {
isSecure,
Expand Down