fix: --timeout NaN causes immediate request abort#77
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
…st abort When `--timeout abc` is passed, parseInt returns NaN. Since NaN is not nullish, `NaN ?? 10000` stays NaN, and setTimeout(abort, NaN) fires immediately in JS (NaN coerces to 0), aborting every request. cli.ts: validate the parsed value and exit(1) with a clear message. fetch.ts: treat any non-finite or non-positive timeoutMs as the default 10000 ms so the public API is safe even when called directly with bad input. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011hppUsheemA66AhrzS5kDT
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.
Bug
When
--timeoutis passed a non-numeric value (e.g.security-headers https://example.com --timeout abc),parseInt('abc', 10)returnsNaN. BecauseNaNis not nullish, the??fallback infetch.tsdoesn't kick in:setTimeoutcoercesNaNto0, so theAbortControllerfires before the request even leaves the event loop. Every fetch silently times out immediately — the CLI exits withError: …on every URL, with no hint that the timeout value is the problem.Fix
src/cli.ts— validate the parsed timeout value and exit with a clear error message before attempting any fetch:src/fetch.ts— harden the public API so that even direct callers passingNaN/Infinity/0throughFetchOptionsget the 10 s default rather than a broken timer:Test plan
security-headers https://example.com --timeout abc→ printsError: --timeout must be a positive integer…and exits 1security-headers https://example.com --timeout -1→ same errorsecurity-headers https://example.com --timeout 5000→ works as beforesecurity-headers https://example.com(no timeout flag) → works as before, uses 10 s default🤖 Generated with Claude Code
https://claude.ai/code/session_011hppUsheemA66AhrzS5kDT
Generated by Claude Code