Repository navigation
fix(proxy): replace Fernet plugin session claims with AES-GCM - #42915
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Fernet (AES-128-CBC + HMAC-SHA256) is not an approved construction for the FIPS 140-3 image. Plugin session claims now use AES-256-GCM through a key-taking pair (encrypt_aes_gcm_with_key / decrypt_aes_gcm_with_key) that the existing _encrypt_aes_gcm / _decrypt_aes_gcm wrappers delegate to, keyed by the unchanged HMAC-SHA256(LITELLM_SALT_KEY, plugin_name) per-plugin key. Claims live 30 seconds so no Fernet read-compatibility window is kept. Resolves LIT-8428 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
bugbot run |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
…n_claim_aes_gcm # Conflicts: # litellm/proxy/common_utils/encrypt_decrypt_utils.py
|
@greptileai review latest head |
|
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 573abe6. Configure here.
TLDR
Problem this solves:
cryptography.ferneton this pathHow it solves it:
v2:gcm:<b64(nonce||ct||tag)>, same 30 s TTLencrypt_aes_gcm_with_key/decrypt_aes_gcm_with_keyexported fromencrypt_decrypt_utils_encrypt_aes_gcm/_decrypt_aes_gcmdelegate to them, bytes unchangedTypeAdapter, no untyped dictUser Flow
Before: an admin opens a plugin in the dashboard and the plugin receives a Fernet token it must decrypt with
cryptography.fernet{"session_claim": "gAAAAAB..."}After: the same flow hands the plugin an AES-256-GCM claim under the same per-plugin key
{"session_claim": "v2:gcm:..."}{plugin, user_id, user_role, exp}expLinear ticket
Resolves LIT-8428
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)Screenshots / Proof of Fix
Setup: two-worker proxy per leg with
LITELLM_SALT_KEY=sk-integration-salt, real Postgres and Redis, the plugin registered throughPOST /config/field/updatewith{"field_name":"plugins","field_value":[{"name":"chat-ui","url":"http://127.0.0.1:9"}],"config_type":"general_settings"}(200 on both legs). The plugin-side decrypt below is what a plugin does with its own key,HMAC-SHA256(LITELLM_SALT_KEY, "chat-ui"). No provider call is involved on this pathBefore (merge base 2e1a98f)
curl -s "http://127.0.0.1:4200/api/plugins/auth-token?plugin_name=chat-ui" -H "Authorization: Bearer sk-integration-master"{"session_claim":"gAAAAABqw1dHtLyLmSLoXmMXEdxD2YKcqYdeEdo9Wy...AESGCM(key).decrypt(...)on that claim:not a v2:gcm claim (Fernet token)admin/ master key, click thechat-uiplugin tab, DevTools Network shows the/api/plugins/auth-tokenresponse as a Fernet tokenDashboard screenshots were captured on the first audit head 3f90e54; the merge from main since then did not touch
plugin_routes.pyor the dashboard plugin page, so the same screens apply at 573abe6After (head 573abe6)
curl -s "http://127.0.0.1:4300/api/plugins/auth-token?plugin_name=chat-ui" -H "Authorization: Bearer sk-integration-master"{"session_claim":"v2:gcm:3H-uwNIeTEOOIpssgW-v7_TRu17JDVRspqx...AESGCM(key).decrypt(raw[:12], raw[12:], None):{"plugin": "chat-ui", "user_id": "default_user_id", "user_role": "proxy_admin", "exp": 1790237891}InvalidTag; same claim under theother-pluginkey:InvalidTagplugin_nameas a list, a 5 KB string, or empty: 404 on both legsPOST /model/newstoresapi_keyencrypted on both legs andPOST /v1/chat/completionsthrough that model returns 200 on both; a value encrypted at the merge base decrypts at the tip (legacy dual read intact)/api/plugins/auth-tokenresponse starting withv2:gcm:; the plugin iframe itself points at a dead port in this rig so its load failure is expectedDeterministic integration audit (!audit)
Head 573abe6, merge base 2e1a98f. Test file
tests/integration/authorization/test_plugin_session_claim.py, seeds--hypothesis-seed=4106601 --integration-order-seed=0, retries and reruns disabledgAAAA...)v2:gcm:, decrypts under HMAC(salt, plugin), payload and exp in [now+30, now+31], fresh nonce per claimtest_plugin_claim_is_aes_gcm_under_the_hmac_derived_plugin_keytest_plugin_claim_rejects_other_plugin_key_wrong_salt_and_tamperingtest_plugin_auth_token_still_gates_registration_and_bearertest_plugin_claims_survive_a_worker_kill_during_a_burstCircleCI at this head: pipeline 90851,
integration-managementjob 2240442 andintegration-management-replicajob 2240450 run all fourtest_plugin_session_claimnodes green on both; the shards themselves are red ontest_team_scoped_models::test_v2_model_info_reports_a_team_model_to_team_and_non_team_keysand the threetest_vector_store_file_list_managed_ids::test_provider_errors_reach_the_caller_and_other_models_keep_mappingcases, the same four that fail on the last threemainintegration runs (jobs 2240372, 2240196, 2240139).integration-cost,integration-mcp,integration-database-replica,integration-providers,llm_translation_testing(xAI reasoning) are red identically on main;logging_testing::test_langsmith_queue_loggingis in the CircleCI flaky-test list and does not touch this diffNot run as integration cells: expired claim (needs a 30 s wall-clock wait, covered by
tests/unit/proxy/test_plugin_routes.py::test_expired_plugin_claim_is_rejected), forged audience, legacy Fernet token and invalid JSON (unit tests in the same file). Out of scope: iframe load into a real third-party plugin, Postgres outage (the claim path does not touch Postgres)Type
🐛 Bug Fix
Caveats (if any)
Severe
v2:gcm:; a plugin decrypting withcryptography.fernetmust switch to AES-GCM under the same derived keydocs/proxy/plugins.mdin litellm-docs still shows the Fernet snippet and needs a companion docs PRLow
POST /config/field/updateforpluginsonly registers the plugin in the worker that served the request until the other workers restart. Pre-existing, outside this diff, observed while building the proofLink to Devin session: https://app.devin.ai/sessions/e12dc9e7f9a244cb955437b8503c7d25
Open in Devin Desktop: https://app.devin.ai/desktop/session/e12dc9e7f9a244cb955437b8503c7d25?variant=devin
Requested by: @yucheng-berri