Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

SRI: don't complain about data URIs #493

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions httpobs/scanner/analyzer/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def subresource_integrity(reqs: dict, expectation='sri-implemented-and-external-
# Relative protocol (src="//host/path")
relativeorigin = False
relativeprotocol = True
elif src.scheme == 'data':
# Data URI is essentially the same as inline script, treat is as local path for simplicity
relativeorigin = True
relativeprotocol = True
else:
relativeorigin = False
relativeprotocol = False
Expand Down
6 changes: 6 additions & 0 deletions httpobs/tests/unittests/files/test_content_sri_data_uri.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<head>
<script src="data:text/javascript;base64,YWxlcnQoMSkK"></script>
<head>
<body></body>
</html>
9 changes: 9 additions & 0 deletions httpobs/tests/unittests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ def test_same_origin(self):
self.assertEquals('sri-not-implemented-but-all-scripts-loaded-from-secure-origin', result['result'])
self.assertTrue(result['pass'])

def test_data_uri(self):
# load from a remote site
self.reqs = empty_requests('test_content_sri_data_uri.html')

result = subresource_integrity(self.reqs)

self.assertEquals('sri-not-implemented-but-all-scripts-loaded-from-secure-origin', result['result'])
self.assertTrue(result['pass'])

def test_implemented_external_scripts_https(self):
# load from a remote site
self.reqs = empty_requests('test_content_sri_impl_external_https1.html')
Expand Down