-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
Open
paskal
wants to merge
1
commit into
master
Choose a base branch
from
paskal/csp
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.
Conversation
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
Pull Request Test Coverage Report for Build 10239559906Details
💛 - Coveralls |
paskal
force-pushed
the
paskal/csp
branch
3 times, most recently
from
August 4, 2024 22:39
be89b16
to
dcc6640
Compare
`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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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. IfimageProxyEnabled
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 thebeforeunload
andunload
events.window-management=()
: Disables the ability to use window management APIs.