Skip to content

Commit

Permalink
fix: Add samesite setting for XSRF (#257)
Browse files Browse the repository at this point in the history
* Add samesite setting for XSRF

* Update package version number for cookie samesite release

---------

Co-authored-by: Andy Wilkins <49269487+andywilkinshmcts@users.noreply.github.com>
  • Loading branch information
connorpgpmcelroy and andywilkinshmcts authored Dec 18, 2024
1 parent 57c9c9e commit 6ee0223
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-node-lib",
"version": "2.29.6",
"version": "2.29.7",
"description": "Common nodejs library components for XUI",
"main": "dist/index",
"types": "dist/index.d.ts",
Expand Down
9 changes: 7 additions & 2 deletions src/auth/models/strategy.class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as events from 'events'
import { NextFunction, Request, RequestHandler, Response, Router } from 'express'
import { CookieOptions, NextFunction, Request, RequestHandler, Response, Router } from 'express'
import passport from 'passport'
import { AUTH } from '../auth.constants'
import jwtDecode from 'jwt-decode'
Expand Down Expand Up @@ -450,9 +450,14 @@ export abstract class Strategy extends events.EventEmitter {
const csrfProtection = csrf({
value: this.getCSRFValue,
})
// cookie options added via EXUI-986, fortify issues
const cookieOptions: CookieOptions = {
sameSite: 'none',
secure: true,
}
/* istanbul ignore next */
this.router.use(csrfProtection, (req, res, next) => {
res.cookie('XSRF-TOKEN', req.csrfToken())
res.cookie('XSRF-TOKEN', req.csrfToken(), cookieOptions)
next()
})
}
Expand Down

0 comments on commit 6ee0223

Please sign in to comment.