Repository navigation
fix: containment check rejects not-yet-created files in Directory.Temporary - #20
Merged
Merged
Conversation
…sed directories assertContained canonicalized the directory and the target with resolvingSymlinksInPath(), which only strips /private when the path exists. For a new file in Directory.Temporary the directory became /var/... while the target stayed /private/var/..., so pathEscapesDirectory was thrown for a valid path. Resolve the deepest existing ancestor and re-append the rest.
andredestro
requested review from
a team,
ItsChaceD,
OS-pedrogustavobilro,
OS-ruimoreiramendes,
alexgerardojacinto,
jcesarmobile,
markemer and
theproducer
October 14, 2026 08:39
OS-pedrogustavobilro
approved these changes
Oct 14, 2026
OS-pedrogustavobilro
left a comment
Contributor
There was a problem hiding this comment.
Dang, it hasn't been long enough to pull the "who wrote that buggy code over at #17" joke 😆
Thought I had tested the different combinations of Directory but guess not.
Also, this makes me think that we evaluate (again?) if we want to have ~> / from on Pod/SPM or use an exact version, to stop customers from accidentally getting a version that could have regressions without actually updating the plugin version from npm. I think we have this in some plugins but others (like filesystem) don't, so should be standardized. I'll create a task for us to look into this.
Anywho, the fix LGTM! Approving the PR.
capacitor-bot
pushed a commit
that referenced
this pull request
Oct 14, 2026
## [2.0.1](2.0.0...2.0.1) (2026-10-14) ### Bug Fixes * contain check rejected not-yet-created files under /private aliased directories ([#20](#20)) ([4e8aa68](4e8aa68))
2 of 7 tasks
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.
Problem
Since 1.1.4 (#17), writing a new file to
Directory.Temporaryon iOS fails (surfaced in the plugin asOS-PLUG-FILE-0006). Reported in ionic-team/capacitor-filesystem#90.assertContainedcanonicalized the directory and the target withresolvingSymlinksInPath(), which only strips/privatewhen the path exists:/var/.../tmp//private/var/.../tmp/new-file.txtThe prefix check failed and
pathEscapesDirectorywas thrown for a valid path.Fix
New
canonicalizeresolves the deepest existing ancestor and re-appends the missing components, so both sides use the same form...and symlink-escape protection is unchanged (existing tests still pass).Tests
..._resolvedViaPrivateVarAlias_containsNotYetCreatedFile. Against the pre-fix code it fails withpathEscapesDirectory(path: "/private/var/.../new-file.txt/", directory: "/var/.../allowed"); with the fix it passes. Full suite passes (iPhone 17 Pro simulator).Device verification (iPhone 16 Pro Max, iOS 27.0.1)
The bug does not reproduce on the simulator (its
tmp/lives under/Users/..., no/privatealias), so this was verified on a physical device with the capacitor-filesystem example app. Both XCFrameworks were built locally withscripts/build_framework.shand the same Xcode (26.6), so the only variable is this commit; the binary UUID in the app bundle was checked to match each build.Directory.Temporary2.0.0(tag, built locally)statOS-PLUG-FILE-0006OS-PLUG-FILE-0008(does not exist) ✅writeFileOS-PLUG-FILE-0006, nothing intmp/tmp/✅writeFileto../../escape.txttmp/✅The published 2.0.0 (CocoaPods) shows the same failure as the locally built tag.