Skip to content

fix(proxy): replace Fernet plugin session claims with AES-GCM - #42915

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
litellm_fips_b4_plugin_claim_aes_gcm
Open

devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
litellm_fips_b4_plugin_claim_aes_gcm

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Plugin session claims were Fernet (AES-128-CBC + HMAC), not FIPS 140-3 approved
  • FIPS builds cannot ship cryptography.fernet on this path

How it solves it:

  • Claims are now AES-256-GCM, v2:gcm:<b64(nonce||ct||tag)>, same 30 s TTL
  • Key stays HMAC-SHA256(LITELLM_SALT_KEY, plugin_name), used directly as the GCM key
  • encrypt_aes_gcm_with_key / decrypt_aes_gcm_with_key exported from encrypt_decrypt_utils
  • Stored-value _encrypt_aes_gcm / _decrypt_aes_gcm delegate to them, bytes unchanged
  • Claim verify parses the payload with a Pydantic TypeAdapter, no untyped dict

User Flow

Before: an admin opens a plugin in the dashboard and the plugin receives a Fernet token it must decrypt with cryptography.fernet

  1. The admin opens http://localhost:4000/ui/ and clicks a registered plugin tab
  2. The dashboard calls GET http://localhost:4000/api/plugins/auth-token?plugin_name=chat-ui and gets {"session_claim": "gAAAAAB..."}
  3. The plugin iframe receives that claim over postMessage and decrypts it with Fernet under its HMAC-derived key
  4. On a FIPS 140-3 image the Fernet primitives are not approved, so the plugin auth path cannot be certified

After: the same flow hands the plugin an AES-256-GCM claim under the same per-plugin key

  1. The admin opens http://localhost:4000/ui/ and clicks a registered plugin tab
  2. The dashboard calls GET http://localhost:4000/api/plugins/auth-token?plugin_name=chat-ui and gets {"session_claim": "v2:gcm:..."}
  3. The plugin iframe receives that claim over postMessage and decrypts it with AES-GCM under the same HMAC-derived key, reading {plugin, user_id, user_role, exp}
  4. A claim for another plugin, a tampered byte, or a wrong salt fails the GCM tag; a claim older than 30 s is rejected on exp

Linear ticket

