fix: report the post-redirect URL instead of silently mislabeling it#114
Merged
Conversation
Reimplements #109 on top of #99's SSRF-hardened fetch loop (redirect: 'manual' with per-hop private-IP validation) instead of the old redirect: 'follow' call #109 assumed, which would have silently reintroduced the SSRF-via-redirect gap. - src/fetch.ts: fetchHeadersWithMeta(url, options) returns {headers, finalUrl}, reusing the existing hop loop; fetchHeaders is now a thin wrapper. - src/types.ts: optional finalUrl on SecurityHeaderReport (additive). - src/index.ts: analyze() sets report.finalUrl when it differs from the input. - src/cli.ts: prints "Redirected to: <url>" and includes finalUrl in --json. - Updated test/cli.test.ts's fetch.js mock (previously exported fetchHeaders, which index.ts no longer calls) to export fetchHeadersWithMeta instead. Closes #93.
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
analyze(url)labels the report with the pre-redirect input URL even though the grade/findings describe whatever host the redirect chain actually landed on — e.g.http://→https://, apex →www, staging → a login page. Verified live againsthttp://github.com: report saidurl: "http://github.com"while every finding actually describedhttps://github.com/.Reimplements #109 (which is closed — its
fetchHeadersWithMetaused a plainfetch(url, {redirect: 'follow'}), predating #99's SSRF hardening) on top of the current hop-by-hop redirect loop insrc/fetch.ts, so the private-IP/redirect validation from #99 stays intact.Changes
src/fetch.ts:fetchHeadersWithMeta(url, options)returns{ headers, finalUrl }from the existing validated hop loop;fetchHeadersis now a thin wrapper, unchanged signature.src/types.ts: additive optionalfinalUrl?: stringonSecurityHeaderReport.src/index.ts:analyze()setsfinalUrlonly when it differs from the requested URL.src/cli.ts: printsRedirected to: <url>; included in--jsonoutput.README.md: documents the new field.test/fetch.test.tscoversfetchHeadersWithMetawith and without a redirect;test/cli.test.ts'sfetch.jsmock updated to exportfetchHeadersWithMeta(it previously mockedfetchHeaders, whichindex.tsno longer calls — would have broken silently otherwise).Verification
npm run typecheck,npm test(143/143),npm run buildall pass.node dist/cli.js http://github.com --json→url: "http://github.com",finalUrl: "https://github.com/".Closes #93.
Generated by Claude Code