-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add missing security headers #2362
Open
snowteamer
wants to merge
8
commits into
master
Choose a base branch
from
add-security-headers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5d9f6c8
Add missing security headers
snowteamer b036ee4
Review feedback
snowteamer 0cacfb3
Update security headers
snowteamer e0baaf5
Use .browserupgrade for fallback element
snowteamer ad50668
Fix CSP for BrowserSync and file attachments in chat
snowteamer e26b1bd
Fix favicon not loading in Chrome
snowteamer 4c36086
Merge branch 'master' into add-security-headers
taoeffect 5d524ff
Merge master into add-security-headers
snowteamer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,23 @@ import { GIMessage } from '~/shared/domains/chelonia/GIMessage.js' | |
|
||
const { CONTRACTS_VERSION, GI_VERSION } = process.env | ||
|
||
const securityHeaders = { | ||
// This is the most likely to break things now; it may need changing when sandboxing or federation is implemented. | ||
'Content-Security-Policy': "default-src 'none'; script-src 'unsafe-eval'; script-src-elem 'self'; script-src-attr 'none'; style-src 'self'; style-src-elem 'self'; style-src-attr 'none'; img-src 'self' blob:; font-src 'self'; connect-src 'self'; media-src 'self'; prefetch-src 'self'; worker-src 'self'; frame-ancestors 'none'; form-action 'self'; upgrade-insecure-requests; manifest-src 'self'", | ||
'X-Content-Type-Options': 'nosniff', | ||
'Referrer-Policy': 'strict-origin-when-cross-origin', | ||
// List generated using https://www.permissionspolicy.com. | ||
'Permissions-Policy': 'accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(self), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(self), execution-while-out-of-viewport=(self), fullscreen=(self), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(self), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(self), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(self), gamepad=(), speaker-selection=()', | ||
// Don't share context with potentially untrusted sites. | ||
'Cross-Origin-Opener-Policy': 'same-origin', | ||
// Block loading the page in a frame. | ||
'X-Frame-Options': 'deny', | ||
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. This should be |
||
// Blocks embedding cross-origin resources that don't explicitly allow it. | ||
'Cross-Origin-Embedder-Policy': 'require-corp', | ||
// Block hotlinking. | ||
'Cross-Origin-Resource-Policy': 'same-origin' | ||
} | ||
|
||
const hapi = new Hapi.Server({ | ||
// debug: false, // <- Hapi v16 was outputing too many unnecessary debug statements | ||
// // v17 doesn't seem to do this anymore so I've re-enabled the logging | ||
|
@@ -52,9 +69,13 @@ hapi.ext({ | |
// but custom headers can be manually added using `.output.headers`. | ||
// See https://hapi.dev/module/boom/api/. | ||
if (typeof request.response.header === 'function') { | ||
request.response.header('X-Frame-Options', 'deny') | ||
for (const [name, value] of Object.entries(securityHeaders)) { | ||
request.response.header(name, value) | ||
} | ||
} else { | ||
request.response.output.headers['X-Frame-Options'] = 'deny' | ||
for (const [name, value] of Object.entries(securityHeaders)) { | ||
request.response.output.headers[name] = value | ||
} | ||
} | ||
} catch (err) { | ||
console.warn(chalk.yellow('[backend] Could not set X-Frame-Options header:', err.message)) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 will cause issues with the emoji images, since those are loaded externally. See #2334. Either
img-src
will need to be expanded, or the sheet be embedded locally (preferred solution).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.
Is using
img-src 'self' blob: https://unpkg.com
OK for now? Otherwise, installing and redistributing emoji sheets viadist/assets
seems a bit tricky regarding e.g. licensing issues.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.
In terms of solving the CSP issue, yes (although you need to check manually, it could interfere with Cross-Origin-Embedder-Policy as well).
The preferred (to me) solution would be embedding the sheet. There could be some licensing concerns, but I'm not sure those concerns are alleviated by hotlinking. This is best left as a question to a lawyer or to the copyright holder. (Sidenote: fonts designs generally aren't under copyright in the US, but I'm guessing emoji designs likely are, and even if they weren't, there's other places to consider).
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.
An alternative solution is to drop the Apple emojis and use an emoji set with a free license. E.g., https://github.com/mozilla/fxemoji