Skip to content

fix: an edit cycle could hang serialization, and selectors could crawl - #96

Merged
jamesconwaydev merged 1 commit into
mainfrom
sync-security
Nov 19, 2026
Merged

jamesconwaydev merged 1 commit into
mainfrom
sync-security

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Problem

The security review for #58 found four ways untrusted input could hurt a caller:

  • F1 (high): append(template_contents(t), t) passed the cycle check, so outer_html and text() never returned.
  • F2 (high): a selector of about 25,000 compounds overflowed an 8 MiB stack while matching, and about 6,000 overflowed a 2 MiB thread.
  • F3 and F4 (medium): div:has(b) and :nth-child(… of S) took time quadratic in the tree.

Also, parse read the clock on every call, which panics in WebAssembly and blocks #24.

Change

Syncs Netweir 75b8681:

Tests

  • cargo test --workspace: 213 test groups, 0 failed. Tokenizer 7,045 and tree construction 3,898 passed, 0 failed.
  • The synced tests cover:
    • both cycle shapes;
    • 20,000- and 100,000-compound chains on a 2 MiB thread;
    • nesting to the cap of 32;
    • 20,000-deep and 20,000-wide trees for :has() and :nth-*;
    • a timeout well inside its budget.
  • bindings/python builds and passes clippy.

Syncs Netweir 75b8681, which brings:

- netweir/netweir#333: fixes for the four findings of the parser's
  security review (#58). An edit could put a template inside its own
  contents, after which outer_html and text() never returned. A long
  descendant chain overflowed the stack while matching. :has() and
  :nth-child(of S) were quadratic. Matching is now iterative, those
  two are linear, and MatchOptions takes an optional time budget.
- netweir/netweir#332: parse read the clock even without a budget,
  which panics on wasm32-unknown-unknown.

The Python bindings built MatchOptions with a struct literal, so they
fill the new budget field with its default.
@jamesconwaydev
jamesconwaydev enabled auto-merge (squash) November 19, 2026 06:29
@jamesconwaydev
jamesconwaydev merged commit 7cd7fe9 into main Nov 19, 2026
32 checks passed
@jamesconwaydev
jamesconwaydev deleted the sync-security branch November 19, 2026 06:32
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.

1 participant