Repository navigation
Confine the file path Share.File vends to the share sheet - #6
Merged
Merged
Conversation
Share.File takes a filePath straight from the web view bridge and hands it to
the OS share sheet with no checks. A page (XSS, or bundled third-party JS) can
name .env or the SQLite database and have the share sheet offer it up — a file
read-out. It is gated by the user picking a share target, so lower severity
than mobile-file's silent copy, but the same root cause.
Mirror the source-side confinement from core's FileFunctions: canonicalise the
path (resolving symlinks and ..) and require it to land inside one of the app's
readable roots — the OS temp dir, the caches dir, or storage_path('app') —
before anything reaches the share sheet. Anything else (.env, *.sqlite,
public/, bootstrap/cache, storage/framework) is refused. URLs are not files, so
the URL branch is left alone, and the documented use (sharing a captured file
from temp/cache or storage/app) still works.
The storage root is derived from LARAVEL_STORAGE_PATH + /app on iOS and
getDir("storage")/persisted_data/storage/app on Android, matching how core
resolves storage_path(), so it tracks the persistent location rather than the
ephemeral app extract.
Tests read the two native files and assert the guard stays in place and ahead
of the share call on both platforms, since no PHP test can run the native code.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
What
Share.Filepassed itsfilePathargument straight to the native share sheet with no checks. This confines it: the path has to resolve inside one of the app's readable roots before anything is shared.Why
Share.Fileis reachable from the web view bridge, so a page — an XSS, or bundled third-party JS — can hand it any path. With no confinement it can name a file outside the app's own working areas (.env, the SQLite database) and have the share sheet offer it up. It's gated by the user actually picking a share target, so it's not silent, but it's still a way to read a named file out of the sandbox. Same root cause as the mobile-file File.Move/Copy fix.The fix
Source-only confinement (Share just reads the file), mirroring the guard in core's FileFunctions:
..— then prefix-check, so neither a symlink nor..can walk out of a root.storage_path('app'). Everything else —.env,*.sqlite,public/,bootstrap/cache,storage/framework,storage/logs— is outside those and gets refused before the sheet opens.http/https/ftp) alone; it shares a string, not a file.The storage root is derived the way core resolves
storage_path():LARAVEL_STORAGE_PATH + /appon iOS,getDir("storage")/persisted_data/storage/appon Android, so it tracks the persistent location and not the app extract that an update swaps out.What a reviewer should watch
storage/appopens the sheet as before.LARAVEL_STORAGE_PATHis ever unset (storage sharing is refused, temp/cache still work) rather than falling back to a core symbol — keeps the plugin compiling against both 3.x and 4.x cores.class FilesoFile(...)keeps meaningjava.io.File;java.io.File.separatoris spelled out for the one static reference that would otherwise bind to the enclosing class.Verification
tests/ShareConfinementTest.phpreads both native files and pins the guard in place and ahead of the share call (no PHP test can run the native code). Full Pest suite green, Pint clean..envand the database are refused, astorage/appfile and a temp file are allowed, and a../escape is canonicalised and caught.Should release as 1.1.1.
🤖 Generated with Claude Code