-
Notifications
You must be signed in to change notification settings - Fork 461
move away from express helmet #927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d5069e0
43b7b3b
207ea9e
a9e09a3
db540cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import crypto from 'node:crypto' | ||
| import { helmet } from '@nichtsam/helmet/node-http' | ||
| import { createRequestHandler } from '@react-router/express' | ||
| import * as Sentry from '@sentry/node' | ||
| import { ip as ipAddress } from 'address' | ||
|
|
@@ -8,7 +9,6 @@ import compression from 'compression' | |
| import express from 'express' | ||
| import rateLimit from 'express-rate-limit' | ||
| import getPort, { portNumbers } from 'get-port' | ||
| import helmet from 'helmet' | ||
| import morgan from 'morgan' | ||
| import { type ServerBuild } from 'react-router' | ||
|
|
||
|
|
@@ -68,6 +68,11 @@ app.use(compression()) | |
| // http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header | ||
| app.disable('x-powered-by') | ||
|
|
||
| app.use((_, res, next) => { | ||
| helmet(res) | ||
| next() | ||
| }) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you help me understand what this does, why we need this, and what's in the entry.server.tsx? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines ensure that all routes are protected, not just Remix routes. When working on CSP and other security headers, I realized that some security headers are specific to the response type. Some apply to all types of resources, such as To improve clarity and control, I categorized the headers into three groups: Here, we apply the general security headers, ensuring that assets, JS files, and other resources are covered. In The main I hope this is clear, feel free to ask for more details! |
||
| if (viteDevServer) { | ||
| app.use(viteDevServer.middlewares) | ||
| } else { | ||
|
|
@@ -110,39 +115,6 @@ app.use((_, res, next) => { | |
| next() | ||
| }) | ||
|
|
||
| app.use( | ||
| helmet({ | ||
| xPoweredBy: false, | ||
| referrerPolicy: { policy: 'same-origin' }, | ||
| crossOriginEmbedderPolicy: false, | ||
| contentSecurityPolicy: { | ||
| // NOTE: Remove reportOnly when you're ready to enforce this CSP | ||
| reportOnly: true, | ||
| directives: { | ||
| 'connect-src': [ | ||
| MODE === 'development' ? 'ws:' : null, | ||
| process.env.SENTRY_DSN ? '*.sentry.io' : null, | ||
| "'self'", | ||
| ].filter(Boolean), | ||
| 'font-src': ["'self'"], | ||
| 'frame-src': ["'self'"], | ||
| 'img-src': ["'self'", 'data:'], | ||
| 'script-src': [ | ||
| "'strict-dynamic'", | ||
| "'self'", | ||
| // @ts-expect-error | ||
| (_, res) => `'nonce-${res.locals.cspNonce}'`, | ||
| ], | ||
| 'script-src-attr': [ | ||
| // @ts-expect-error | ||
| (_, res) => `'nonce-${res.locals.cspNonce}'`, | ||
| ], | ||
| 'upgrade-insecure-requests': null, | ||
| }, | ||
| }, | ||
| }), | ||
| ) | ||
|
|
||
| // When running tests or running in development, we want to effectively disable | ||
| // rate limiting because playwright tests are very fast and we don't want to | ||
| // have to wait for the rate limit to reset between tests. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nitpick, but is there any chance you could add exports config in your package.json so that we don't have to dive deep into your package? Instead, this could be more like this for example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also didn't like that, but didn't know how to path them better, thanks for the idea!
I will update the package to simplify the import path.