fix: redact() scrubs custom-endpoint key values (closes #14)#30
Merged
Merged
Conversation
redact() previously masked only built-in providers' env-var values, so a custom OpenAI-compatible endpoint's api_key_env value (unrecognized shape) could leak into ModelAnswer.error via any of call_model's three error paths (_status_error echo, TransportError, unexpected exception). Fix at the chokepoint: redact() now also masks the values of every custom-endpoint env var declared in config (loaded lazily; never raises, falls back to pattern-only scrubbing on error). No existing pattern detection weakened -- name-based coverage added only. Closes the whole leak class since all three error paths funnel through redact(). Adds an e2e test (custom endpoint returns 401 echoing an unprefixed fake key -> asserted absent from ModelAnswer.error) and a redact unit test.
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.
#14 — BYO-keys leak: redact() missed custom-endpoint keys
redact()masked only the built-in providers' env-var values. A custom OpenAI-compatible endpoint (endpoints[*].env_var) names a key var with no recognized shape (sk-/xai-/etc.), so its value could leak unredacted intoModelAnswer.errorvia all three ofcall_model's error paths (_status_errorecho,TransportError, unexpected exception).Fix
One chokepoint:
redact()now also masks values of every custom-endpoint env var declared in config (lazy load, never raises — falls back to pattern-only scrubbing on any error). No existing pattern detection weakened; name-based coverage added only. Because all three error paths funnel throughredact(), this closes the whole class.Tests (+2, 66→68 green)
test_call_model_custom_endpoint_key_not_leaked_in_error— e2e: custom endpoint returns 401 echoing an unprefixed synthetic fake key; asserts it's absent fromModelAnswer.errorand[REDACTED]present. (This is the redact slice of test gaps: transport/cli/logging untested + end-to-end redact test #18.)test_redact_scrubs_custom_endpoint_env_var_value— unit proof.Out of scope (tracked separately)