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

Check only stylesheet link rels rather than whitelisting other rels #529

Merged
merged 3 commits into from
Sep 7, 2019
Merged
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
6 changes: 4 additions & 2 deletions lib/html-proofer/check/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ def find_fragments(html, fragment_ids)
html.xpath(*xpaths)
end

IGNORABE_REL = %(canonical alternate next prev previous icon manifest apple-touch-icon)
# Whitelist for affected elements from Subresource Integrity specification
# https://w3c.github.io/webappsec-subresource-integrity/#link-element-for-stylesheets
SRI_REL_TYPES = %(stylesheet)

def check_sri(line, content)
return if IGNORABE_REL.include?(@link.rel)
return unless SRI_REL_TYPES.include?(@link.rel)
Copy link
Owner

Choose a reason for hiding this comment

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

I like this but I think I have to think on it a bit more before approving. For example, script and link will also need to be checked. I'm not sure if there are more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, this code should only apply to link tags - script is handled by another check, in https://github.com/gjtorikian/html-proofer/blob/master/lib/html-proofer/check/scripts.rb#L33, so is unaffected. As I mentioned, as far as I can tell from the spec, the only thing that is proactively loaded in by browsers from link tags are rel='stylesheet', which this should cover.

Copy link
Owner

Choose a reason for hiding this comment

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

You're right! My mistake.

if !defined?(@link.integrity) && !defined?(@link.crossorigin)
add_issue("SRI and CORS not provided in: #{@link.src}", line: line, content: content)
elsif !defined?(@link.integrity)
Expand Down
8 changes: 8 additions & 0 deletions spec/html-proofer/fixtures/links/link_with_me.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<link rel="me" href="https://github.com/gjtorikian/html-proofer" />
<link rel="webmention" href="https://webmention.io/username/webmention" />
<link rel="pingback" href="https://webmention.io/username/xmlrpc" />
</head>
<body></body>
</html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec/html-proofer/links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@
expect(proofer.failed_tests).to eq []
end

it 'is not checking SRI and CORS for indieweb links with rel "me", "webmention", or "pingback"' do
file = "#{FIXTURES_DIR}/links/link_with_me.html"
proofer = run_proofer(file, :file, check_sri: true)
expect(proofer.failed_tests).to eq []
end

it 'can link to external non-unicode hash' do
file = "#{FIXTURES_DIR}/links/hash_to_unicode_ref.html"
proofer = run_proofer(file, :file, check_external_hash: true)
Expand Down