Skip to content

fix(tools): drop credentials on cross-origin redirects - #9516

Open
Kiko0301 wants to merge 1 commit into
crewAIInc:mainfrom
Kiko0301:fix/safe-get-cross-origin-credentials
Open

Kiko0301 wants to merge 1 commit into
crewAIInc:mainfrom
Kiko0301:fix/safe-get-cross-origin-credentials

Conversation

@Kiko0301

@Kiko0301 Kiko0301 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9511

Summary

safe_get() follows redirects itself so that every hop is validated, and it reuses the caller's request options for each hop. When a hop changes origin, _strip_cross_origin_credentials() removed sensitive headers and cookies, but left auth, cert and params in the reused options, and left request bodies (data, json) in place as well. The next _raw_get() call therefore replayed an HTTP auth handler, a TLS client certificate, query parameters and a request body to the redirect target's origin.

This change drops all of them together with the headers and cookies, so a cross-origin hop receives no caller credentials in any form. Same-origin redirects are unchanged.

Verification

  • The new regression test fails on main for every credential kind: the second hop's captured kwargs still contain auth, cert, params, data or json after _same_origin() reported an origin change (http to https on the same host).
  • With this change the test passes (parametrized over data and json bodies), and lib/crewai-tools/tests/utilities/test_safe_requests.py passes in full (39 passed).

The test mocks _raw_get, as the existing redirect tests do, so no network access is involved.

AI assistance

I used an AI coding agent to investigate, implement, and test this change, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.

@strix-security

strix-security Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 29 commits after the last Strix review (ab00f4a). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

To fix before merging (1)

PR summary: `safe_get()` follows redirects itself and previously replayed the caller's `auth`, `cert` and `params` options to a redirect target on a different origin. The PR drops those three options in `_strip_cross_origin_credentials()`, leaving same-origin redirects unchanged, and adds a regression test.

Review summary

This PR hardens safe_get()'s cross-origin redirect handling by dropping auth, cert and params from the kwargs reused on the next hop, and adds a regression test for it. The change itself is correct and fail-closed: the strip happens before the next _raw_get(), persists for the rest of the chain (including a hop back to the original origin), a fresh session per hop already prevents cookie carryover, and nothing in the redirect loop, the SSRF IP pinning or the hop-close/history handling regresses. One gap remains in the same sanitizer: it is a deny-list, so data and json request bodies are still rebuilt and sent to the redirect target's origin, which the validation agent confirmed dynamically against the real module — a JSON body and a form body were both received verbatim by a second origin while the newly stripped channels were absent. No in-repo caller passes a request body to safe_get, so the exposure is limited to consumers of this public helper; the finding notes the fix is best made an allow-list rather than one more deny-list key.

Ruled out (2)
  • Do credential headers whose names evade the sensitive-name check still reach a cross-origin redirect target?
    The name matching is untouched by this PR and the new statements never touch it; no in-repo caller supplies such a header, the redirect target cannot influence header names, and headers in this codebase are developer- or fixed-default-configured, so this is pre-existing deny-list hardening rather t…
  • Can the origin comparison treat two different origins as the same, or can a later hop regain the stripped credentials?
    The comparison requires byte-identical scheme and netloc, which is the same string the connection authority is derived from, so every spelling difference (case, default port, trailing dot, userinfo, IDN) fails closed and the stripped kwargs are never re-added by the new per-hop session.

Fixed the findings? re-run the review, or tag @strix-security in a PR comment to run a fresh review.

Review 1 on this PR · ab00f4a · requested Nov 17 12:41 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@strix-security strix-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Strix flagged a new security finding below. See the pinned summary comment for the full PR status.

