Skip to content

fix(proxy): stop double-decrypting email/slack alerting env vars in get_config - #31117

Merged
mubashir1osmani merged 3 commits into
litellm_internal_stagingfrom
litellm_fix_email_settings_double_decrypt
Jun 25, 2026
Merged

mubashir1osmani merged 3 commits into
litellm_internal_stagingfrom
litellm_fix_email_settings_double_decrypt

Conversation

@mubashir1osmani

@mubashir1osmani mubashir1osmani commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #19221

Linear ticket

N/A

Pre-Submission checklist

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

  • I have added meaningful tests
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (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: true and a fixed LITELLM_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:

curl -s -X POST http://localhost:4000/config/update \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"general_settings":{"alerting":["email"]},"environment_variables":{"SMTP_HOST":"smtp.resend.com","SMTP_PORT":"587","SMTP_USERNAME":"resend","SMTP_PASSWORD":"super-secret-app-password","SMTP_SENDER_EMAIL":"alerts@example.com","TEST_EMAIL_ADDRESS":"admin@example.com"}}'

{"message":"Config updated successfully"}

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):

{
  "name": "email",
  "variables": {
    "SMTP_HOST": null,
    "SMTP_PORT": null,
    "SMTP_USERNAME": null,
    "SMTP_PASSWORD": null,
    "SMTP_SENDER_EMAIL": null,
    "TEST_EMAIL_ADDRESS": null,
    "EMAIL_LOGO_URL": null,
    "EMAIL_SUPPORT_CONTACT": null
  }
}

and the proxy log shows the misleading decryption error users reported, even though the salt key was never touched:

encrypt_decrypt_utils.py:74 - Error decrypting value for key: SMTP_HOST, Did your master_key/salt key change recently?
encrypt_decrypt_utils.py:74 - Error decrypting value for key: SMTP_PORT, Did your master_key/salt key change recently?
encrypt_decrypt_utils.py:74 - Error decrypting value for key: SMTP_PASSWORD, Did your master_key/salt key change recently?
...

After this fix (same saved DB row, fixed code):

{
  "name": "email",
  "variables": {
    "SMTP_HOST": "smtp.resend.com",
    "SMTP_PORT": "587",
    "SMTP_USERNAME": "resend",
    "SMTP_PASSWORD": "supe*****************word",
    "SMTP_SENDER_EMAIL": "alerts@example.com",
    "TEST_EMAIL_ADDRESS": "admin@example.com",
    "EMAIL_LOGO_URL": null,
    "EMAIL_SUPPORT_CONTACT": null
  }
}
Screenshot 2026-06-23 at 12 34 40 PM

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 the environment_variables row of LiteLLM_Config. On a refresh the UI reads them back via GET /get/config/callbacks (get_config()), and every SMTP_* field came back blank.

The root cause is a double decryption. By the time get_config() reads environment_variables, the values are already plaintext: the DB overlay path decrypts the whole section in ProxyConfig._update_config_fields before returning it, and YAML-sourced values are plaintext to begin with. The slack and email blocks in get_config() then called decrypt_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 returns None, 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 same environment_variables dict 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 via mask_sensitive_keys is unchanged, so SMTP_PASSWORD and SLACK_WEBHOOK_URL are still never returned verbatim.

The slack block keeps its existing fallback to the OS SLACK_WEBHOOK_URL env var, but guards it with an explicit is not None check rather than truthiness. A webhook the admin cleared is stored as "", and a falsy or fallback 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.py drive GET /get/config/callbacks: test_get_config_returns_email_settings and test_get_config_returns_slack_webhook pass already-decrypted env vars and assert the real values come back rather than None (both fail on the pre-fix code, the email one with the same CryptoError: Decryption failed the proxy was swallowing). test_get_config_cleared_slack_webhook_not_overridden_by_os_env locks 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 accepts email but not the registered logger names smtp_email / resend_email / sendgrid_email) and is better handled in its own PR

…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-apps

greptile-apps Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a double-decryption bug in GET /get/config/callbacks where the email and Slack alerting blocks called decrypt_value_helper() on values already returned as plaintext by proxy_config.get_config(), causing every SMTP and Slack field to silently become None on Admin UI refresh.

  • proxy_server.py: Removes the decrypt_value_helper() calls from both the slack and email blocks, reading environment_variables values directly (already decrypted upstream). The Slack webhook fallback to os.getenv is tightened to an explicit is not None check so a webhook cleared to "" is not overridden by a stale OS environment variable.
  • test_proxy_server.py: Adds three new mock-only regression tests covering email settings round-trip, Slack webhook masking, and the cleared-webhook/OS-env fallback behavior; no existing tests are modified.

Confidence Score: 5/5

Safe 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 get_config() was redundant because values are already plaintext when retrieved from proxy_config.get_config(). The is not None guard for the Slack webhook fallback is the right semantic for distinguishing an absent key from a cleared one. Three targeted regression tests are added, no existing tests are weakened, and the change does not touch any authentication or critical request paths.

No files require special attention.

Important Files Changed

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

Comment thread litellm/proxy/proxy_server.py Resolved
…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

codecov Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mubashir1osmani

Copy link
Copy Markdown
Contributor Author

idk what the linting error is - something changed with based pyright

@mubashir1osmani
mubashir1osmani enabled auto-merge (squash) June 24, 2026 01:31
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri 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.

LGTM; thanks!

@mubashir1osmani
mubashir1osmani merged commit 0e1d0f4 into litellm_internal_staging Jun 25, 2026
76 checks passed
@mubashir1osmani
mubashir1osmani deleted the litellm_fix_email_settings_double_decrypt branch June 25, 2026 02:19
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.

[Bug]: Email settings won't save from UI

2 participants