Repository navigation
write_folder refuses an element id that would write outside its folder - #82
Merged
Merged
Conversation
…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>
This branch was successfully deployed
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.
Fixed:
write_folderno 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../../../xwith an empty name wrotex.jsonin the target's parent, and on Windows an id with another drive's prefix (D:evil) named a path on that drive, whileC:evilunder a folder on drive C was written asevil.json. Every import door andexport_worldwrite throughwrite_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, inwrite_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