Resolves LIT-8428

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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 through POST /config/field/update with {"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 path

Before (merge base 2e1a98f)

  1. curl -s "http://127.0.0.1:4200/api/plugins/auth-token?plugin_name=chat-ui" -H "Authorization: Bearer sk-integration-master"
  2. {"session_claim":"gAAAAABqw1dHtLyLmSLoXmMXEdxD2YKcqYdeEdo9Wy...
  3. Plugin-side AESGCM(key).decrypt(...) on that claim: not a v2:gcm claim (Fernet token)
  4. Admin UI http://127.0.0.1:4200/ui, login admin / master key, click the chat-ui plugin tab, DevTools Network shows the /api/plugins/auth-token response as a Fernet token

Dashboard screenshots were captured on the first audit head 3f90e54; the merge from main since then did not touch plugin_routes.py or the dashboard plugin page, so the same screens apply at 573abe6

Before: dashboard auth-token response is a Fernet token

After (head 573abe6)

  1. curl -s "http://127.0.0.1:4300/api/plugins/auth-token?plugin_name=chat-ui" -H "Authorization: Bearer sk-integration-master"
  2. {"session_claim":"v2:gcm:3H-uwNIeTEOOIpssgW-v7_TRu17JDVRspqx...
  3. Plugin-side AESGCM(key).decrypt(raw[:12], raw[12:], None): {"plugin": "chat-ui", "user_id": "default_user_id", "user_role": "proxy_admin", "exp": 1790237891}
  4. Same claim with one ciphertext byte flipped: InvalidTag; same claim under the other-plugin key: InvalidTag
  5. Unauthenticated GET: 401 on both legs; plugin_name as a list, a 5 KB string, or empty: 404 on both legs
  6. Stored-value path unchanged: POST /model/new stores api_key encrypted on both legs and POST /v1/chat/completions through that model returns 200 on both; a value encrypted at the merge base decrypts at the tip (legacy dual read intact)
  7. Admin UI http://127.0.0.1:4300/ui, same steps, DevTools Network shows the /api/plugins/auth-token response starting with v2:gcm:; the plugin iframe itself points at a dead port in this rig so its load failure is expected

After: dashboard auth-token response is a v2:gcm claim

Deterministic 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 disabled

run id commit result
lit8428-base-run1 2e1a98f 4 failed (claims are Fernet gAAAA...)
lit8428-head-run1 573abe6 4 passed
lit8428-head-run2 573abe6 4 passed, identical collected and passed node list, 0 skipped
cell node id base head
claim is v2:gcm:, decrypts under HMAC(salt, plugin), payload and exp in [now+30, now+31], fresh nonce per claim test_plugin_claim_is_aes_gcm_under_the_hmac_derived_plugin_key FAIL PASS
other plugin key, wrong salt, flipped byte all raise InvalidTag test_plugin_claim_rejects_other_plugin_key_wrong_salt_and_tampering FAIL PASS
401 without bearer, non-admin refused, unknown plugin_name refused, admin gets claim test_plugin_auth_token_still_gates_registration_and_bearer FAIL (format assert only, gating identical) PASS
chaos: 30-request burst across both workers with one worker killed mid-burst, every claim decrypts, distinct nonces test_plugin_claims_survive_a_worker_kill_during_a_burst FAIL PASS

CircleCI at this head: pipeline 90851, integration-management job 2240442 and integration-management-replica job 2240450 run all four test_plugin_session_claim nodes green on both; the shards themselves are red on test_team_scoped_models::test_v2_model_info_reports_a_team_model_to_team_and_non_team_keys and the three test_vector_store_file_list_managed_ids::test_provider_errors_reach_the_caller_and_other_models_keep_mapping cases, the same four that fail on the last three main integration 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_logging is in the CircleCI flaky-test list and does not touch this diff

Not 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

  • Claim wire format changes from Fernet to v2:gcm:; a plugin decrypting with cryptography.fernet must switch to AES-GCM under the same derived key
    • No compatibility window by design (30 s TTL), per the LIT-8428 roadmap
    • docs/proxy/plugins.md in litellm-docs still shows the Fernet snippet and needs a companion docs PR

Low

  • POST /config/field/update for plugins only registers the plugin in the worker that served the request until the other workers restart. Pre-existing, outside this diff, observed while building the proof

Link 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

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>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical risk] Replaces session encryption for plugin authentication.

The PR appears safe to merge based on the reviewed changes

Summary

The PR replaces Fernet plugin session claims with per-plugin AES-256-GCM claims and adds unit and integration coverage for claim issuance, verification, and tampering

  • Stored-value encryption delegates to the new keyed AES-GCM helpers without changing its wire format
  • Both previous Greptile threads are resolved; no new actionable issue was found

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

Comment thread litellm/proxy/plugin_routes.py Resolved
Comment thread litellm/proxy/plugin_routes.py Resolved

@cursor cursor Bot left a comment •

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.

Stale Bugbot comment from a previous run.

@codspeed

codspeed Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_fips_b4_plugin_claim_aes_gcm (573abe6) with main (2e1a98f)

Open in CodSpeed

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 24, 2026
…n_claim_aes_gcm

# Conflicts:
#	litellm/proxy/common_utils/encrypt_decrypt_utils.py
@yucheng-berri

Copy link
Copy Markdown
Contributor

@greptileai review latest head

@yucheng-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

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.

✅ 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.

This branch had an error being deployed

1 failed deployment
e2e-changed — 573abe61 Deployed Oct 5, 2026 by yucheng-berri via oauth #3064
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.

2 participants