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

Tighten up Content-Security-Policy #1513

Merged
merged 14 commits into from Aug 14, 2021
Merged

Tighten up Content-Security-Policy #1513

merged 14 commits into from Aug 14, 2021

Conversation

davidmehren
Copy link
Member

@davidmehren davidmehren commented Aug 6, 2021

Component/Part

Content Security Policy

Description

This PR

  • tightens the default CSP by setting default-src to none and then only allowing things explicitly.
  • introduces a config option to disallow iframing HedgeDoc in other pages
  • introduces a config option to disallow embedding PDFs in notes

When both options are disabled, CSP Scanner is pretty happy and gives us an A score

By default, both options are enabled for backwards-compatibility, CSP Scanner gives us a B

Steps

  • Added implementation
  • Added / updated tests
  • Added / updated documentation
  • I read the contribution documentation and
    made sure that:
    • My commits are signed-off to accept the DCO.
    • This PR targets the correct branch: master for 1.x & docs, develop for 2.x

Related Issue(s)

@davidmehren davidmehren added the type: feature enhancement An improvement to existing functionality label Aug 6, 2021
@davidmehren davidmehren added this to the Release 1.9 milestone Aug 6, 2021
@davidmehren davidmehren self-assigned this Aug 6, 2021
lib/csp.js Show resolved Hide resolved
@davidmehren davidmehren marked this pull request as ready for review August 8, 2021 16:22
@davidmehren
Copy link
Member Author

Now with green tests!

Copy link
Member

@ErikMichelson ErikMichelson left a comment

Choose a reason for hiding this comment

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

This tightening breaks slideshare on Chrome.

jquery.js:10185 Refused to load the script 'http://www.slideshare.net/api/oembed/2?url=http://www.slideshare.net/briansolis/26-disruptive-technology-trends-2016-2018-56796196&format=json&callback=jQuery36008752817940203228_1628541591964&_=1628541591965' because it violates the following Content Security Policy directive: "script-src http://localhost:3000/build/ http://localhost:3000/js/ http://localhost:3000/config https://gist.github.com/ https://vimeo.com/api/oembed.json https://www.slideshare.net/api/oembed/2 'unsafe-inline' 'nonce-c14f1eb8-61a0-47e5-a4f1-5d41be287756' 'sha256-81acLZNZISnyGYZrSuoYhpzwDTTxi7vC1YM4uNxqWaM='". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

This commit changes the
- default-src to none, so everything is disallowed by default
- base-uri, connect-uri and font-src to self,
  so these are restricted to the current origin
- frame-src to allow SlideShare, Vimeo and YouTube
- script-src to the specific paths that are used by HedgeDoc to serve scripts.
  This explicitly does not include the /uploads route
 - style-src to the specific paths that are used by HedgeDoc to serve styles
 -

Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: David Mehren <git@herrmehren.de>
Reveal.js styles are hosted there

Signed-off-by: David Mehren <git@herrmehren.de>
The reveal.js speaker view uses frames to display the slides

Signed-off-by: David Mehren <git@herrmehren.de>
Chrome complains otherwise, as it can't download the Web Manifest.

Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: David Mehren <git@herrmehren.de>
In 25f5fd2 the `media-src`, `child-src` and `connect-src`
settings were removed, as they are filled with the `default-src` automatically.

This caused a bug in the test code, as it now tried to access a
nonexistent field  of `unextendedCSP`.

This commit adds a filter that removes the empty array field
before converting to a string.

Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: David Mehren <git@herrmehren.de>
Otherwise, `video` tags and reveal background video
does not work

Signed-off-by: David Mehren <git@herrmehren.de>
@davidmehren davidmehren merged commit fc1aec6 into master Aug 14, 2021
@davidmehren davidmehren deleted the fix/csp branch August 14, 2021 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature enhancement An improvement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants