Skip to content
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
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add missing security headers #2362

wants to merge 6 commits into from

Conversation

snowteamer
Copy link
Collaborator

@snowteamer snowteamer commented Sep 23, 2024

Fix #2291

Emoji sheet, audio asset loading and file upload in chat manually tested on:

  • Firefox Developer Edition v132.b09
  • Chrome 130

Note that the favicon badge gets blocked in Chrome, but maybe it's acceptable, so as to avoid allowing data: URLs?
image

Copy link

cypress bot commented Sep 23, 2024

group-income    Run #3352

Run Properties:  status check passed Passed #3352  •  git commit eae5add86a ℹ️: Merge ad50668cf97c93d66337c2401ec7cf2ab1f19d7b into 1bc76ebde99551c7e9d478bfca90...
Project group-income
Branch Review add-security-headers
Run status status check passed Passed #3352
Run duration 09m 08s
Commit git commit eae5add86a ℹ️: Merge ad50668cf97c93d66337c2401ec7cf2ab1f19d7b into 1bc76ebde99551c7e9d478bfca90...
Committer Snowteamer
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 111
View all changes introduced in this branch ↗︎

@snowteamer snowteamer self-assigned this Sep 23, 2024
// 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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be DENY (uppercase)

@@ -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'",
Copy link
Member

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).

Copy link
Collaborator Author

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 via dist/assets seems a bit tricky regarding e.g. licensing issues.

Copy link
Member

@corrideat corrideat Sep 27, 2024

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).

Copy link
Member

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

@corrideat
Copy link
Member

Running the app locally and opening http://localhost:3000 on Firefox doesn't seem to work due to CSP.

image

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test this PR on as many browsers as you have available locally and let us know which browsers you tested so that I can test on the remaining ones that you don't have access to (e.g. Safari).

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @snowteamer, it's coming along, still a few more browsers we need to test on.

BTW, if you'd like to test on BrowserStack, I'll send you credentials.

The site doesn't load on Safari on macOS:

Screenshot 2024-12-09 at 9 13 07 AM

And the other error your noticed in Chrome related to the favicon not being set also needs to be fixed, as we need the red dot to be visible when DMs are sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Security Headers
3 participants