Repository navigation
Conversation
Strix Security ReviewWarning This pull request has 29 commits after the last Strix review ( 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 summaryThis PR hardens Ruled out (2)
Fixed the findings? re-run the review, or tag Review 1 on this PR · Reviewed by Strix |
| # 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) |
There was a problem hiding this comment.
🟡 _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;
dataandjsonare such carriers andrequestshappily sends a body on a GET. _strip_cross_origin_credentials()is called between hops but only popscookies,auth,certandparams, sodataandjsonremain in the dict that the next_raw_get()sends.safe_get()copies every caller keyword argument once intorequest_kwargsand 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.
| # 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.
ab00f4a to
59a7eaa
Compare
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.
59a7eaa to
3556afe
Compare
Vidit Ostwal (Vidit-Ostwal)
left a comment
There was a problem hiding this comment.
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.
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 leftauth,certandparamsin 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
auth,cert,params,dataorjsonafter_same_origin()reported an origin change (http to https on the same host).dataandjsonbodies), andlib/crewai-tools/tests/utilities/test_safe_requests.pypasses 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-generatedlabel; external contributors cannot add it with my current permissions.