-
Notifications
You must be signed in to change notification settings - Fork 55
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
Comments
@alin04 OK to close this or is there more that needs to be done? |
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
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:src
attribute whose value is not prefixed byhttps://cdn.ampproject.org/
(case-insensitive match).src
attribute and notype
attribute (case-insensitive match).type
attribute whose value is neitherapplication/json
norapplication/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 removedonfoo
should be removedThe text was updated successfully, but these errors were encountered: