fix: detect masked short secrets in contains_masked_key#398
Open
developer603 wants to merge 1 commit into
Open
fix: detect masked short secrets in contains_masked_key#398developer603 wants to merge 1 commit into
developer603 wants to merge 1 commit into
Conversation
contains_masked_key() guards against persisting a still-masked secret by
checking for the MASK_MARKER ("***") substring. But mask_key() only emits
3+ consecutive asterisks for keys longer than VISIBLE_CHARS + 2. For short
secrets it emits fewer: e.g. mask_key("EMPTY") == "*MPTY" (a single
asterisk). Such masked values slip past the guard, so a dashboard
"save without editing" round-trips the masked display string back and
overwrites the real stored value with e.g. "*MPTY".
This bites self-hosted/OpenAI-compatible providers that use a short
no-validate sentinel api_key such as "EMPTY".
Match the full shape mask_key() produces — a run of MASK_CHAR followed by
at most VISIBLE_CHARS revealed characters — in addition to the legacy
marker. Verified: masked short secrets ("*MPTY", "*", "*ykey") are now
detected while real unmasked values ("EMPTY", "sk-live-abcd", ...) are
not, so there are no false positives.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
stefandsl
added a commit
to stefandsl/dograh
that referenced
this pull request
Jun 2, 2026
…d_key Upstream dograh-hq#398. Pure-logic fix; 38 masking/config unit tests pass.
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.
fix: detect masked short secrets in
contains_masked_keyProblem
contains_masked_key()guards against persisting a still-masked secret by testingfor the
MASK_MARKER("***") substring:But
mask_key()only produces 3+ consecutive asterisks for keys longer thanVISIBLE_CHARS + 2. For short secrets it produces fewer:These masked values slip past the guard, so a dashboard "save without editing"
round-trips the masked display string back to the server and overwrites the real
stored value with e.g.
"*MPTY"— silently corrupting the secret.This is most visible for self-hosted / OpenAI-compatible providers that use a short
no-validate sentinel api_key such as
"EMPTY"(common for local vLLM, Ollama, etc.).Fix
Match the full shape
mask_key()actually produces — a run ofMASK_CHARfollowedby at most
VISIBLE_CHARSrevealed trailing characters — in addition to the legacymarker:
Testing
Verified against
mask_key()output and against real unmasked values:mask_key()EMPTY*MPTYX*mykey*ykeysk-1234567890abcdef***************cdefabcd****Real unmasked values are not flagged — no false positives:
contains_masked_key("EMPTY") / ("sk-live-abcd") / ("mykey") / ("X")all returnFalse(no leading-asterisk run, so the anchored regex doesn't match).
python -m py_compileclean.