Skip to content

feat(proxy): FIPS-compliant encryption and password hashing - #28729

Closed
yassin-berriai wants to merge 5 commits into
mainfrom
litellm_fix/fips-compliant-encryption
Closed

yassin-berriai wants to merge 5 commits into
mainfrom
litellm_fix/fips-compliant-encryption

Conversation

@yassin-berriai

Copy link
Copy Markdown
Contributor

Summary

Resolves LIT-3317 | Closes #16789

LiteLLM currently uses pynacl (libsodium / XSalsa20-Poly1305) for credential encryption and scrypt for password hashing. Neither algorithm is FIPS 140-2/3 approved, which blocks deployment in FIPS-restricted environments.

This PR adds full FIPS compliance via a single environment variable: LITELLM_FIPS_MODE=true.

What changes

Component Default (unchanged) FIPS mode (LITELLM_FIPS_MODE=true)
Credential encryption pynacl / XSalsa20-Poly1305 AES-256-GCM via cryptography (OpenSSL)
Password hashing scrypt PBKDF2-HMAC-SHA256 (600 000 iterations, NIST SP 800-132)
Token hashing SHA-256 (unchanged) SHA-256 (unchanged — already FIPS-compliant)

Backward compatibility

  • Encryption: Values written with pynacl are still readable in FIPS mode (no prefix → nacl path). New values written in FIPS mode carry an aes256gcm: prefix and are readable in non-FIPS mode too.
  • Passwords: verify_password supports pbkdf2:, scrypt:, and legacy SHA-256 formats. On next login, _rehash_password_if_needed automatically upgrades to the current algorithm.
  • migrate_passwords_to_scrypt_async skips already-hashed pbkdf2: passwords.

No new dependencies

cryptography (already pinned at 46.0.7) is used for AES-256-GCM. hashlib.pbkdf2_hmac is stdlib. pynacl is still present for reading legacy encrypted values.


Behavioral test matrix

Scenario Input FIPS mode Expected
Encrypt new value any string OFF nacl ciphertext (no prefix)
Encrypt new value any string ON aes256gcm:<b64>
Decrypt aes256gcm value aes256gcm:… OFF ✅ plaintext
Decrypt nacl value raw b64 ON ✅ plaintext (nacl fallback)
Decrypt nacl value raw b64 OFF ✅ plaintext
Wrong signing key any any ❌ raises InvalidTag
Ciphertext too short <12 bytes any ❌ raises ValueError
Hash password any OFF scrypt:…
Hash password any ON pbkdf2:…
Verify correct password scrypt:… any ✅ True
Verify correct password pbkdf2:… any ✅ True
Verify correct password SHA-256 hex any ✅ True (legacy)
Verify wrong password any format any ❌ False
Verify plaintext not-hashed any ❌ False (no plaintext fallback)
Verify scrypt in FIPS mode scrypt:… ON ✅ True (cross-format)
Verify pbkdf2 in non-FIPS pbkdf2:… OFF ✅ True (cross-format)
Rehash on login scrypt:… ON upgrades to pbkdf2:…
Rehash on login pbkdf2:… ON no-op
Rehash on login SHA-256 hex OFF upgrades to scrypt:…
Rehash on login scrypt:… OFF no-op
Migrate plaintext passwords plaintext any migrated to current algorithm
Migrate scrypt/pbkdf2 passwords already hashed any skipped
LITELLM_FIPS_MODE detection true/1/yes — FIPS mode enabled
LITELLM_FIPS_MODE detection false/0/unset — FIPS mode disabled

48 unit tests, all passing.

Test plan

  • uv run pytest tests/test_litellm/proxy/auth/test_fips_compliance.py -v → 48 passed
  • uv run pytest tests/test_litellm/proxy/auth/test_password_hashing.py tests/test_litellm/proxy/auth/test_login_utils.py -v → 27 passed (existing tests unchanged)
  • uv run ruff check → no issues
  • uv run black → no issues
  • Zero diff in litellm/proxy/_experimental/out/

https://claude.ai/code/session_01PfHdZL7eNSDDfJsv4Bcyx1


Generated by Claude Code

yuneng-berri and others added 4 commits May 23, 2026 16:41
…8683)

* fix(team): refresh team cache on team_model_add/delete (LIT-3244)