Comment on lines +62 to +66
# Auth handlers, TLS client certificates and query parameters are
# credentials too, and each is reapplied by the next ``_raw_get`` call.
# Drop them rather than replaying a caller's secret to a new origin.
for key in ("auth", "cert", "params"):
sanitized.pop(key, None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 _strip_cross_origin_credentials() leaves data/json request bodies in place, so safe_get() replays a caller's body to a cross-origin redirect target

Severity: MEDIUM

TL;DR: The sanitizer at safe_requests.py:52-67 drops cookies, auth, cert and params on an origin change but not data/json, and safe_get() re-sends the same kwargs dict on every hop, so a caller's request body reaches the redirect target's origin.

Impact: Whoever controls or compromises a URL the app fetches can redirect it and receive any credential or personal data a caller placed in the request body, such as an API token or client secret, then use it against the account it belongs to.

Root cause:

  • The sanitizer is written as a deny-list of credential keyword arguments, so any credential carrier it does not explicitly name survives the origin change; data and json are such carriers and requests happily sends a body on a GET.
  • _strip_cross_origin_credentials() is called between hops but only pops cookies, auth, cert and params, so data and json remain in the dict that the next _raw_get() sends.
  • safe_get() copies every caller keyword argument once into request_kwargs and reuses that same dict for each hop, so the body is rebuilt verbatim for the new origin instead of being limited to the origin the caller addressed.
Suggested change
# Auth handlers, TLS client certificates and query parameters are
# credentials too, and each is reapplied by the next ``_raw_get`` call.
# Drop them rather than replaying a caller's secret to a new origin.
for key in ("auth", "cert", "params"):
sanitized.pop(key, None)
# Auth handlers, TLS client certificates, query parameters and request
# bodies are credentials too, and each is reapplied by the next
# ``_raw_get`` call. Drop them rather than replaying a caller's secret to
# a new origin.
for key in ("auth", "cert", "params", "data", "json"):
sanitized.pop(key, None)
Prompt to fix with AI
This is a security vulnerability found during a code review.

Vulnerability: `_strip_cross_origin_credentials()` leaves `data`/`json` request bodies in place, so `safe_get()` replays a caller's body to a cross-origin redirect target
Severity: MEDIUM
CWE: CWE-200

**TL;DR:** The sanitizer at `safe_requests.py:52-67` drops `cookies`, `auth`, `cert` and `params` on an origin change but not `data`/`json`, and `safe_get()` re-sends the same kwargs dict on every hop, so a caller's request body reaches the redirect target's origin.

**Impact:** Whoever controls or compromises a URL the app fetches can redirect it and receive any credential or personal data a caller placed in the request body, such as an API token or client secret, then use it against the account it belongs to.

**Root cause:**
- The sanitizer is written as a deny-list of credential keyword arguments, so any credential carrier it does not explicitly name survives the origin change; `data` and `json` are such carriers and `requests` happily sends a body on a GET.
- `_strip_cross_origin_credentials()` is called between hops but only pops `cookies`, `auth`, `cert` and `params`, so `data` and `json` remain in the dict that the next `_raw_get()` sends.
- `safe_get()` copies every caller keyword argument once into `request_kwargs` and reuses that same dict for each hop, so the body is rebuilt verbatim for the new origin instead of being limited to the origin the caller addressed.

Location: lib/crewai-tools/src/crewai_tools/security/safe_requests.py:62-66
Context: sanitizer drops auth/cert/params but not request bodies
```
// Before:
    # Auth handlers, TLS client certificates and query parameters are
    # credentials too, and each is reapplied by the next ``_raw_get`` call.
    # Drop them rather than replaying a caller's secret to a new origin.
    for key in ("auth", "cert", "params"):
        sanitized.pop(key, None)
// After:
    # Auth handlers, TLS client certificates, query parameters and request
    # bodies are credentials too, and each is reapplied by the next
    # ``_raw_get`` call. Drop them rather than replaying a caller's secret to
    # a new origin.
    for key in ("auth", "cert", "params", "data", "json"):
        sanitized.pop(key, None)
```

Location: lib/crewai-tools/src/crewai_tools/security/safe_requests.py:150-150
Context: caller kwargs are copied once and reused for every hop
```
    request_kwargs = {**kwargs, "allow_redirects": False}
```

How to fix:
Treat the sanitizer as an allow-list of request options that may cross an origin boundary (timeout, headers that survive the name check) and drop everything else, rather than enumerating credential keys to remove. If a body must be supported at all, refuse to forward it once the hop changes origin instead of forwarding it without the accompanying credentials. Add the request body to the existing cross-origin regression test so the "no caller credentials in any form" guarantee is actually asserted, and cover both `data` and `json`.

Please fix this vulnerability. If you propose a fix, make it concise and minimal.

React 👍 / 👎 to tune Strix for this repo. A repo collaborator (or the PR author) can resolve this thread to dismiss the finding.

@Kiko0301
Kiko0301 force-pushed the fix/safe-get-cross-origin-credentials branch from ab00f4a to 59a7eaa Compare November 18, 2026 06:38
safe_get follows redirects manually, so the request options from the
original hop are re-applied to every new origin. Only headers, cookies
and proxies were being removed when the origin changed, leaving auth
handlers, TLS client certificates, query parameters and request bodies
to be sent to the redirect target.

Remove auth, cert, params, data, json and files on a cross-origin hop
and cover the behavior with regression tests.
@Vidit-Ostwal
Vidit Ostwal (Vidit-Ostwal) force-pushed the fix/safe-get-cross-origin-credentials branch from 59a7eaa to 3556afe Compare November 19, 2026 15:18

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix. Dropping auth, cert and params (and the body options) in _strip_cross_origin_credentials closes the replay on cross-origin hops and matches how headers and cookies are already handled.
I checked that the new test fails on main (both the data and json cases) and passes on this branch, and that the rest of test_safe_requests.py still passes.
Optional follow-up: a small assertion that a same-origin redirect still keeps auth and params would pin down the unchanged behavior. files is dropped but isn't covered by a test, though safe_get is GET-only.

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.

[BUG] safe_get replays auth, client certificates and query credentials on cross-origin redirects

2 participants