Skip to content

cache: keep cache keys within the cache directory - #14884

Merged
RonnyPfannschmidt merged 1 commit into
pytest-dev:mainfrom
RonnyPfannschmidt:cache-key-containment
Aug 18, 2026
Merged

cache: keep cache keys within the cache directory#14884
RonnyPfannschmidt merged 1 commit into
pytest-dev:mainfrom
RonnyPfannschmidt:cache-key-containment

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Aug 14, 2026

Copy link
Copy Markdown
Member

Cache joined keys onto the cache directory without normalizing them, so a key
that was absolute or contained .. resolved outside it — set() then also
created the missing parent directories at that location.

  • _getvaluepath() normalizes the joined path and checks containment, so
    get()/set() reject escaping keys while a .. that cancels out within the
    values directory still works.
  • mkdir() used the same check; it previously only rejected path separators,
    which .. passes as a single part.
  • --cache-show globs are filtered the same way — rglob() follows ..
    segments in the pattern.

Note Path.is_absolute() is not sufficient on Windows: a rooted-but-driveless
key like /x reports False yet still replaces the base in joinpath().
Normalizing the joined path covers that without enumerating path flavours.

RonnyPfannschmidt added a commit to RonnyPfannschmidt/pytest that referenced this pull request Aug 14, 2026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 14, 2026
Keys were joined onto the cache directory without normalization, so an
absolute or ".."-containing key resolved somewhere else entirely, and
``set()`` created the missing parents there. Normalize the joined path
and check containment instead.

``mkdir()`` only rejected path separators, which ".." passes as a single
part, and ``--cache-show`` globbed with the same lack of normalization.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@RonnyPfannschmidt
RonnyPfannschmidt marked this pull request as ready for review August 14, 2026 20:13

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@RonnyPfannschmidt
RonnyPfannschmidt merged commit 2a9e201 into pytest-dev:main Aug 18, 2026
36 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants