Skip to content

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

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

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

Conversation

@simonhamp

Copy link
Copy Markdown
Member

What

Share.File passed its filePath argument 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.File is 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:

  • Canonicalise the path first — resolve symlinks and .. — then prefix-check, so neither a symlink nor .. can walk out of a root.
  • Allow three roots: the OS temp dir, the caches dir, and storage_path('app'). Everything else — .env, *.sqlite, public/, bootstrap/cache, storage/framework, storage/logs — is outside those and gets refused before the sheet opens.
  • Leave the URL branch (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 + /app on iOS, getDir("storage")/persisted_data/storage/app on Android, so it tracks the persistent location and not the app extract that an update swaps out.

What a reviewer should watch

  • The legitimate use still works: sharing a file the app captured into temp/cache or saved under storage/app opens the sheet as before.
  • iOS fails closed if LARAVEL_STORAGE_PATH is 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.
  • The Kotlin helpers live inside class File so File(...) keeps meaning java.io.File; java.io.File.separator is spelled out for the one static reference that would otherwise bind to the enclosing class.

Verification

  • tests/ShareConfinementTest.php reads 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.
  • Built against a real 4.x app: iOS Debug simulator, iOS unsigned Release, and the Android release AAB all compile.
  • Checked the confinement decision against a live simulator container: .env and the database are refused, a storage/app file and a temp file are allowed, and a ../ escape is canonicalised and caught.

Should release 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 2941920 into main Nov 5, 2026
4 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