Skip to content

Commit 8f1ce8d

Browse files
committed
fix: update default cookie name
The default cookie name and README recommendation was incorrect. The recommended prefix is not "Host__", but "__Host-". A minor security advisory will be released for this issue. It isn't a huge vulnerability as there are workarounds available, e.g. you can set your own cookieName.
1 parent c4cbfbe commit 8f1ce8d

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ When creating your csrfSync, you have a few options available for configuration,
154154
```js
155155
const doubleCsrfUtilities = doubleCsrf({
156156
getSecret, // A function that optionally takes the request and returns a secret
157-
cookieName = "Host__psifi.x-csrf-token", // The name of the cookie to be used, recommend using Host prefix.
157+
cookieName = "__Host-psifi.x-csrf-token", // The name of the cookie to be used, recommend using Host prefix.
158158
cookieOptions: {
159159
httpOnly = true,
160160
sameSite = "lax", // Recommend you make this strict if posible

example/complete/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"license": "ISC",
1313
"dependencies": {
1414
"cookie-parser": "^1.4.6",
15-
"csrf-csrf": "2.2.0",
15+
"csrf-csrf": "2.2.1",
1616
"express": "^4.18.1"
1717
}
1818
}

example/simple/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"author": "psibean",
1212
"license": "ISC",
1313
"dependencies": {
14-
"csrf-csrf": "2.2.0",
14+
"csrf-csrf": "2.2.1",
1515
"express": "^4.18.1",
1616
"cookie-parser": "^1.4.6"
1717
}

example/simple/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const port = 5555;
1010
// In production, ensure you're using cors and helmet and have proper configuration.
1111
const { generateToken, doubleCsrfProtection } = doubleCsrf({
1212
getSecret: () => "this is a test", // NEVER DO THIS
13-
cookieName: "x-csrf-test", // Prefer HOST__ prefixed names if possible
13+
cookieName: "x-csrf-test", // Prefer "__Host-" prefixed names if possible
1414
cookieOptions: { sameSite: false, secure: false, signed: true }, // not ideal for production, development only
1515
});
1616

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface DoubleCsrfUtilities {
6161

6262
export function doubleCsrf({
6363
getSecret,
64-
cookieName = "Host__psifi.x-csrf-token",
64+
cookieName = "__Host-psifi.x-csrf-token",
6565
cookieOptions: {
6666
httpOnly = true,
6767
sameSite = "lax",

src/tests/testsuite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const createTestSuite: CreateTestsuite = (name, doubleCsrfOptions) => {
3030
} = doubleCsrf({ ...doubleCsrfOptions });
3131

3232
const {
33-
cookieName = "Host__psifi.x-csrf-token",
33+
cookieName = "__Host-psifi.x-csrf-token",
3434
cookieOptions: {
3535
signed = false,
3636
path = "/",

0 commit comments

Comments
 (0)