Skip to content

Commit

Permalink
html_rewriter: added the nullification of meta tag delivered CSP poli…
Browse files Browse the repository at this point in the history
…cies to HTMLRewriterMixin, treat it like the integrity attribute (#274)

rewrite test: updated the html_rewriter test to cover the changes made for meta CSP rewriting
fixes #273
  • Loading branch information
N0taN3rd authored and ikreymer committed Jan 8, 2018
1 parent d3b379e commit 3c05f27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pywb/rewrite/html_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ def _rewrite_tag_attrs(self, tag, tag_attrs):
elif (tag == 'meta') and (attr_name == 'content'):
if self.has_attr(tag_attrs, ('http-equiv', 'refresh')):
attr_value = self._rewrite_meta_refresh(attr_value)
elif self.has_attr(tag_attrs, ('http-equiv', 'content-security-policy')):
attr_name = '_' + attr_name
elif self.has_attr(tag_attrs, ('name', 'referrer')):
attr_value = 'no-referrer-when-downgrade'
elif attr_value.startswith(self.DATA_RW_PROTOCOLS):
Expand Down
3 changes: 3 additions & 0 deletions pywb/rewrite/test/test_html_rewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
>>> parse('<meta name="referrer" content="origin">')
<meta name="referrer" content="no-referrer-when-downgrade">
>>> parse('<meta http-equiv="Content-Security-Policy" content="default-src http://example.com" />')
<meta http-equiv="Content-Security-Policy" _content="default-src http://example.com"/>
# Custom -data attribs
>>> parse('<div data-url="http://example.com/a/b/c.html" data-some-other-value="http://example.com/img.gif">')
<div data-url="/web/20131226101010oe_/http://example.com/a/b/c.html" data-some-other-value="/web/20131226101010oe_/http://example.com/img.gif">
Expand Down

0 comments on commit 3c05f27

Please sign in to comment.