Skip to content

Commit 12180a1

Browse files
committed
Update index to match latest Helmet README
1 parent 966dfcb commit 12180a1

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

content/_index.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Helmet.js"
33
---
44

5-
Help secure Express apps by setting HTTP response headers.
5+
Security headers for Express.js apps.
66

77
```javascript
88
import helmet from "helmet";
@@ -28,7 +28,7 @@ Helmet sets the following headers by default:
2828
- [`X-Powered-By`](#x-powered-by): Info about the web server. Removed because it could be used in simple attacks
2929
- [`X-XSS-Protection`](#x-xss-protection): Legacy header that tries to mitigate [XSS attacks][XSS], but makes things worse, so Helmet disables it
3030

31-
Each header can be configured. For example, here's how you configure the `Content-Security-Policy` header:
31+
Each header can be configured. For example, here's how to configure the `Content-Security-Policy` header:
3232

3333
```js
3434
// Configure the Content-Security-Policy header.
@@ -161,6 +161,23 @@ app.use(
161161
);
162162
```
163163

164+
`upgrade-insecure-requests`, a directive that causes browsers to upgrade HTTP to HTTPS, is set by default. You may wish to avoid this in development, as you may not be developing with HTTPS. Notably, Safari will upgrade `http://localhost` to `https://localhost`, which can cause problems. To work around this, you may wish to disable the `upgrade-insecure-requests` directive in development. For example:
165+
166+
```js
167+
const isDevelopment = app.get("env") === "development";
168+
169+
app.use(
170+
helmet({
171+
contentSecurityPolicy: {
172+
directives: {
173+
// Disable upgrade-insecure-requests in development.
174+
"upgrade-insecure-requests": isDevelopment ? null : [],
175+
},
176+
},
177+
}),
178+
);
179+
```
180+
164181
Helmet performs very little validation on your CSP. You should rely on CSP checkers like [CSP Evaluator](https://csp-evaluator.withgoogle.com/) instead.
165182

166183
To disable the `Content-Security-Policy` header:

0 commit comments

Comments
 (0)