Repository navigation
fix(proxy): stop double-decrypting email/slack alerting env vars in get_config - #31117
Conversation
…et_config proxy_config.get_config() already returns environment_variables decrypted (the DB overlay decrypts them in _update_config_fields, and YAML values are plaintext), so the /get/config/callbacks slack and email blocks were running decrypt_value_helper() a second time on plaintext. That second decrypt always failed and the helper swallowed the error and returned None, so every SMTP_* field came back blank when the Admin UI reloaded the email settings, and the proxy logged a misleading "Did your master_key/salt key change recently?" error even when nothing changed. Consume the already-decrypted values directly, matching process_callback's handling of the same dict for langfuse/datadog/etc. Sensitive-value masking is preserved. Fixes #19221
Greptile SummaryThis PR fixes a double-decryption bug in
Confidence Score: 5/5Safe to merge — the change removes incorrect decryption calls, is well-tested with mock-only regression tests, and is tightly scoped to the Admin UI config read path. The fix is minimal and correct: decryption in No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/proxy_server.py | Removes erroneous second decryption pass from the slack and email blocks in get_config(); values from environment_variables are already plaintext at this point. Slack fallback now uses an explicit is not None guard to correctly handle cleared (empty-string) webhooks. |
| tests/test_litellm/proxy/test_proxy_server.py | Adds three new mock-only tests: email settings round-trip, slack webhook masking, and cleared-webhook OS-env fallback guard. No existing tests modified, no real network calls. |
Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile
…to OS env Use an explicit is-not-None guard rather than truthiness when deciding whether to fall back to os.getenv for SLACK_WEBHOOK_URL. With `or`, a webhook the admin cleared (stored as "") is falsy and would surface a stale SLACK_WEBHOOK_URL from the OS environment; only a truly absent key should trigger the OS lookup. No decryption is reintroduced.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
idk what the linting error is - something changed with based pyright |
…itellm_fix_email_settings_double_decrypt
Relevant issues
Fixes #19221
Linear ticket
N/A
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
make test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Live proxy on a Postgres-backed instance with
store_model_in_db: trueand a fixedLITELLM_SALT_KEY(the key never changes between the two runs below; only the code differs).Step 1, save the email settings exactly as the Admin UI "Save Changes" button does:
Step 2, read them back the way a page refresh does (
GET /get/config/callbacks), filtered to the email block.Before this fix (same saved DB row, pre-fix code):
and the proxy log shows the misleading decryption error users reported, even though the salt key was never touched:
After this fix (same saved DB row, fixed code):
The settings now survive a refresh, the password stays masked, and the two optional fields that were never set stay null.
Type
🐛 Bug Fix
Changes
The Admin UI saves SMTP/email server settings via
POST /config/update, which encrypts them and stores them in theenvironment_variablesrow ofLiteLLM_Config. On a refresh the UI reads them back viaGET /get/config/callbacks(get_config()), and everySMTP_*field came back blank.The root cause is a double decryption. By the time
get_config()readsenvironment_variables, the values are already plaintext: the DB overlay path decrypts the whole section inProxyConfig._update_config_fieldsbefore returning it, and YAML-sourced values are plaintext to begin with. The slack and email blocks inget_config()then calleddecrypt_value_helper()on that plaintext a second time. The second decrypt always fails (plaintext is not valid ciphertext), and the helper swallows the error and returnsNone, so the whole email form rendered empty. It also logged the misleading "Did your master_key/salt key change recently?" error, which is the "encryption error" several people hit in the thread, even when no key had changed.The sibling reader
process_callback()(used for langfuse, datadog, and the other logging callbacks) already consumes the sameenvironment_variablesdict as plaintext with no decrypt step, which is why those integrations displayed fine while only the SMTP values broke. This change makes the slack and email blocks follow that same convention and read the already-decrypted values directly. Sensitive-value masking viamask_sensitive_keysis unchanged, soSMTP_PASSWORDandSLACK_WEBHOOK_URLare still never returned verbatim.The slack block keeps its existing fallback to the OS
SLACK_WEBHOOK_URLenv var, but guards it with an explicitis not Nonecheck rather than truthiness. A webhook the admin cleared is stored as"", and a falsyorfallback would have surfaced a stale OS-env value the user thought they had removed; only a truly absent key should trigger the OS lookup.Tests in
tests/test_litellm/proxy/test_proxy_server.pydriveGET /get/config/callbacks:test_get_config_returns_email_settingsandtest_get_config_returns_slack_webhookpass already-decrypted env vars and assert the real values come back rather thanNone(both fail on the pre-fix code, the email one with the sameCryptoError: Decryption failedthe proxy was swallowing).test_get_config_cleared_slack_webhook_not_overridden_by_os_envlocks the cleared-webhook behavior and fails if the fallback regresses to truthiness.Out of scope: the thread also mentions a
Service=smtp_email not in ...400 from the callback "Test" button. That is a separate naming mismatch in/health/services(it acceptsemailbut not the registered logger namessmtp_email/resend_email/sendgrid_email) and is better handled in its own PR