Skip to content

Commit 7cb20ea

Browse files
committed
Update homepage with new Helmet readme
1 parent 51434bf commit 7cb20ea

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

content/_index.md

+15-28
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,17 @@
22
title: "Helmet.js"
33
---
44

5-
Helmet helps secure Express apps by setting HTTP response headers.
6-
7-
## Get started
8-
9-
Here's a sample Express app that uses Helmet:
5+
Help secure Express apps by setting HTTP response headers.
106

117
```javascript
12-
import express from "express";
138
import helmet from "helmet";
149

1510
const app = express();
1611

17-
// Use Helmet!
1812
app.use(helmet());
19-
20-
app.get("/", (req, res) => {
21-
res.send("Hello world!");
22-
});
23-
24-
app.listen(8000);
2513
```
2614

27-
You can also `require("helmet")` if you prefer.
28-
29-
By default, Helmet sets the following headers:
15+
Helmet sets the following headers by default:
3016

3117
- [`Content-Security-Policy`](#content-security-policy): A powerful allow-list of what can happen on your page which mitigates many attacks
3218
- [`Cross-Origin-Opener-Policy`](#cross-origin-opener-policy): Helps process-isolate your page
@@ -45,8 +31,7 @@ By default, Helmet sets the following headers:
4531
Each header can be configured. For example, here's how you configure the `Content-Security-Policy` header:
4632

4733
```js
48-
// This sets custom options for the
49-
// Content-Security-Policy header.
34+
// Configure the Content-Security-Policy header.
5035
app.use(
5136
helmet({
5237
contentSecurityPolicy: {
@@ -61,8 +46,7 @@ app.use(
6146
Headers can also be disabled. For example, here's how you disable the `Content-Security-Policy` and `X-Download-Options` headers:
6247

6348
```js
64-
// This disables the Content-Security-Policy
65-
// and X-Download-Options headers.
49+
// Disable the Content-Security-Policy and X-Download-Options headers
6650
app.use(
6751
helmet({
6852
contentSecurityPolicy: false,
@@ -84,7 +68,7 @@ Content-Security-Policy: default-src 'self';base-uri 'self';font-src 'self' http
8468

8569
The `Content-Security-Policy` header mitigates a large number of attacks, such as [cross-site scripting][XSS]. See [MDN's introductory article on Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP).
8670

87-
This header is powerful but likely requires some configuration.
71+
This header is powerful but likely requires some configuration for your specific app.
8872

8973
To configure this header, pass an object with a nested `directives` object. Each key is a directive name in camel case (such as `defaultSrc`) or kebab case (such as `default-src`). Each value is an array (or other iterable) of strings or functions for that directive. If a function appears in the array, it will be called with the request and response objects.
9074

@@ -105,7 +89,8 @@ app.use(
10589

10690
```js
10791
// Sets the `script-src` directive to
108-
// "'self' 'nonce-e33...'" (or similar)
92+
// "'self' 'nonce-e33cc...'"
93+
// (or similar)
10994
app.use((req, res, next) => {
11095
res.locals.cspNonce = crypto.randomBytes(32).toString("hex");
11196
next();
@@ -142,7 +127,7 @@ app.use(
142127
);
143128
```
144129

145-
You can get the default directives object with `helmet.contentSecurityPolicy.getDefaultDirectives()`. Here is the default policy (whitespace added for readability):
130+
You can get the default directives object with `helmet.contentSecurityPolicy.getDefaultDirectives()`. Here is the default policy (formatted for readability):
146131

147132
```
148133
default-src 'self';
@@ -160,7 +145,7 @@ upgrade-insecure-requests
160145

161146
The `default-src` directive can be explicitly disabled by setting its value to `helmet.contentSecurityPolicy.dangerouslyDisableDefaultSrc`, but this is not recommended.
162147

163-
You can set the [`Content-Security-Policy-Report-Only`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only) instead.
148+
You can set the [`Content-Security-Policy-Report-Only`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only) instead:
164149

165150
```javascript
166151
// Sets the Content-Security-Policy-Report-Only header
@@ -261,7 +246,7 @@ Default:
261246
Cross-Origin-Resource-Policy: same-origin
262247
```
263248

264-
The `Cross-Origin-Resource-Policy` header blocks others from loading your resources cross-origin in some cases. For more, see ["Consider deploying Cross-Origin Resource Policy](https://resourcepolicy.fyi/) and [MDN's article on this header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy).
249+
The `Cross-Origin-Resource-Policy` header blocks others from loading your resources cross-origin in some cases. For more, see ["Consider deploying Cross-Origin Resource Policy"](https://resourcepolicy.fyi/) and [MDN's article on this header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy).
265250

266251
```js
267252
// Sets "Cross-Origin-Resource-Policy: same-origin"
@@ -375,17 +360,17 @@ You can use this as standalone middleware with `app.use(helmet.referrerPolicy())
375360
Default:
376361

377362
```http
378-
Strict-Transport-Security: max-age=15552000; includeSubDomains
363+
Strict-Transport-Security: max-age=31536000; includeSubDomains
379364
```
380365

381366
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.
382367

383368
```js
384-
// Sets "Strict-Transport-Security: max-age=15552000; includeSubDomains"
369+
// Sets "Strict-Transport-Security: max-age=31536000; includeSubDomains"
385370
app.use(helmet());
386371
```
387372

388-
`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.
373+
`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.
389374

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

@@ -432,6 +417,8 @@ app.use(
432417
);
433418
```
434419

420+
You may wish to disable this header for local development, as it can make your browser force redirects from `http://localhost` to `https://localhost`, which may not be desirable if you develop multiple apps using `localhost`. See [this issue](https://github.com/helmetjs/helmet/issues/451) for more discussion.
421+
435422
You can use this as standalone middleware with `app.use(helmet.strictTransportSecurity())`.
436423

437424
</details>

0 commit comments

Comments
 (0)