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

Feat/csp check #205

Merged
merged 19 commits into from
Nov 16, 2020
Merged

Feat/csp check #205

merged 19 commits into from
Nov 16, 2020

Conversation

gweiying
Copy link
Contributor

@gweiying gweiying commented Nov 5, 2020

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.

Screenshot 2020-11-09 at 9 10 24 AM

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 the child-src policy value (link1 [link2])(http://csplite.com/csp/test121/), and defaults to default-src if child-src is not specified either. Similarly, if script-src-elem is not specified, script-src-elem falls back to script-src and defaults to default-src if script-src is not specified. All other fetch directives default automatically to default-src if not specified.

@gweiying gweiying marked this pull request as ready for review November 9, 2020 09:13
Copy link
Contributor

@kwajiehao kwajiehao left a 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

src/utils/cspUtils.js Outdated Show resolved Hide resolved
src/utils/cspUtils.js Outdated Show resolved Hide resolved
src/utils/cspUtils.js Outdated Show resolved Hide resolved
src/utils/cspUtils.js Outdated Show resolved Hide resolved
src/utils/cspUtils.js Outdated Show resolved Hide resolved
src/utils/cspUtils.js Show resolved Hide resolved
Copy link
Contributor

@kwajiehao kwajiehao left a comment

Choose a reason for hiding this comment

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

lgtm

@gweiying gweiying merged commit 4ed5ee1 into staging Nov 16, 2020
@gweiying gweiying deleted the feat/csp-check branch November 16, 2020 11:05
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.

2 participants