Repository navigation
🔒 fix(expand): keep values out of template errors - #335
Merged
gaborbernat merged 2 commits intoNov 17, 2026
Merged
Conversation
A {VAR} template with a field nested in a format spec, such as
{A:-{B}}, made str.format raise a ValueError whose message quotes the
expanded spec, which is the value of B. Nothing caught it, so the
traceback printed a variable value in a run without
--pytest-env-verbose.
The expansion now reports a usage error that names the entry and
carries neither the template nor a value.
Reported by Anthropic's OSS Scanner: ANT-2026-5FWSIIT0.
…hides-value # Conflicts: # README.md # tests/test_env.py
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.
_apply_entriesexpanded{VAR}templates with an unguardedentry.value.format(**os.environ)(old line). A template that nests one field inside another's format spec, such as{A:-{B}}, made that call raise aValueErrorwhose message quotes the value ofB, and the traceback printed it in a run without--pytest-env-verbose. Anyone able to read the run's output, such as a CI log, could read that value. 🔒 After this PR the run stops with a usage error that names the entry and carries no value. This addresses draft advisory ANT-2026-5FWSIIT0.The format error quoted an environment value
A format spec may hold nested replacement fields, and Python substitutes them before it interprets the spec. The expanded text is rarely a valid spec for a
str, and CPython's error quotes it in full:Invalid format specifier '<expanded spec>' for object of type 'str'. The hook runs inside atrythat catches onlyConftestImportFailure, and pytest'smainhandlesUsageErrorbut notValueError, so the interpreter printed the traceback with the message. INI entries expand unless they carryR:, and TOML entries expand withtransform = true; both went through the same call.The expansion now lives in
_expand_value, which catchesValueErrorand raisespytest.UsageErrorwithfrom None, so the original message is not chained into the output. The new message is built from the entry's name alone. It leaves out the template as well, because a template can hold a literal secret.Behavior changes
A template that
str.formatrejects withValueErrorstops pytest before collection with exit code 4 and one line:The run used to end with exit code 1 and a traceback. A template that references an unset variable still ends in a
KeyErrortraceback; that message names the variable and holds no value, and this PR leaves it alone. Templates that expanded before expand to the same text.Reported by Anthropic's OSS Scanner: ANT-2026-5FWSIIT0.