Skip to content

zone: strip trailing dots from a name in linear time - #89

Merged
msimerson merged 2 commits into
mainfrom
zone-name-regex
Oct 16, 2026
Merged

msimerson merged 2 commits into
mainfrom
zone-name-regex

Conversation

@msimerson

@msimerson msimerson commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

canonicalZoneName() stripped /\.+$/. On a long run of dots that isn't at the end of the string, the regex restarts at every dot, so the time is quadratic (CodeQL js/polynomial-redos, alert 29). With 50k dots before a letter it took 858 ms.

It now walks back over the trailing dots in a loop. It strips every trailing dot, as before, so example.com.. still matches example.com for a caller that skips the route's schema. The loop runs in linear time: 200k dots, mid-name or trailing, take about 1 ms.

Tests pass on mysql, json and toml.

canonicalZoneName() stripped /\.+$/, which backtracks over every run of
dots: 50k dots before a letter took 858 ms (CodeQL js/polynomial-redos,
alert 29). The zone schema refuses a name ending in more than one dot,
so stripping one is enough; dns-nameserver and 2.x strip one too.
Stripping one dot left example.com.. distinct from example.com for a
caller that skips the route's schema. A loop strips them all, as /\.+$/
did, in linear time.
@msimerson msimerson changed the title zone: strip one trailing dot from a name zone: strip trailing dots from a name in linear time Oct 16, 2026
@msimerson
msimerson requested a balanced review from Copilot October 16, 2026 04:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The isolated change preserves normalization behavior and removes quadratic processing, with no unresolved findings.

0 open findings

What changed in this PR

Updates zone-name normalization to remove quadratic regex processing while preserving trailing-dot removal and lowercase conversion.

Changes:

  • Replaces the trailing-dot regex with a linear-time backward scan.
  • Adds a comment explaining the performance rationale.
File Description
lib/​zone/​store/​base.js Makes trailing-dot removal linear-time.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@msimerson
msimerson merged commit 1029fda into main Oct 16, 2026
14 checks passed
@msimerson
msimerson deleted the zone-name-regex branch October 16, 2026 04:11
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.

2 participants