bugger.
All challenges/Pythonhardthe-archive-that-walks-outside-v1
THE INVESTIGATION

The archive that walks outside

An archive member looks contained after lexical normalization but follows an existing link outside the extraction directory.

FilesystemSecurityInvariants

What’s going wrong

An archive extraction planner checks member names lexically. Pre-existing symbolic links can redirect a harmless-looking member outside the destination.

Input is {"links": {absolute-path:absolute-target,...}, "members":[relative-path,...]}. The virtual extraction root is /work and is never itself a link. Link keys and targets are normalized absolute POSIX paths; there are at most eight links. Resolve paths component by component: . is ignored, .. removes the current resolved component, and encountering a link substitutes its absolute target before processing remaining components. More than 32 followed links is rejected. Reject all absolute member names, and any resolved destination outside /work (including prefix lookalikes such as /workspace). Return an array of resolved absolute destinations or null. The empty member names /work. Members are independent plans; they never create or change links. No host filesystem operations are permitted.

Expected behavior

Containment is checked after virtual link resolution; valid internal links work, traversal and cycles are rejected, and sibling prefixes do not count as containment.

Reproduction

01 Existing link escapes
{"links":{"/work/out":"/outside"},"members":["out/report.txt"]}
[null]
02 Ordinary members
{"links":{},"members":["a.txt","dir/b.txt"]}
["/work/a.txt","/work/dir/b.txt"]
03 Internal link resolves
{"links":{"/work/current":"/work/releases"},"members":["current/app.py"]}
["/work/releases/app.py"]

Before you begin

  • Path components
  • Symbolic links
  • Containment
  • State machines

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.