Fix settings endpoint secret exposure#27
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
Co-authored-by: Ritesh Verma <riteshverma@users.noreply.github.com>
| if _settings_cache is not None: | ||
| SETTINGS_FILE.write_text(json.dumps(_settings_cache, indent=2)) | ||
| SETTINGS_FILE.write_text( | ||
| json.dumps(_strip_env_secrets_for_persistence(_settings_cache), indent=2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and impact
reload_settings()overlays Supabase credentials from environment variables into the runtime settings object.GET /settingsreturned that object verbatim, so a hosted deployment could exposeSUPABASE_SERVICE_ROLE_KEYto anyone who can reach the settings endpoint. The same runtime object was also written bysave_settings(), so any settings-writing endpoint could persist env-sourced credentials intoconfig/settings.json.Root cause
Runtime settings and persisted settings shared the same mutable dictionary, with no redaction before API responses and no stripping of env-sourced secret values before JSON writes.
Fix
redact_settings_for_client()and used it inGET /settings.save_settings()to preserve runtime access to env credentials while replacing env-sourced Supabase secret values with the existing persisted value (or empty string) before writingsettings.json.Validation
python3 -m unittest tests.test_settings_router tests.test_settings_loader.SettingsSecretHandlingTests✅python3 -m py_compile config/settings_loader.py routers/settings.py tests/test_settings_loader.py tests/test_settings_router.py✅Note:
python3 -m unittest tests.test_settings_loader tests.test_settings_routeralso surfaced an unrelated existing failure:ProfileSettingsTests.test_profile_overrides_defaultsexpectsgemma4:e4b, whileconfig/profiles/local-laptop-gemma.jsoncurrently containsgemma3:4b. The router module also required installing minimal runtime dependencies (fastapi,httpx) in this stripped environment.