Repository navigation
fix: sanitise user-editable names in default screenshot filenames - #119
Merged
Merged
Conversation
Follow-up to #118, which fixed this for ios-device screenshot: the simulator default filename interpolated the FBSimulator name verbatim, and simctl accepts any free text as a name — "My iPhone/Work" turned the default output into a directory hierarchy, and ".." segments could walk out of the current directory. The name now passes through OutputFilePath.safeFilenameComponent, same as the physical-device verb. The Android default filename embeds the adb serial, whose accepted router charset already excludes separators; it is sanitised too as defence in depth. Video default filenames (sim-use-video-<ISO8601>) embed no user-controlled text and need no change. Regression tests pin the slash and traversal cases; verified live with a simulator actually named "Slash/Name Probe". Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: onevcat <onevcat@gmail.com>
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.
Summary
Follow-up to #118, which introduced
OutputFilePath.safeFilenameComponentfor the physical-device screenshot. The same hazard existed on the simulator side and predates #118: the default filename interpolates the FBSimulator name verbatim, andsimctlaccepts any free text as a name — so a simulator namedMy iPhone/Workturned the default output into a directory hierarchy under the current directory, and..segments could walk out of it, breaking the documented "single file in the current directory" default.Changes
IOSSimScreenshotCommand.prepareOutputURLcollapses the simulator name into a single path component (/→-) before building the default filename, matchingios-device screenshot. With separators gone,..can never form a standalone path component, which closes the traversal case as well.[A-Za-z0-9._:-]) already excludes separators, so this was structurally safe — it is now sanitised too, as defence in depth should the routing rules ever loosen (commented as such).sim-use-video-<ISO8601>.<ext>embeds no user-controlled text. Swept the codebase for other name-interpolating filename sites; the only remaining interpolations are daemon socket/pid/log paths keyed by shape-validated UDIDs.Verification
make build— passed, 0 warnings.make test— 1353 passed, 0 warnings; new regression tests pin the slash case (single component, resolves into cwd) and the traversal-shaped name.Slash/Name Probe, booted it, ran default-namesim-use screenshot— produced the single fileSimulator Screenshot - Slash-Name Probe - <timestamp>.pngin the working directory, no directory hierarchy. Probe simulator deleted afterwards.Not included
The simulator/video "remove the existing
--outputfile before capture" window (a failed capture afterprepareOutputURLloses the old file) is a separate pre-existing behaviour, also noted during #118 review — worth its own follow-up (temp + atomic replace, asios-device screenshotnow does) rather than riding along here.