Skip to content

🐛 fix(extract): read meta refresh like browsers - #2126

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:sec-fix/iyetyclo
Nov 15, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:sec-fix/iyetyclo

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

The link methods and Document.meta_refresh() read the same <meta http-equiv=refresh> value differently. One tag could name different targets depending on the method, so a crawler, link checker or rewriter could list or rewrite a target that a browser does not follow, or miss the one it does. 🔗 After this change all of them read the value by the HTML standard's pragma directive rules, so they agree with each other and with browsers.

Architecture

One routine reads the delay and the target from the value, and both the link scanner and Document.meta_refresh() call it. The routine sits in the core layer, next to the ASCII helpers, because the extract and DOM modules both need it and neither should own the other's parsing. The HTML standard reads the target only after the delay and a separator, and the url= keyword is optional and counts only at that position.

Behavior changes

  • Document.meta_refresh() returns None for a value with text other than a separator right after the delay. It returned that text as the redirect before.
  • Document.meta_refresh() treats whitespace alone as the separator and returns the target after it.
  • links(), rewrite_links() and resolve_links() report no link for a value without a delay. The old scanner reported any url= target in the value.
  • links(), rewrite_links() and resolve_links() report a target written without url=, and take an unquoted target to the end of the value instead of its first space.
  • The url= keyword counts only right after the delay. An unquoted target runs to the end of the value, with surrounding whitespace removed. A quoted target with no closing quote runs to the end of the value, and the quote is no longer part of the target.
  • A quote with no text after it gives no target, so Document.meta_refresh() returns the fallback URL.
  • A delay written as a lone . makes Document.meta_refresh() return a delay of 0.0 with the fallback URL. It raised ValueError before.

Fixes #1737.

links() and Document.meta_refresh() read a <meta http-equiv=refresh>
target differently. The link scanner searched the whole content value
for a url= keyword, so a keyword inside the target was taken as the
target. meta_refresh() stopped at a delay with no separator and kept
text after the delay that a browser never follows. Both readers now
call one routine in core/refresh.h that follows the HTML shared
declarative refresh steps, so every reader names the URL a browser
redirects to.

Text right after the delay that is not a separator is no refresh, so
meta_refresh() returns None for it. A lone "." delay now reads as zero
instead of raising ValueError.

Fixes tox-dev#1737
@gaborbernat gaborbernat added the bug Something isn't working label Nov 15, 2026
@codspeed

codspeed Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 582 untouched benchmarks
⏩ 89 skipped benchmarks1


Comparing gaborbernat:sec-fix/iyetyclo (12d8320) with main (56b393e)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

The CSS scanner checks the byte before url( with the identifier test.
Prefixes that are an uppercase letter, a digit, or punctuation had no
case, so those branches of the check never ran on the 3.14 coverage
gate.
@gaborbernat
gaborbernat merged commit e84e06c into tox-dev:main Nov 15, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

links() reads meta refresh targets from the wrong part of the content value

1 participant