Repository navigation
zone: strip trailing dots from a name in linear time - #89
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
🟢 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (CodeQLjs/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 matchesexample.comfor 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.