Skip to content

Commit 77fbe3a

Browse files
committed
Strict-Transport-Security: fix documentation for default max-age
This changed in Helmet v8 but I forgot to update the docs. Thanks to [@kristinademeshchik on GitHub][kristinademeshchik] for pointing this out in [#479]. [#479]: #479 [kristinademeshchik]: https://github.com/kristinademeshchik
1 parent 632e629 commit 77fbe3a

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,17 @@ You can use this as standalone middleware with `app.use(helmet.referrerPolicy())
358358
Default:
359359

360360
```http
361-
Strict-Transport-Security: max-age=15552000; includeSubDomains
361+
Strict-Transport-Security: max-age=31536000; includeSubDomains
362362
```
363363

364364
The `Strict-Transport-Security` header tells browsers to prefer HTTPS instead of insecure HTTP. See [the documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security) for more.
365365

366366
```js
367-
// Sets "Strict-Transport-Security: max-age=15552000; includeSubDomains"
367+
// Sets "Strict-Transport-Security: max-age=31536000; includeSubDomains"
368368
app.use(helmet());
369369
```
370370

371-
`maxAge` is the number of seconds browsers should remember to prefer HTTPS. If passed a non-integer, the value is rounded down. It defaults to `15552000`, which is 180 days.
371+
`maxAge` is the number of seconds browsers should remember to prefer HTTPS. If passed a non-integer, the value is rounded down. It defaults to 365 days.
372372

373373
`includeSubDomains` is a boolean which dictates whether to include the `includeSubDomains` directive, which makes this policy extend to subdomains. It defaults to `true`.
374374

middlewares/strict-transport-security/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
This middleware adds the `Strict-Transport-Security` header to the response. This tells browsers, "hey, only use HTTPS for the next period of time". ([See the spec](https://tools.ietf.org/html/rfc6797) for more.) Note that the header won't tell users on HTTP to _switch_ to HTTPS, it will just tell HTTPS users to stick around. You can enforce HTTPS with the [express-enforces-ssl](https://github.com/aredo/express-enforces-ssl) module.
44

5-
This will set the Strict Transport Security header, telling browsers to visit by HTTPS for the next 180 days:
5+
This will set the Strict Transport Security header, telling browsers to visit by HTTPS for the next 365 days:
66

77
```javascript
88
const strictTransportSecurity = require("hsts");
99

10-
// Sets "Strict-Transport-Security: max-age=15552000; includeSubDomains"
10+
// Sets "Strict-Transport-Security: max-age=31536000; includeSubDomains"
1111
app.use(
1212
strictTransportSecurity({
13-
maxAge: 15552000, // 180 days in seconds
13+
maxAge: 31536000, // 365 days in seconds
1414
}),
1515
);
1616
```
@@ -22,7 +22,7 @@ The `includeSubDomains` directive is present by default. If this header is set o
2222
```javascript
2323
app.use(
2424
strictTransportSecurity({
25-
maxAge: 15552000,
25+
maxAge: 31536000,
2626
includeSubDomains: false,
2727
}),
2828
);

test/strict-transport-security.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { check } from "./helpers";
22
import strictTransportSecurity from "../middlewares/strict-transport-security";
33

44
describe("Strict-Transport-Security middleware", () => {
5-
it('by default, sets max-age to 180 days and adds "includeSubDomains"', async () => {
5+
it('by default, sets max-age to 365 days and adds "includeSubDomains"', async () => {
66
expect(31536000).toStrictEqual(365 * 24 * 60 * 60);
77

88
const expectedHeaders = {

0 commit comments

Comments
 (0)