fix(browser-runtime): prevent path traversal in SKILL_API filesystem bridge (CWE-22)#219
Open
sebastiondev wants to merge 2 commits intoAIPexStudio:mainfrom
Open
Conversation
All paths passed to SKILL_API.fs.* operations from untrusted skill code running in the QuickJS sandbox are now resolved relative to the skill root (/skills/<skillId>) and validated to stay within it. This prevents one skill from reading, writing, or deleting files belonging to other skills. - Adds resolveSafePath() that normalizes via posix path.resolve() and rejects any resolved path outside /skills/<skillId>/. - Rejects paths containing null bytes. - Every async and sync fs method in the bridge now calls safePath() before delegating to zenfs. - Adds 25 unit tests covering traversal attacks, allowed paths, and edge cases.
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.
Summary
The
SKILL_API.fs.*bridge inpackages/browser-runtime/src/lib/vm/skill-api.tspasses paths supplied by skill code directly to the zenfs filesystem mounted at/skills. Because no path validation occurs, a skill can read, overwrite, or delete files belonging to other installed skills by using..segments or absolute paths — breaking the per-skill isolation that the QuickJS sandbox is intended to enforce.packages/browser-runtime/src/lib/vm/skill-api.tsfsmethods exposed to skills (readFile,writeFile,readdir,exists,mkdir,rm,stat, plus the*Syncvariants)Data flow (before fix)
A malicious or compromised skill running under skillId
evilcould:fs.readFile("../victim/credentials.json")— read another skill's datafs.writeFile("/skills/victim/index.js", payload)— overwrite another skill's codefs.rm("../victim", { recursive: true })— delete another skill entirelyfs.readdir("/skills")— enumerate every installed skillFix
Introduce a
resolveSafePath(skillId, userPath)helper and route everyfs.*call through it before invoking zenfs.The helper:
/skills/<skillId>) usingposix.resolve, which collapses../.segments and absorbs absolute paths into the resolved string.skillRootor starts withskillRoot + "/". The trailing slash is important — it prevents the sibling-prefix bypass where/skills/abc-evilwould otherwise be accepted as "starting with"/skills/abc.All 14 fs methods (async + sync) are updated to call
safePath(). There is no parallel code path that bypasses the helper.Tests
Added 25 new unit tests in
skill-api.test.tscovering:..traversal (../other/file,../../etc/passwd)/skills/other,/etc/passwd)sub/../../other)/skills/<id>-evil/...)*SyncvariantsFull test suite (
npm run preflight) passes locally, including pre-existing tests.Security analysis
Why this is exploitable. Skills are explicitly designed to run untrusted third-party code in QuickJS, and the per-skill
/skills/<skillId>/directory is the isolation boundary that callers rely on. Thefsbridge previously passed paths through verbatim, so any skill could enumerate or mutate any other skill's files using standard path traversal — no exotic primitives required.Preconditions. The user installs or runs a malicious skill. This is precisely the threat model the QuickJS sandbox exists to contain; treating it as a precondition would defeat the purpose of the sandbox. The fix is what makes cross-skill isolation actually hold.
What the fix prevents. Cross-skill read, write, and delete; enumeration of installed skills via
/skills; escapes to arbitrary virtual-FS paths. It does not change behavior for legitimate in-scope paths.Adversarial review
Before submitting, we tried to disprove this. We checked whether zenfs itself enforces a chroot-style boundary on the
/skillsmount (it doesn't — it's a generic filesystem), whether the QuickJS marshalling layer normalizes or restricts paths (it forwards them as plain strings), and whether installation flows somehow prevent a skill from issuing arbitraryfscalls (they don't — the bridge is the only gate). We also confirmed there isn't a separate vetting/signing step that would make malicious skills out-of-scope; skills are user-installable and the sandbox is the documented trust boundary. The traversal is therefore reachable from the intended attacker model and not mitigated elsewhere.cc @lewiswigmore