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

Strip javascript in golang transformer #148

Closed
Gregable opened this issue Oct 8, 2018 · 1 comment
Closed

Strip javascript in golang transformer #148

Gregable opened this issue Oct 8, 2018 · 1 comment
Assignees

Comments

@Gregable
Copy link
Member

Gregable commented Oct 8, 2018

Users of the packager may mistakenly transform and sign non-amp content. The AMP Cache will reject this, but for security we want some light protections against this content being usable. This issue tracks removing non-amp javascript from the document in a new transformer.

The steps we should take are:

For each <script> tag on the page, if any one of of the following is true:

  • It has a src attribute whose value is not prefixed by https://cdn.ampproject.org/ (case-insensitive match).
  • It has no src attribute and no type attribute (case-insensitive match).
  • It has a type attribute whose value is neither application/json nor application/ld+json (case-insensitive match on both name and value).

Then, remove the <script> tag and all descendant nodes of <script> tag, including text / cdata nodes.

For example:

  • <script async src="https://cdn.ampproject.org/v0.js"> should not be removed
  • <script async custom-element='amp-analytics' src='https://cdn.ampproject.org/v0/amp-analytics-0.1.js'> should not be removed.
  • <script src='http://example.com/example.js'> should be removed.
  • <script>foo</script> should be removed
  • <script type=application/javascript>foo</script> should be removed
  • <script type=application/json>foo</script>should not be removed
  • <script type=application/json src="https://cdn.ampproject.org/v0.js">

For every tag on the page, if the tag has an attribute with a case-insensitive prefix of on followed by another alphabetic character ([A-Za-z]), then remove that attribute. For example:

  • on should not be removed.
  • on-foo should not be removed
  • onfoo should be removed
@alin04 alin04 self-assigned this Oct 12, 2018
alin04 added a commit that referenced this issue Oct 12, 2018
PiperOrigin-RevId: 216936577
twifkak pushed a commit that referenced this issue Oct 12, 2018
PiperOrigin-RevId: 216936577
@Gregable
Copy link
Member Author

@alin04 OK to close this or is there more that needs to be done?

@alin04 alin04 closed this as completed Oct 15, 2018
twifkak added a commit that referenced this issue Dec 18, 2019
…ansformer

was #148, and text/plain scripts should not be relevant to that aim. Note that
the text/plain scripts used by the amp-script component are further guarded by
computeMaxAgeSeconds in transformer.go.

PiperOrigin-RevId: 286250297
twifkak added a commit that referenced this issue Dec 18, 2019
…ansformer

was #148, and text/plain scripts should not be relevant to that aim. Note that
the text/plain scripts used by the amp-script component are further guarded by
computeMaxAgeSeconds in transformer.go.

PiperOrigin-RevId: 286250297
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

No branches or pull requests

2 participants