Repository navigation
🐛 fix(ini): reject env lines with unknown flags - #334
Merged
gaborbernat merged 2 commits intoNov 17, 2026
Merged
Conversation
The INI parser kept only the D, R and U pieces before the name and dropped the rest, so a typo changed what a line did without any sign of it: `DR:API_TOKEN=x` overwrote an existing value and `DB_HOST: test-db` created an empty variable named `test-db`. A line without a name crashed later with a bare OSError. The usage error gives the entry's position and the flag, never the line, because the value may be a secret. Reported by Anthropic's OSS Scanner: ANT-2026-4L02Y0M6. Fixes pytest-dev#323
…tion # Conflicts: # README.md
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.
The INI branch of
_load_valuessplit the text before the first=on:, took the last piece as the variable name and looked among the others only forD,RandU(old lines). Any other piece was dropped, so a mistyped line was applied as a different instruction and pytest exited 0:DR:API_TOKEN=localoverwrote an existingAPI_TOKEN, andDB_HOST: test-dbcreated an empty variable namedtest-db. 🐛 After this PR such a line stops pytest with a usage error. Fixes #323.Unknown flags were dropped
The flags were consulted through three membership tests, so
DRmatched none of them and the entry ran as if it had no flag: expanded, and not skipped when the variable existed. A line without=went through the same split, which madeDB_HOSTa flag andtest-dbthe name. The parser now rejects any flag outsideD,RandU.A line without a name crashed later
=valueandD:produced an empty name, and the assignment toos.environthen failed with a bareOSError: [Errno 22] Invalid argumentthat named no line. The parser now rejects an empty name before applying anything.Behavior changes
A line with a flag other than
D,RorU, in any letter case, or with no variable name, stops pytest with exit code 4 and one of:The message gives the entry's position among the
enventries and the flag. It does not print the line, because the value may be a secret and pytest-env prints values only with--pytest-env-verbose. A configuration that relied on a dropped piece, such asAPP:MODE=xsettingMODE, now fails and has to be rewritten asMODE=x. Lines in the documented(FLAG:)NAME=VALUEform and the native[pytest_env]tables behave as before.Reported by Anthropic's OSS Scanner: ANT-2026-4L02Y0M6.