Skip to content

fix(shared): strip credentials and request bodies when safeFetch follows redirects - #1137

Open
Adityakk9031 wants to merge 1 commit into
databuddy-analytics:stagingfrom
Adityakk9031:fix/shared-safe-fetch-redirect-credentials
Open

Adityakk9031 wants to merge 1 commit into
databuddy-analytics:stagingfrom
Adityakk9031:fix/shared-safe-fetch-redirect-credentials

Conversation

@Adityakk9031

@Adityakk9031 Adityakk9031 commented Oct 15, 2026 •

Copy link
Copy Markdown

Problem

safeFetch re-sends the original headers and body to every redirect target. A webhook configured with Authorization or a secret header (WebhookProvider) leaks them to whatever host the endpoint redirects to, and a 301/302/303 redirect of a POST is replayed as a POST with the body.

Fix

New exported redirectInit applied on each hop:

  • cross-origin: keep only accept, accept-language, content-type, user-agent
  • 301/302 on POST and 303 on non-GET/HEAD: switch to GET and drop the body and content-* headers (as in the Fetch spec)
  • 307/308 and same-origin hops are otherwise unchanged

Tests

Added redirectInit cases to ssrf-guard.test.ts.


Summary by cubic

Fixes safeFetch so redirects no longer forward credentials or request bodies to the redirect target.

  • Cross-origin hops keep only accept, accept-language, content-type, and user-agent headers, dropping Authorization and secret headers.
  • 301/302/303 redirects of a POST switch to GET and drop the body and content-* headers, matching the Fetch spec.
  • Same-origin and 307/308 redirects keep behavior unchanged.
  • Added tests for the new redirectInit export.

Written for commit bb46799. Summary will update on new commits.

View guided diff

…ows redirects

safeFetch re-sent the original headers and body to every redirect target, so a
webhook configured with Authorization or secret headers leaked them to whatever
host the endpoint redirected to. Cross-origin hops now keep only benign
headers, and 301/302/303 redirects of a POST become a body-less GET as in the
Fetch spec.
@vercel

vercel Bot commented Oct 15, 2026

Copy link
Copy Markdown

@Adityakk9031 is attempting to deploy a commit to the Databuddy OSS Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a70477e0-19e1-464a-a385-fce6e659c133

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Critical impact] Modifies how the fetch wrapper handles HTTP redirects.

The PR appears safe to merge, with non-blocking fixes recommended for redirected robots.txt checks and redirect-chain tests.

Findings

  1. P2 Redirects can hide crawler rules ▶
  2. P2 Redirect chains remain untested ▶

Summary

Adds redirectInit and applies it on each safeFetch redirect.

  • Redirects now filter headers across origins and rewrite selected requests as GETs.

Reviews (1) · Last reviewed commit: "fix(shared): strip credentials and reque..." · Reviewed by Greptile

Comment on lines +210 to +215
const CROSS_ORIGIN_REDIRECT_HEADERS = new Set([
"accept",
"accept-language",
"content-type",
"user-agent",
]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redirects can hide crawler rules

The allowlist drops accept-encoding, including the identity value required by fetchRobotsTxt. If a website redirects to another origin that sends compressed content, fetchRobotsTxt rejects the response. checkAiRobots then reports no robots.txt and treats blocked crawlers as allowed. Preserve accept-encoding across redirects; it does not carry credentials.

Suggested change
const CROSS_ORIGIN_REDIRECT_HEADERS = new Set([
"accept",
"accept-language",
"content-type",
"user-agent",
]);
const CROSS_ORIGIN_REDIRECT_HEADERS = new Set([
"accept",
"accept-encoding",
"accept-language",
"content-type",
"user-agent",
]);

});
});

describe("redirectInit", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redirect chains remain untested

The new tests call only redirectInit; none exercise the changed safeFetch loop. Removing the assignment to fetchInit would leave every new test passing while restoring the original behavior.

Add a test with multiple redirects that checks the outgoing requests. Verify that stripped credentials stay stripped and that a POST changed to GET does not regain its body.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant