Skip to content

write_folder refuses an element id that would write outside its folder - #82

Merged
tmoosting merged 4 commits into
mainfrom
unsafe-ids
Nov 28, 2026
Merged

tmoosting merged 4 commits into
mainfrom
unsafe-ids

Conversation

@tmoosting

@tmoosting tmoosting commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Fixed: write_folder no longer writes outside its folder. An element with no sluggable name is written as <id>.json, so an id holding a path wrote a file outside the target: an id of ../../../x with an empty name wrote x.json in the target's parent, and on Windows an id with another drive's prefix (D:evil) named a path on that drive, while C:evil under a folder on drive C was written as evil.json. Every import door and export_world write through write_folder.

Now an id that is empty, holds /, \, : or a control character, or is . or .. is refused with a ValueError naming the type, the id and why, before anything is written. A second guard checks that every file name made from an id stays inside its type folder, in write_folder, the OKF export and the LegendKeeper board records. The refused and written cases are shared with the npm SDK byte for byte.

🤖 Generated with Claude Code

tmoosting and others added 4 commits November 28, 2026 13:28
…ts folder

An element whose name gives no slug is written as <id>.json, and the collision
rule can fall back to the full id at any time, so an id holding a path, such as
../../x from an export or a server, wrote a file outside the folder write_folder
was asked to write. write_folder now refuses, before anything is written, an
element id that holds / or a backslash, or a control character (U+0000 to
U+001F), or is . or .., whatever the name: a ValueError naming the type, the id
as JSON text and why. The target is not made, and an empty one is left as it
was, as on the writer's other refusals. Every writer that names files by id
goes through write_folder (export_world and the five import doors); the world's
id names no path.

The cases are tests/fixtures/unsafe-ids.cases.json, the same bytes as the npm
SDK's copy, both suites holding its sha256.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inside its folder

Two more shapes refused by write_folder's id rule: an empty id, which would be
written as the hidden file .json, and an id holding a colon. On Windows
C:evil.json joined to a relative folder is a path on drive C, D:/x.json one at
the root of drive D, and a:b.json in a folder names a stream of the file a.

Behind the character rule, a second guard: before anything is written, every
file a writer names from an id must have a path that lies inside its folder,
resolved. write_folder checks each element file against its type folder (and
that the name joins as one plain name); write_bundle, the OKF export, checks
each path against the bundle; the LegendKeeper import checks its board record
paths before it writes the folder. A ValueError names the path.

The shared cases file gains the empty id, a:b, C:evil and D:/x; its sha256
moves in both suites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ites, too

write_folder writes its files into a temp folder beside the target and renames
it into place. The second guard checked each element file's path against the
target's type folder only; it now checks the temp folder's as well, before
anything is written, since that is where the bytes land first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its folder

The release entry; its colon example is a drive the folder is not on, where the join leaves the folder (on the folder's own drive it names another file inside it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmoosting
tmoosting merged commit 52f4802 into main Nov 28, 2026
11 checks passed

This branch was successfully deployed

1 active deployment
pypi — 52f4802b Deployed Nov 28, 2026 by tmoosting via publish #260
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant