Skip to content

fix: containment check rejects not-yet-created files in Directory.Temporary - #20

Merged
andredestro merged 1 commit into
mainfrom
fix/canonical-path-not-yet-created-file
Oct 14, 2026
Merged

andredestro merged 1 commit into
mainfrom
fix/canonical-path-not-yet-created-file

Conversation

@andredestro

@andredestro andredestro commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Since 1.1.4 (#17), writing a new file to Directory.Temporary on iOS fails (surfaced in the plugin as OS-PLUG-FILE-0006). Reported in ionic-team/capacitor-filesystem#90.

assertContained canonicalized the directory and the target with resolvingSymlinksInPath(), which only strips /private when the path exists:

  • directory (exists) -> /var/.../tmp/
  • new file (doesn't exist) -> /private/var/.../tmp/new-file.txt

The prefix check failed and pathEscapesDirectory was thrown for a valid path.

Fix

New canonicalize resolves 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

  • Added ..._resolvedViaPrivateVarAlias_containsNotYetCreatedFile. Against the pre-fix code it fails with pathEscapesDirectory(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 /private alias), so this was verified on a physical device with the capacitor-filesystem example app. Both XCFrameworks were built locally with scripts/build_framework.sh and 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.

On new file in Directory.Temporary 2.0.0 (tag, built locally) this PR
stat OS-PLUG-FILE-0006 OS-PLUG-FILE-0008 (does not exist) ✅
writeFile OS-PLUG-FILE-0006, nothing in tmp/ written, file present in tmp/ ✅
writeFile to ../../escape.txt blocked still blocked, nothing written outside tmp/ ✅

The published 2.0.0 (CocoaPods) shows the same failure as the locally built tag.

…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.

@OS-pedrogustavobilro OS-pedrogustavobilro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@andredestro
andredestro merged commit 4e8aa68 into main Oct 14, 2026
1 check passed
@andredestro
andredestro deleted the fix/canonical-path-not-yet-created-file branch October 14, 2026 13:18
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))
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.

2 participants