Skip to content

Assert the saved-copy allowlist as an invariant - #81

Merged
Alcides1123 merged 2 commits into
mainfrom
archive-allowlist-tests
Nov 12, 2026
Merged

Alcides1123 merged 2 commits into
mainfrom
archive-allowlist-tests

Conversation

@Alcides1123

Copy link
Copy Markdown
Owner

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_text and archive.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)'> becomes href="https://ok.example/&quot; onmouseover=&quot;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.py already checks particular markup. The new tests/test_archive_safety.py parses 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 every href is 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, so colspan="²" reached the saved copy. No browser reads that as a span. Only ASCII digits are kept now. The test for it fails on main and passes here.

77 new test cases; 497 pass in total, ruff clean.

Scope

This covers the sanitizer. The /archive response also carries Content-Security-Policy: sandbox; default-src 'none', which test_saved_copies.py and the browser tests already check, so defence in depth is unchanged.

@Alcides1123
Alcides1123 merged commit fcaf858 into main Nov 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test the saved-copy allowlist as a rule, not by example

1 participant