team_model_add and team_model_delete wrote to the DB but did not
invalidate the in-memory LiteLLM_TeamTableCachedObj used by
common_checks. After the v1.83.14 common_checks centralization made
team.models authoritative on /v1/files and /v1/vector_stores/*,
adding a Team-BYOK model silently failed to grant the new public
model name to team members until the cache TTL expired (and a
removed model kept working until then on the symmetric path).

Extract the cache-refresh snippet from update_team into a small
helper and apply it consistently at all three team-write sites.

* test: also assert updated models in team-cache-refresh pin

Strengthens the LIT-3244 regression test to also assert
`call_kwargs["team_table"].models` matches the updated row,
not just `team_id`. Both `existing_team` and `updated_team`
share `team_id` in the test setup, so the previous assertion
would have passed even if the implementation accidentally cached
the pre-mutation row.

Greptile review feedback.

* fix(team): hydrate object_permission on cache-refreshing team updates

The Prisma update calls in update_team, team_model_add, and
team_model_delete returned a team row with object_permission_id set
but object_permission=None (the relation was not requested via
include=). _refresh_cached_team then wrote that to the in-memory
LiteLLM_TeamTableCachedObj, and the cache-hit path in get_team_object
returns the cached object without re-hydrating. Downstream consumers
(validate_key_search_tools_against_team, the MCP/agent authz paths)
treat a missing object_permission as no team-level restriction, so
a team-write op silently dropped object-permission enforcement until
the cache TTL expired or a DB-fetch path re-hydrated it.

Add include={"object_permission": True} to all three updates so the
refresh writes a complete cached team. Extend the LIT-3244 regression
test to pin both the cached object_permission and the include shape
on the Prisma call.

Surfaced in PR review of LIT-3244.
… Anthropic (#28723)

`getProviderModels()` matched a model into a provider's dropdown when the
model's `litellm_provider` string *contained* the provider key as a
substring. The intent was to admit suffix variants (e.g. `anthropic_text`,
`bedrock_converse`), but the substring check is too loose: it also pulls in
unrelated providers whose name happens to contain the key, most visibly
`vertex_ai-anthropic_models` matching `anthropic` and `vertex_ai-openai_models`
matching `openai`.

Replace `.includes()` with separator-anchored prefix matching
(`startsWith(provider + "_")` / `startsWith(provider + "-")`). All legitimate
variants in `model_prices_and_context_window.json` still match
(`anthropic_text`, `azure_text`, `azure_ai`, `bedrock_converse`,
`bedrock_mantle`, `cohere_chat`, `fireworks_ai-embedding-models`,
`vertex_ai-*`, `vertex_ai_beta`), and the cross-provider leak is closed.

Tests: update one assertion that pinned the buggy substring behavior
(`custom_openai_endpoint` matching `openai` — not a real provider value);
add 6 new tests covering the leak regressions and the variant-preservation
contract for vertex_ai/bedrock/fireworks.
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: ryan-crabbe-berri <ryan-crabbe-berri@users.noreply.github.com>
…3317)

Replace pynacl (XSalsa20-Poly1305, not FIPS-approved) with AES-256-GCM
from the `cryptography` library (OpenSSL-backed, FIPS 140-2/3 compliant)
when LITELLM_FIPS_MODE=true is set.

Replace scrypt password hashing with PBKDF2-HMAC-SHA256 (NIST SP 800-132
approved, 600 000 iterations) in FIPS mode. Full backward compatibility is
maintained: legacy nacl-encrypted values and scrypt/SHA256 password hashes
are still readable in all modes, and migration to the new algorithm happens
automatically on next login.

- encrypt_value_helper: emits `aes256gcm:<b64>` when FIPS mode is on
- decrypt_value_helper: routes on prefix; nacl fallback for legacy values
- hash_password: emits `pbkdf2:…` in FIPS mode, `scrypt:…` otherwise
- verify_password: supports pbkdf2, scrypt, and SHA256 (legacy) formats
- _rehash_password_if_needed: upgrades to current algorithm on login
- migrate_passwords_to_scrypt_async: skips pbkdf2-prefixed hashes
- 48 new unit tests covering all modes and cross-format compatibility

https://claude.ai/code/session_01PfHdZL7eNSDDfJsv4Bcyx1
@CLAassistant

CLAassistant commented May 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ ryan-crabbe-berri
✅ yuneng-berri
❌ claude
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed

codspeed Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing litellm_fix/fips-compliant-encryption (aefca0e) with main (06f6cfc)

Open in CodSpeed

@codecov

codecov Bot commented May 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

UserAPIKeyAuth,
)
from litellm.proxy.auth.auth_checks import (
_cache_team_object,
Comment on lines +4604 to +4608
from litellm.proxy.proxy_server import (
prisma_client,
proxy_logging_obj,
user_api_key_cache,
)
Comment on lines +4691 to +4695
from litellm.proxy.proxy_server import (
prisma_client,
proxy_logging_obj,
user_api_key_cache,
)
Comment thread litellm/proxy/utils.py Fixed
…rd_if_needed

Define _is_fips_mode directly in proxy/utils.py (uses only stdlib `os`) instead
of lazily importing it from encrypt_decrypt_utils, which created a cyclic
import chain detected by CodeQL (utils → encrypt_decrypt_utils → proxy_server
→ utils). Import _is_fips_mode from proxy/utils in login_utils to match.

https://claude.ai/code/session_01PfHdZL7eNSDDfJsv4Bcyx1
@Shanay-Mehta

Copy link
Copy Markdown

Hi @yassin-berriai ,
May I know why this PR was closed?
I am looking for a FIPS compliant version of litellm and came across this.

@devin-ai-integration
devin-ai-integration Bot deleted the litellm_fix/fips-compliant-encryption branch September 10, 2026 03:41
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.

7 participants