Repository navigation
fix(responses): encrypt the response id on every streamed event - #39534
mateo-berri merged 3 commits into
Conversation
Background streaming emits event types with no typed model, which arrive as GenericEvent holding a plain dict. Only typed events had their nested response id rewritten, so those frames advertised the raw internal id while their siblings advertised the encrypted one. The raw shape skips the ownership check, so any other key could retrieve or cancel that response. Rewrite the advertised id wherever an event carries one, whichever shape it arrives in, so a future event type cannot reopen this.
Greptile SummaryThis PR applies consistent security hardening to response identifiers across typed and generic streamed events.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/proxy/hooks/responses_id_security.py | Centralizes streamed response-identifier rewriting and extends it to generic mapping payloads without an identified blocking regression. |
| tests/test_litellm/test_responses_id_security.py | Adds focused mocked regression tests covering identifier consistency, serialization, and preservation of sibling event fields. |
| ruff-strict-budget.json | Reduces the B010 lint budget to match the source cleanup. |
| type-discipline-budget.json | Reduces the relevant type-discipline budgets to reflect improved typing. |
Reviews (2): Last reviewed commit: "fix(responses): encrypt the response id ..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit d3b6ce9. Configure here.
…itellm_fix_responses_queued_id_encryption # Conflicts: # type-discipline-budget.json
…itellm_fix_responses_queued_id_encryption # Conflicts: # type-discipline-budget.json
TLDR
Problem this solves:
response.queuedone skipped the gateway's ownership checkHow it solves it:
User Flow
Before: a developer opening a background streaming response gets back one id that any other key on the same gateway can read.
"stream": trueand"background": trueresponse.created,response.in_progressandresponse.completedframes each carry the same long scrambled idresponse.queuedframe carries a different, much shorter id in an obviously different formatresponse.queued} and gets 200 with the first developer's whole response, prompt and output text includedAnyone who sees a
response.queuedframe can read and cancel the response it belongs to.After: every frame carries the same protected id, so the second developer is refused on all of them.
"stream": trueand"background": trueresponse.created,response.in_progressandresponse.completedframes each carry the same long scrambled idresponse.queuedframe now carries that same long scrambled idAnother user can no longer read or cancel a response they do not own.
Relevant issues
Linear ticket
Resolves LIT-6832
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Both legs ran against a live proxy booted with
--num_workers 2against the real OpenAI API, same commands in the same order, only the commit differing. Response ids are redacted; their length and format are the whole point.Shared setup, two keys belonging to two different users:
Before (e6e5be0)
Four frames, two distinct ids.
response.queuedhands the client the gateway's own internal id format instead of the protected one every other frame carries.response.created:response.queued:response.createdid, and is correctly refused:response.queuedid, and is NOT refused:response.queuedid. The gateway does not refuse it, so the request goes upstream and only the provider answers:After (2df5f4a)
Four frames, one distinct id.
response.created:response.queued, which is now the same id:response.createdid:response.queuedid:response.queuedid:Observations from the run:
background: truewas never affected/v1/chat/completionsand/v1/messagescarry no response idsresponse.queued, unrelatedLive PR risk: base vs head vs merge-ref
Same scenarios on three proxies, each booted with
--num_workers 2on its own Postgres database, with keys for two users (lit6832_user_aowns the response,lit6832_user_bholds only itsresponse.queuedid): base is the merge-base e6e5be0, head is 2df5f4a, and merge-ref is 2df5f4a merged with staging ab44e8d (8a777f30, clean merge, no drift on the responses surface)response.queuedidPOST /v1/responsesstream+backgroundPOST /openai/v1/responsesGET /v1/responses/{id}GET /v1/responses/{id}/input_itemsPOST /v1/responseswithprevious_response_idPOST /v1/responses/{id}/cancelDELETE /v1/responses/{id}Identical on every side: A's own retrieve, input_items, chaining, and delete with the queued id (200); the non-streaming
background: truecreate (encrypted id, B gets 403 on retrieve and cancel,LiteLLM_ManagedObjectTable.unified_object_idholds the 477-char encrypted id);claude-sonnet-5streaming through/v1/responses(typed events, encrypted everywhere);/health/readiness200; and the same successful call types and spend per side. One difference outside the PR: OpenAI stalled the head side's first background stream afterresponse.queued, sending only its own keepalive frames for 240 s until the client gave up (the proxy log shows no upstreamresponse.in_progresschunk ever arrived), so that side has 15 spend rows to the others' 16; three reruns on head streamed to completion in about 6 s, as did base and merge-ref. Not observed live: the enterprisecheck_responses_costpoller, which reads that stored id and is untouched by this PRCircleCI at the tip (pipeline 89061, workflow 78646cb8, failed jobs rerun as 75d33c81): 40 of 43 jobs green, the same two red on both runs, both staging-side and outside this diff.
litellm_router_unit_testingfailstest_no_linear_scans_in_routeron the twoRoutermethods #39468 added (red on staging's own pipeline 89058, tracked in LIT-6911).e2e_ui_testingfailstests/e2e/ui/tests/users/searchUsers.spec.ts, which still looks for theSearch by email…placeholder that #39604 renamed toSearch by email or ID…(merged 21:14Z, after staging's last scheduled pipeline at 21:09Z, tracked in LIT-6919).upload-coveragedid not run because of those twoType
🐛 Bug Fix
Caveats (if any)
Low
Final Attestation
Note
High Risk
Security fix for proxy response-id isolation; incorrect rewriting could still leak provider ids or break legitimate retrieve/cancel flows.
Overview
Fixes a cross-tenant authorization bypass on background
/v1/responsesstreams: frames likeresponse.queuedarrived asGenericEventwith a plainresponsedict, so their providerresp_*id was never rewritten while typed events got the encrypted id—clients could read or cancel another user’s response with that shorter id.ResponsesIDSecuritynow routes all outbound id rewriting through_rewrite_advertised_id, which updates top-levelid, nestedResponsesAPIResponse, or dict payloads validated via Pydantic._encrypt_response_iddelegates to that helper and keeps the per-request cache so every frame advertises the same encrypted id.Regression tests simulate a mixed background stream (typed + generic events) and assert a single encrypted id, no raw provider id in serialized output, and unchanged sibling fields. Lint/type-discipline budget files are nudged down slightly.
Reviewed by Cursor Bugbot for commit d3b6ce9. Bugbot is set up for automated code reviews on this repo. Configure here.