Repository navigation
fix(http_spec): expand secrets in headers and URL and guard None values - #401
Open
brixtonpham wants to merge 2 commits into
Open
brixtonpham wants to merge 2 commits into
brixtonpham wants to merge 2 commits into
Conversation
msoedov
reviewed
Nov 26, 2026
| return Modality.TEXT | ||
|
|
||
|
|
||
| def _build_secret_replacer( |
Owner
There was a problem hiding this comment.
Thanks for adding this _build_secret_replacer!
However, I would leave get_secrets and set_secrets as they are and use an empty string instead of None.
Contributor
Author
There was a problem hiding this comment.
Good call — reverted get_secrets and set_secrets to their original signatures/behavior and updated expand_secrets to fall back to "" instead of None.
…ty string fallback
This branch has not been deployed
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.
Problem
Two bugs affect secret expansion in HTTP specs:
parse_http_spec()(agentic_security/http_spec.py) only expands$SECRETplaceholders inbody, ignoringheadersandurl. Because 18 of 20 built-inLLM_SPECSpresets and the default Web UI spec useAuthorization: Bearer $OPENAI_API_KEY(or API keys in URL query params), the literal$OPENAI_API_KEYstring is sent over the wire and fails with HTTP 401.expand_secrets()/set_secrets()(agentic_security/core/app.py) crash on repeated calls when an env var is unset. The firstset_secrets({"KEY": "$UNSET_VAR"})storesNonein_secrets; the nextset_secrets(...)call iterates over_secretsand callsval.startswith("$")onNone, raisingAttributeError: 'NoneType' object has no attribute 'startswith'. Re-expanding all of_secretsalso re-runs env lookup on previously stored secrets whose literal value begins with$.Solution
agentic_security/http_spec.py:_build_secret_replacer()using single-pass regex substitution (longest key first,(?![A-Za-z0-9_])token boundary, callable replacement so$or\1inside secret values cannot double-expand or trigger backreferences).None, empty, non-string, and bare"$"entries cleanly.url, parsedheadersvalues (leaving header names untouched so:in secret values cannot break header parsing), andbody.urlparse, while formattingInvalidHTTPSpecErrorwith the unexpandedraw_urlso expanded secrets are not leaked in errors.agentic_security/core/app.py:expand_secrets()withisinstance(val, str) and val.startswith("$")and updateset_secrets()to expand a copy of only the incoming dict before_secrets.update(expanded).tests/unit/test_spec.py,agentic_security/core/test_app.py):$/\1safety,None/non-string skipping, non-leakingInvalidHTTPSpecError, and repeatedset_secrets()calls.Testing
OPENAI_API_KEY="sk-fake" python3 -m pytest tests/unit/test_spec.py agentic_security/core/test_app.py -v: 24 passedOPENAI_API_KEY="sk-fake" python3 -m pytest . -q: 649 passed, 4 skippedpre-commit run --all-files: all hooks passed