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 Content-Security-Policy and Permissions-Policy headers #1805

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

paskal
Copy link
Collaborator

@paskal paskal commented Aug 4, 2024

This is a security change. The policies I've added are not ideal but an improvement over lack of policies, and were tested by me for a few months to verify their work.

Content-Security-Policy now restricts resource loading and execution to enhance security:

  • default-src 'none': Disallow all resource loading by default.
  • base-uri 'none': Prevents the use of <base> tag to change the base URL for relative URLs.
  • form-action 'none': Disallows form submissions.
  • connect-src 'self': Restricts the origins that can be connected to (via XHR, WebSockets, etc.) to the same origin.
  • frame-src *: Allow to be embedded on any domain.
  • img-src 'self': Allows images to be loaded only from the same origin. If imageProxyEnabled is true, allows images from any origin (*).
  • script-src 'self' 'unsafe-inline': Allows scripts to be loaded and executed only from the same origin and allows inline scripts.
  • style-src 'self' 'unsafe-inline': Allows styles to be loaded and applied only from the same origin and allows inline styles.
  • font-src data:: Allows fonts to be loaded from data URIs.
  • object-src 'none': Disallows the use of <object>, <embed>, and <applet> tags.

Permissions-Policy now restricts the use of certain browser features which we don't use to enhance user privacy and security:

  • accelerometer=(): Disables the use of the accelerometer sensor.
  • autoplay=(): Disables automatic playback of media.
  • camera=(): Disables the use of the camera.
  • cross-origin-isolated=(): Disallows the page from being treated as cross-origin isolated.
  • display-capture=(): Disables the ability to capture the display.
  • encrypted-media=(): Disables the use of Encrypted Media Extensions .
  • fullscreen=(): Disables the ability to use fullscreen mode.
  • geolocation=(): Disables the use of geolocation.
  • gyroscope=(): Disables the use of the gyroscope sensor.
  • keyboard-map=(): Disables the use of the keyboard map.
  • magnetometer=(): Disables the use of the magnetometer sensor.
  • microphone=(): Disables the use of the microphone.
  • midi=(): Disables the use of the MIDI API.
  • payment=(): Disables the Payment Request API.
  • picture-in-picture=(): Disables the use of Picture-in-Picture mode .
  • publickey-credentials-get=(): Disables the use of the Web Authentication API.
  • screen-wake-lock=(): Disables the ability to prevent the screen from dimming.
  • sync-xhr=(): Disables synchronous XMLHttpRequest.
  • usb=(): Disables the use of the USB API.
  • xr-spatial-tracking=(): Disables the use of spatial tracking in WebXR.
  • clipboard-read=(): Disables the ability to read from the clipboard .
  • clipboard-write=(): Disables the ability to write to the clipboard .
  • gamepad=(): Disables the use of the Gamepad API.
  • hid=(): Disables the use of the Human Interface Device API.
  • idle-detection=(): Disables the ability to detect idle state.
  • interest-cohort=(): Disables the use of interest cohort tracking.
  • serial=(): Disables the use of the Serial API.
  • unload=(): Disables the ability to use the beforeunload and unload events.
  • window-management=(): Disables the ability to use window management APIs.

Copy link

github-actions bot commented Aug 4, 2024

Pull Request Test Coverage Report for Build 10239559906

Details

  • 10 of 12 (83.33%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 84.877%

Changes Missing Coverage Covered Lines Changed/Added Lines %
backend/app/rest/api/rest.go 9 11 81.82%
Totals Coverage Status
Change from base Build 10172404701: 0.03%
Covered Lines: 5994
Relevant Lines: 7062

💛 - Coveralls

@paskal paskal force-pushed the paskal/csp branch 3 times, most recently from be89b16 to dcc6640 Compare August 4, 2024 22:39
`Content-Security-Policy` now restricts resource loading and execution
to enhance security:
  - `default-src 'none'`: Disallow all resource loading by default.
  - `base-uri 'none'`: Prevents the use of `<base>` tag to change the
  base URL for relative URLs.
  - `form-action 'none'`: Disallows form submissions.
  - `connect-src 'self'`: Restricts the origins that can be connected to
   (via XHR, WebSockets, etc.) to the same origin.
  - `frame-src 'self'`: Restricts the origins that can be embedded using
   `<frame>` and `<iframe>` to the same origin (for `/web/` demo
    endpoint).
  - `frame-ancestors %s;`: Specifies the origins that are allowed to
  embed this content in a frame. If no specific origins are allowed, it
  defaults to `*` (any origin). This enhances security by controlling
  which sites can embed your content.
  - `img-src 'self'`: Allows images to be loaded only from the same
  origin. If `imageProxyEnabled` is true, allows images from any origin
  (`*`).
  - `script-src 'self' 'unsafe-inline'`: Allows scripts to be loaded and
   executed only from the same origin and allows inline scripts.
  - `style-src 'self' 'unsafe-inline'`: Allows styles to be loaded and
  applied only from the same origin and allows inline styles.
  - `font-src data:`: Allows fonts to be loaded from data URIs.
  - `object-src 'none'`: Disallows the use of `<object>`, `<embed>`, and
   `<applet>` tags.

`Permissions-Policy` now restricts the use of certain browser features
which we don't use to enhance user privacy and security:
  - `accelerometer=()`: Disables the use of the accelerometer sensor.
  - `autoplay=()`: Disables automatic playback of media.
  - `camera=()`: Disables the use of the camera.
  - `cross-origin-isolated=()`: Disallows the page from being treated as
   cross-origin isolated.
  - `display-capture=()`: Disables the ability to capture the display.
  - `encrypted-media=()`: Disables the use of Encrypted Media Extensions
  .
  - `fullscreen=()`: Disables the ability to use fullscreen mode.
  - `geolocation=()`: Disables the use of geolocation.
  - `gyroscope=()`: Disables the use of the gyroscope sensor.
  - `keyboard-map=()`: Disables the use of the keyboard map.
  - `magnetometer=()`: Disables the use of the magnetometer sensor.
  - `microphone=()`: Disables the use of the microphone.
  - `midi=()`: Disables the use of the MIDI API.
  - `payment=()`: Disables the Payment Request API.
  - `picture-in-picture=()`: Disables the use of Picture-in-Picture mode
  .
  - `publickey-credentials-get=()`: Disables the use of the Web
  Authentication API.
  - `screen-wake-lock=()`: Disables the ability to prevent the screen
  from dimming.
  - `sync-xhr=()`: Disables synchronous XMLHttpRequest.
  - `usb=()`: Disables the use of the USB API.
  - `xr-spatial-tracking=()`: Disables the use of spatial tracking in
  WebXR.
  - `clipboard-read=()`: Disables the ability to read from the clipboard
  .
  - `clipboard-write=()`: Disables the ability to write to the clipboard
  .
  - `gamepad=()`: Disables the use of the Gamepad API.
  - `hid=()`: Disables the use of the Human Interface Device API.
  - `idle-detection=()`: Disables the ability to detect idle state.
  - `interest-cohort=()`: Disables the use of interest cohort tracking.
  - `serial=()`: Disables the use of the Serial API.
  - `unload=()`: Disables the ability to use the `beforeunload` and
  `unload` events.
  - `window-management=()`: Disables the ability to use window
  management APIs.
@umputun umputun merged commit f9d4837 into master Oct 15, 2024
3 checks passed
@umputun umputun deleted the paskal/csp branch October 15, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants