Repository navigation
fix(updater): linear-time version parsing, skip malformed release tags (#172) - #310
Conversation
|
/mira pause |
Mira PR WalkthroughThis PR fixes a ReDoS vulnerability in the version parsing logic by replacing a complex regex with linear-time validation. It also improves robustness by skipping malformed release tags instead of failing the entire update check. The changes ensure security while maintaining backward compatibility with valid version formats. ⏳ Code review in progress…
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Mira Review Summary
The PR addresses CodeQL alerts by replacing the exponential-time SemVer regex with linear-time parsing and adding graceful handling of malformed tags. The changes look good overall. I found a minor issue: empty tag names would pass the type check but be rejected later; adding explicit empty check improves clarity. Also, the test's 500ms timeout may be flaky on slow CI. The error messages could be more specific for debugging. No critical bugs found.
| const checksum = latest.release.assets?.find((value) => value.name === "SHA256SUMS"); | ||
| if (!asset || !checksum) throw new Error("update release is missing verified assets"); | ||
| return Object.freeze({ available: true, currentVersion: current.normalized, version: latest.version.normalized, releaseUrl: latest.release.html_url, assetUrl: asset.url, checksumUrl: checksum.url }); | ||
| } |
There was a problem hiding this comment.
Clarity
💡 Suggestion
Error message could be more specific
The error message "version: expected semver" is thrown for multiple different failure cases: non-string, too long, pattern mismatch, invalid identifier. When debugging, it's hard to know which condition failed. Consider adding more specific error messages for each validation step, or at least differentiate between length and pattern failures.
| } | |
| if (typeof value !== "string") throw new TypeError("version: expected semver"); | |
| if (value.length > MAX_VERSION_LENGTH) throw new TypeError("version: too long"); |
Prompt for AI Agents
In src/update-check.js line 30, split the validation to provide more specific error messages. First check if value is a string, then check length separately with a distinct error message like 'version: too long'.
Apply this code change:
if (typeof value !== "string") throw new TypeError("version: expected semver");
if (value.length > MAX_VERSION_LENGTH) throw new TypeError("version: too long");
Not useful? Reply
@mira-reviewer-rk rejectto dismiss this suggestion.
There was a problem hiding this comment.
Done: the length case now says "expected semver (too long)".
a3fc85b to
2353722
Compare
2353722 to
22dfe8e
Compare
What changed
parseVersioninsrc/update-check.jsno longer uses the single SemVer regex with the nested[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*groups. It matches the shape with one unambiguous pattern (-([0-9A-Za-z.-]+)), then checks each prerelease identifier on its own: non-empty, alphanumerics and hyphens only, no leading zeros on numeric parts. Versions are capped at 128 characters. Valid versions parse exactly as before.Why
Fixes CodeQL alerts #2 (js/redos, error) and #1 (js/polynomial-redos, warning) on
src/update-check.js. Release tags come from the network, so a crafted tag could hang the updater.Checks
Issue
Part of #172