Repository navigation
Assert the saved-copy allowlist as an invariant - #81
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #80.
markfind saves a copy of every page it fetches and serves it back from
/archive, so the sanitizer is a security boundary. I attacked it and found no vulnerability. This PR records that as a test, and fixes one cosmetic nit the attempt turned up.What I threw at it
38 payloads through
extract_textandarchive.render: script tags in several disguises (<scr<script>ipt>, uppercase,src=), event handlers,javascript:/data:/vbscript:links with tab and space obfuscation,<iframe srcdoc>,<base>,<meta refresh>,<object>,<embed>,<form>, SVG and MathML wrappers,<template>,<xmp>,<plaintext>, attribute-boundary tricks, NUL bytes, comments and CDATA.Nothing executable survived. Two cases looked like hits at first and were not:
<a href='https://ok.example/" onmouseover="alert(1)'>becomeshref="https://ok.example/" onmouseover="alert(1)". The quotes are escaped, so it is one odd URL, not an attribute.<p>" onload="alert(1)</p>keeps its raw quotes, but in text content, where a quote cannot begin an attribute.What this adds
A test of the rule, not of examples.
test_saved_copies.pyalready checks particular markup. The newtests/test_archive_safety.pyparses the output and asserts the invariant: every surviving tag is in_READER_TAGS, every surviving attribute is one the allowlist names for that tag, and everyhrefis http or https. It runs over all 38 payloads, for the fragment and for the whole served page. A future change that quietly widens the allowlist fails it.One real fix. Span attributes were kept when
str.isdigit()was true, which it also is for²and for digits in other scripts, socolspan="²"reached the saved copy. No browser reads that as a span. Only ASCII digits are kept now. The test for it fails onmainand passes here.77 new test cases; 497 pass in total, ruff clean.
Scope
This covers the sanitizer. The
/archiveresponse also carriesContent-Security-Policy: sandbox; default-src 'none', whichtest_saved_copies.pyand the browser tests already check, so defence in depth is unchanged.