Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const EOL_DATES: Record<string, string> = {
"24": "2028-04-30",
};

const MAX_VERSION_LENGTH = 256;

/**
* Check if a major version is EOL.
*/
Expand Down Expand Up @@ -52,6 +54,9 @@ export const getVersion = (): NodeVersion => {
* Compare the current node version with a target version string.
*/
const compareTo = (target: string): number => {
if (target.length > MAX_VERSION_LENGTH) {
return NaN;
}
if (target !== target.trim() || target.length === 0) {
return NaN;
}
Expand Down
8 changes: 8 additions & 0 deletions src/security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ describe("security fixes", () => {
const v = getVersion();
expect(v.isAtLeast("10.0.0")).toBe(true);
});

test("should reject version strings exceeding MAX_VERSION_LENGTH", () => {
const v = getVersion();
const longVersion = `${"1".repeat(300)}.0.0`;
// Should be fail-closed (return false) for all checks if string is too long
expect(v.isAtLeast(longVersion)).toBe(false);
expect(v.isBelow(longVersion)).toBe(false);
});
});