fix: validate --timeout CLI arg to prevent silent NaN abort#61
Open
dmchaledev wants to merge 1 commit into
Open
fix: validate --timeout CLI arg to prevent silent NaN abort#61dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
Previously, passing a non-numeric value like --timeout notanumber caused parseInt to return NaN. Since NaN is not null/undefined, the ?? fallback in fetch.ts was skipped, and setTimeout received NaN (treated as 0 by browsers and Node), aborting every request immediately with an opaque AbortError. The fix: - Errors immediately with a clear message if --timeout is missing its value or if the value parses to NaN or a non-positive number. - Uses the raw string (not String(NaN)) to exclude the timeout value from the URL-candidate scan, fixing a secondary bug where the timeout string could have been picked up as the URL. https://claude.ai/code/session_01V8MbP8UKNDFzXh4oMew2C2
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.
Summary
--timeout(e.g.--timeout notanumber) causedparseIntto returnNaN. BecauseNaNis notnull/undefined, the?? 10000fallback infetch.tswas bypassed.setTimeoutthen receivedNaN, which Node.js/browsers treat as0— aborting every request immediately with an opaqueAbortError.a !== String(timeoutMs)to exclude the timeout value from URL candidates. WhentimeoutMsisNaN,String(NaN) === 'NaN', not the actual raw string (e.g.'notanumber'), so the invalid input could be misidentified as the URL.--timeoutwith no following value (last arg, or immediately before another flag) now emits a clear error instead of silently ignoring the flag.Changes (
src/cli.ts)User-visible behaviour after fix
security-headers https://example.com --timeout notanumberError: --timeout value must be a positive integer in milliseconds (e.g. --timeout 5000), got: 'notanumber'+ exit 1security-headers https://example.com --timeoutError: --timeout requires a value in milliseconds (e.g. --timeout 5000)+ exit 1security-headers https://example.com --timeout --jsonsecurity-headers https://example.com --timeout 5000Test plan
npm run typecheck— passes (no TypeScript errors)npm test— all 82 existing tests passnode dist/cli.js https://example.com --timeout notanumber→ clear error message, exit 1node dist/cli.js https://example.com --timeout 5000→ normal reporthttps://claude.ai/code/session_01V8MbP8UKNDFzXh4oMew2C2
Generated by Claude Code