Filter regexes run on the linear-time engine, so a match timeout no longer lets a blocked name through #53

Closed
opened 2026-10-31 12:41:57 -04:00 by claude · 0 comments
Owner
  • Draft: BUG-5
  • Priority: medium (a stalled thread or a crafted name can let a blocked domain through; today only a warning is logged)
  • Agent: coder
  • Depends on: none
  • Decisions: Q-BUG-1

Why

Every wildcard and regex entry runs with a wall-clock 250 ms timeout (src/dotnet/src/Ninlil.Dns.Server.Filtering/DnsFilterEngine.cs:92). A timeout counts as "no match" (:597-618):

  • On a block list, the query is allowed (fail open).
  • On an exception (allow) list, the allow is skipped.
    The timeout is wall-clock, so a thread stalled by load or a GC pause trips it too. B23-16 found this while fixing a flaky test and kept it as the ReDoS guard.

What changes

  • Compile every pattern with RegexOptions.NonBacktracking, which matches in linear time and needs no timeout. A pattern that engine refuses (backreferences, lookarounds, atomic groups and the like throw NotSupportedException at construction) falls back to the backtracking engine with today's timeout and today's rule.
  • CompileOrNull (:626) is also used by FilterListEntriesController and FilterPatternPreviewController, so what counts as a valid pattern must not change.
  • In DnsFilterIndex/DnsFilterListIndex.cs, record which entries use the fallback; the preview endpoint may report it (optional; if it adds a response field, an api-regen step follows in the same PR).
  • DnsFilterPatternPrefilterTests parity tests and EvaluateDomainAsync_ForARegexThatTimesOut_AllowsTheNameAndLogsAWarning are updated: the timeout test now uses a pattern that needs the fallback.

Acceptance

  • Red first: a block-list entry ^(a+)+$ matched against 40 a's is blocked in linear time (no timeout, no warning); fails on HEAD.
  • A pattern with a backreference still compiles, runs on the fallback and keeps today's timeout rule.
  • dotnet test src/dotnet/tests/Ninlil.Dns.Server.Filtering.Tests passes 20 times in a row.
  • FilterEngine benchmarks before/after (Large) show no regression over 10 %.
  • README filter section states the rule. No schema or option change.

Source

b23-design.md:522 (B23-16 production concern); DnsFilterEngine.cs:606-616.
Owner decision 2026-10-31 (Q-BUG-1): "NonBacktracking first".

- **Draft:** BUG-5 - **Priority:** medium (a stalled thread or a crafted name can let a blocked domain through; today only a warning is logged) - **Agent:** coder - **Depends on:** none - **Decisions:** Q-BUG-1 ### Why Every wildcard and regex entry runs with a wall-clock 250 ms timeout (`src/dotnet/src/Ninlil.Dns.Server.Filtering/DnsFilterEngine.cs:92`). A timeout counts as "no match" (`:597-618`): - On a block list, the query is allowed (fail open). - On an exception (allow) list, the allow is skipped. The timeout is wall-clock, so a thread stalled by load or a GC pause trips it too. B23-16 found this while fixing a flaky test and kept it as the ReDoS guard. ### What changes - Compile every pattern with `RegexOptions.NonBacktracking`, which matches in linear time and needs no timeout. A pattern that engine refuses (backreferences, lookarounds, atomic groups and the like throw `NotSupportedException` at construction) falls back to the backtracking engine with today's timeout and today's rule. - `CompileOrNull` (`:626`) is also used by `FilterListEntriesController` and `FilterPatternPreviewController`, so what counts as a valid pattern must not change. - In `DnsFilterIndex`/`DnsFilterListIndex.cs`, record which entries use the fallback; the preview endpoint may report it (optional; if it adds a response field, an `api-regen` step follows in the same PR). - `DnsFilterPatternPrefilterTests` parity tests and `EvaluateDomainAsync_ForARegexThatTimesOut_AllowsTheNameAndLogsAWarning` are updated: the timeout test now uses a pattern that needs the fallback. ### Acceptance - [ ] Red first: a block-list entry `^(a+)+$` matched against 40 a's is blocked in linear time (no timeout, no warning); fails on HEAD. - [ ] A pattern with a backreference still compiles, runs on the fallback and keeps today's timeout rule. - [ ] `dotnet test src/dotnet/tests/Ninlil.Dns.Server.Filtering.Tests` passes 20 times in a row. - [ ] FilterEngine benchmarks before/after (Large) show no regression over 10 %. - [ ] README filter section states the rule. No schema or option change. ### Source `b23-design.md:522` (B23-16 production concern); `DnsFilterEngine.cs:606-616`. Owner decision 2026-10-31 (Q-BUG-1): "NonBacktracking first".
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil#53
No description provided.