Skip to content

fix: mask sensitive API keys in /api/config response - #633

Open
mango766 wants to merge 1 commit into
666ghj:mainfrom
mango766:fix/mask-api-keys-in-config
Open

fix: mask sensitive API keys in /api/config response#633
mango766 wants to merge 1 commit into
666ghj:mainfrom
mango766:fix/mask-api-keys-in-config

Conversation

@mango766

Copy link
Copy Markdown

Closes #632, related to #620

The /api/config GET endpoint currently returns API keys in plaintext. This masks sensitive config values (anything containing API_KEY, SECRET, or PASSWORD) in the response, showing only the last 4 characters.

This way the frontend can still indicate whether a key is configured, without exposing the actual value to anyone with network access.

Changes:

  • Added a helper to identify and mask sensitive config keys
  • GET /api/config now returns masked values for sensitive fields
  • POST /api/config response is also masked (the write itself still accepts full values)

The GET /api/config endpoint was returning all configuration values in
plaintext, including API keys and passwords.  This meant anyone with
network access could read every secret stored in the config.

Add helper functions that identify sensitive keys (those containing
API_KEY, SECRET, or PASSWORD) and replace their values with a masked
form that only shows the last 4 characters (e.g. "***abcd").  The POST
endpoint response is also masked so secrets are never leaked in any
config API response.

Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 13, 2026
@666ghj

666ghj commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Automated Agent response on behalf of the maintainer.

Thank you for raising and addressing the plaintext configuration response. We are aware that the current convenience-oriented config endpoint exposes sensitive values.

BettaFish is designed primarily for local, self-hosted use, where straightforward configuration and ease of modification are deliberate priorities. It is not intended to be exposed directly to an untrusted public network without additional hardening. Operators choosing a public deployment are expected to add authentication and network controls, or replace/harden this endpoint for their environment; the code is intentionally accessible enough for that customization, including AI-assisted changes.

We will keep this PR open as a useful hardening proposal, but we cannot merge the current implementation. The frontend loads masked placeholders into its form and later submits every field, while the backend writes those placeholders as new values. Saving any configuration can therefore overwrite real API keys and database passwords with strings such as ***abcd.

A mergeable revision would need to treat masks as “keep the existing value” sentinels (or omit unchanged sensitive fields), add regression coverage for the full GET → edit → POST flow, and document the local-only deployment boundary. We are keeping the PR open for that direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API keys exposed in plaintext via /api/config endpoint

2 participants