-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Describe your changes Fixes https://linear.app/nango/issue/NAN-1339/[pen-test]-fix-security-misconfiguration-exposed-in-pen-test Fixes https://linear.app/nango/issue/NAN-1340/[pen-test]-content-security-policy-csp-header-not-implemented Fixes https://linear.app/nango/issue/NAN-1454/remediate-medium-severity-vulnerabilities-from-pen-test - Add helmet.js to fix all notice related to SOC2 - CSP - No Sniff - No embed in iframe - HSTS - Setup stricter cors Allows all origin for public api and expose headers, restrict private api
- Loading branch information
1 parent
7181c1c
commit 2c009d0
Showing
7 changed files
with
139 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { basePublicUrl, baseUrl } from '@nangohq/utils'; | ||
import type { RequestHandler } from 'express'; | ||
import helmet from 'helmet'; | ||
|
||
export function securityMiddlewares(): RequestHandler[] { | ||
const hostPublic = basePublicUrl; | ||
const hostApi = baseUrl; | ||
const reportOnly = process.env['CSP_REPORT_ONLY']; | ||
|
||
return [ | ||
helmet.xssFilter(), | ||
helmet.noSniff(), | ||
helmet.ieNoOpen(), | ||
helmet.frameguard({ action: 'sameorigin' }), | ||
helmet.dnsPrefetchControl(), | ||
helmet.hsts({ | ||
maxAge: 5184000 | ||
}), | ||
// == "Content-Security-Policy" | ||
helmet.contentSecurityPolicy({ | ||
reportOnly: reportOnly !== 'false', | ||
directives: { | ||
defaultSrc: ["'self'", hostPublic, hostApi], | ||
childSrc: "'self'", | ||
connectSrc: ["'self'", 'https://*.google-analytics.com', 'https://*.sentry.io', hostPublic, hostApi, 'https://*.posthog.com'], | ||
fontSrc: ["'self'", 'https://*.googleapis.com', 'https://*.gstatic.com'], | ||
frameSrc: ["'self'", 'https://accounts.google.com'], | ||
imgSrc: ["'self'", 'data:', hostPublic, hostApi, 'https://*.google-analytics.com', 'https://*.googleapis.com', 'https://*.posthog.com'], | ||
manifestSrc: "'self'", | ||
mediaSrc: "'self'", | ||
objectSrc: "'self'", | ||
scriptSrc: [ | ||
"'self'", | ||
"'unsafe-eval'", | ||
"'unsafe-inline'", | ||
hostPublic, | ||
hostApi, | ||
'https://*.google-analytics.com', | ||
'https://*.googleapis.com', | ||
'https://apis.google.com', | ||
'https://*.posthog.com' | ||
], | ||
styleSrc: ['blob:', "'self'", "'unsafe-inline'", 'https://*.googleapis.com', hostPublic, hostApi], | ||
workerSrc: ['blob:', "'self'", hostPublic, hostApi, 'https://*.googleapis.com', 'https://*.posthog.com'] | ||
} | ||
}) | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters