Skip to content

Confine the file path Share.File vends to the share sheet - #5

Merged
simonhamp merged 1 commit into
mainfrom
harden/share-confined-path
Nov 4, 2026
Merged

simonhamp merged 1 commit into
mainfrom
harden/share-confined-path

Conversation

@simonhamp

Copy link
Copy Markdown
Member

Confines the file path Share.File hands to the share sheet, so a web view page can't exfiltrate a named sandbox file.

Share.File took a page-supplied filePath and passed it to the OS share sheet (iOS UIActivityViewController, Android FileProvider + ACTION_SEND) with no confinement. Because /_native/api/call is reachable from web view script (an XSS, or a bundled third-party script), a page could name .env or the SQLite database and have it vended out. It's gated by the user picking a share target, so lower severity than a silent read, but the same root cause as the nativephp/mobile-file path issue.

The fix confines the source: canonicalise filePath (resolve symlinks and ..) and require it to resolve inside the app's readable roots (temp, caches, storage_path('app')), refusing .env, *.sqlite, bootstrap/cache, storage/framework, storage/logs, public/. Legitimate use — sharing a file the app captured into temp/cache/storage — still works. Source-assertion tests pin the guard on both platforms. Releases as 1.1.1.

🤖 Generated with Claude Code

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>
@simonhamp
simonhamp merged commit cc30896 into main Nov 4, 2026
2 checks passed
@simonhamp
simonhamp deleted the harden/share-confined-path branch November 5, 2026 23:07
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.

1 participant