-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feat/csp check #205
Merged
Merged
Feat/csp check #205
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
kwajiehao
suggested changes
Nov 9, 2020
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 is very well-researched and i like how the functions are broken down, it was very easy to read. left comments and will follow-up offline
…es csp, cleans up console logging, cleans up variable names, and cleans up test code
…tures html and sanitizing before rendering
…ration for supporting child-src and script-src-elem cases
…licy object on each render
gweiying
force-pushed
the
feat/csp-check
branch
from
November 16, 2020 09:48
e2a0148
to
bb83164
Compare
kwajiehao
approved these changes
Nov 16, 2020
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.
lgtm
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 PR introduces utilities to check editor markdown content for unsupported elements in EditPage, resolving #179.
Implementation
At a high level, this is done by first retrieving and parsing the
netlify.toml
file from the website repo to extract the CSP for the repo. The user-edited markdown content is compiled into html, and inspected for any elements that violate the CSP. The violating elements are replaced with an error message, and the Save button is disabled until the user resolves the error message. An example of this is shown in the screenshot below.Details
The CSP of a website specifies accepted sources for scripts on the website. Only scripts received from domains specified in the respective fetch directives can executed on the website. Currently, only 5 fetch directives and their fallbacks are supported in our CSP checking,
frame-src
,img-src
,script-elem-src
,object-src
,media-src
.For each fetch directives, the types of html elements restricted are as follows:
frame-src
:frame
,iframe
img-src
:img
media-src
:audio
,video
,track
object-src
:object
,embed
,applet
script-src-elem
:script
For example, with a
media-src
policy of'none'
,<audio src="animal.mp3" controls></audio>
will be considered a violating element.If the
frame-src
is not specified, the checker falls back to thechild-src
policy value (link1 [link2])(http://csplite.com/csp/test121/), and defaults todefault-src
ifchild-src
is not specified either. Similarly, ifscript-src-elem
is not specified,script-src-elem
falls back toscript-src
and defaults todefault-src
ifscript-src
is not specified. All other fetch directives default automatically todefault-src
if not specified.