Repository navigation
feat(execd): block pseudo-filesystems and internal platform paths on /files and /directories APIs - #3091
feat(execd): block pseudo-filesystems and internal platform paths on /files and /directories APIs#3091Pangjiping wants to merge 10 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87cb2d197f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Pangjiping
left a comment
There was a problem hiding this comment.
Review notes for 87cb2d1, all findings as inline comments below.
The direct-access goal works: on the base commit GET /files/download?path=/proc/1/environ&offset=1 returns 200 (177 bytes) and /directories/list?path=/dev returns 200; both are 403 here. What remains is that the guard can be bypassed and the public contract is not synced yet.
Items marked reproduced were run against this commit in a Linux container (go1.26.11, kernel 6.12, root) and on macOS, with throwaway tests that are not part of this PR.
| # | Severity | Where | Issue | Status |
|---|---|---|---|---|
| S1 | High | filesystem.go:253,257 |
symlink/.. deletes a blocked tree via DELETE /directories |
reproduced, HTTP 200 |
| S2 | High | filesystem_upload.go:168,179,314 |
symlink/.. writes into a blocked directory via upload |
reproduced |
| S3 | High | filesystem_download.go:65,84, utils.go:40 |
check-then-use race serves blocked regular files | reproduced, 1965–2051 of 30000 requests |
| S4 | Medium | filesystem_guard.go:141 |
relative deny_paths not enforced by the identity worker |
reproduced, 200 with contents |
| S7 | Medium | main.go:102 |
default lifecycle config path is not blocked | code-verified |
| S5 | Low | filesystem.go:448 |
list / search are lexical-only | reproduced, 237 entries via a procfs alias |
| S6 | Low | filesystem_guard.go:281 |
more than 40 symlink hops fails open | Linux relies on ELOOP, no leak |
| F1 | High | model/error.go:27 |
403 not in the spec; docs and generated SDKs not updated | verified |
| F2 | High | filesystem_guard.go:239, filesystem.go:586 |
gocognit 40 / 33 / 31 and mirror turn the lint job red |
reproduced with gocognit |
| F3 | High | filesystem_guard_test.go:403 |
syscall.Mkfifo breaks the Windows go vet |
reproduced |
| F4 | Medium | filesystem.go:372 |
per-entry full path walk slows search and list | measured, 15.7x |
| F5 | Medium | filesystem_guard_linux.go:71 |
fallback and worker-propagation paths untested | 0 coverage for the fallback |
| F6 | Medium | filesystem_guard.go:214 |
deny rules ineffective on Windows | static and pure-function check |
| F7 | Low | filesystem_guard_linux.go:71 |
fstatfs error fails open, dead branches |
code-verified |
| F8 | Low | filesystem_guard_other.go:23 |
FIFO open still blocks on non-Linux | pre-existing on the base commit |
S1, S2 and F4 have one-line or small fixes that I checked locally: os.RemoveAll(absDir), returning absPath from resolveUploadTarget, and a lexical-first check in the walks. With those, S1 and S2 no longer reproduce and the search/list allocations return to base numbers.
The Linux-only cases that CI skipped because the lint step failed first (TestIsBlockedFSMagic, TestOpenGuardedReadFileRejectsProcDescriptor, TestFilesystemControllerRejectsFIFO, the identity tests) pass when run manually in a container, as do go test and go test -race for ./pkg/web/controller, ./pkg/web and the main package.
Pangjiping
left a comment
There was a problem hiding this comment.
Round-2 verification of ca1247f. Thanks, this closes most of the first round. I re-ran the earlier reproductions and the PR tests at this commit on Linux (container, root, with -race) and on macOS.
| Round-1 finding | Status | Re-verification |
|---|---|---|
| S1 | fixed | blocked tree survives symlink/.. on DELETE /directories |
| S2 | partial | reported shape fixed; a symlink-target .. shape is still open (N1) |
| S3 | partial | reads fixed: 0 of 30000 raced requests leaked (was 1965–2051); mutations still racy (N2) |
| S4 | fixed | identity route returns 403 for a relative deny path |
| S5 | partial | list and download on a procfs alias are 403; /files/info still returns metadata (N7) |
| S6 | fixed | a 45-hop chain returns 403 |
| S7 | fixed | lifecycle.ResolveConfigPath() |
| F1 | fixed | 22/22 operations declare 403; Python and JS clients match generator output; pnpm docs:build passes |
| F2 | fixed | CI lint reports 0 issues; gocognit max 29 |
| F3 | fixed | GOOS=windows go vet passes; Windows CI job green |
| F4 | fixed | allocations back to base; 1.03–1.57x time (was 15.7x) |
| F5 | partial | 6 tests added; no negative test for N1 / N2 |
| F6 | partial | operator rules enforced on Windows; N3 / N4 remain |
| F7 | fixed | fstatfs fails closed; dead branches removed |
| F8 | fixed | FIFO returns 403 immediately on macOS |
Still blocking: N1. Every path-based mutation can still be steered into a blocked root, deterministically, through a symlink whose target contains <symlink>/..: chmod 0777, mv the file out, delete, upload (create or overwrite), rmdir, mkdir. N2 is the same endpoints under a directory-swap race. Details are in the inline comments. N3 to N7 are low or informational.
Pangjiping
left a comment
There was a problem hiding this comment.
Addendum to the round-2 review above, after a tool-assisted pass over ca1247f. Two more findings, both checked at this commit on Linux and macOS:
- N8 (High): the guard checks only the requested path.
rmdirormvof an ancestor of a blocked root is accepted and takes the blocked subtree along. Details are inline (delete onfilesystem.go, rename onutils.go). - N9 (Low):
permis ignored by the UnixopenGuardedWriteFile; no live bug today.
The other two points from that pass (the RemoveDirs race and the uncleaned Windows deny path) are already covered by N2 and N3.
…and fstatfs info guard
…sed perm, and fix lint
…, chunk rmdir, and use renameat2
…nd scope glob ancestor walk
…te walks, and handle renameat2 EPERM
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: abff2b2c86
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31b04331e7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
… block /dev bind mounts
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53495f4f94
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if err := checkFilesystemPath(absTarget); err != nil { | ||
| return newUploadError(http.StatusForbidden, model.ErrorCodePermissionDenied, err.Error()) |
There was a problem hiding this comment.
Create upload staging files through a guarded parent
When a root daemon uploads to /workspace/slot/file and sandbox code flips slot from an allowed directory to /etc/execd after this check, the later path-based createUploadTemp follows the new symlink and writes request bytes into the blocked tree; flipping it back before commit also makes cleanup miss the random staging file, enabling persistent disk pollution. The fresh evidence after the guarded-open fix is that staging creation still never uses a pinned destination directory descriptor.
AGENTS.md reference: AGENTS.md:L46-L47
Useful? React with 👍 / 👎.
| return err | ||
| } | ||
| cleaned := filepath.Clean(absPath) | ||
| if g.isRootOrBlockedAncestor(cleaned) || g.hasGlobBlockedDescendant(cleaned, checkAllGlobs) { |
There was a problem hiding this comment.
Make anchored-glob rename enforcement atomic
When an anchored deny_globs rule is configured and another process adds a matching credential after this path-based descendant scan, the subsequent descriptor-based directory rename never rechecks the tree and moves the credential to a destination where the anchored pattern no longer matches, making it available through the file API. Enforce the anchored rule against the pinned source atomically, or refuse such directory renames when that guarantee cannot be maintained.
AGENTS.md reference: AGENTS.md:L46-L47
Useful? React with 👍 / 👎.
| if canonical := canonicalizeExistingPrefix(cleaned); canonical != "" && | ||
| canonical != filepath.Dir(canonical) { | ||
| appendNormalizedRoot(&roots, seen, canonical, windowsMode, caseInsensitive) |
There was a problem hiding this comment.
Export canonical roots to identity workers
When an extra blocked path contains a symlink beneath a directory that the selected filesystem UID cannot traverse, the privileged parent resolves and blocks the canonical target here, but CurrentFilesystemGuardPolicy exports only the lexical normalizedExtras; the reduced-identity worker cannot rediscover that canonical path and can access it directly when DAC otherwise permits. Include the parent's canonical extra roots in the propagated policy so identity-prefixed routes enforce the same guard.
AGENTS.md reference: AGENTS.md:L46-L47
Useful? React with 👍 / 👎.
| return nil, statErr, newUploadError( | ||
| http.StatusInternalServerError, | ||
| model.ErrorCodeRuntimeError, | ||
| fmt.Sprintf("error opening destination file %s. not a regular file", resolvedTarget), |
There was a problem hiding this comment.
Return forbidden for special upload destinations
When the upload destination already exists as a FIFO, socket, or device, this branch explicitly returns 500 RUNTIME_ERROR, even though the new public Forbidden response classifies special device/FIFO/socket nodes as 403 FORBIDDEN_PATH. Generated consumers therefore treat this policy denial as a server failure; map these special modes to the forbidden response while retaining the appropriate handling for directories.
AGENTS.md reference: AGENTS.md:L46-L47
Useful? React with 👍 / 👎.
| default: | ||
| return false |
There was a problem hiding this comment.
Block remaining pseudo-filesystem submounts
On Linux where a submount such as /sys/firmware/efi/efivars is bind-mounted below an allowed directory, fstatfs reports EFIVARFS_MAGIC, which falls through this switch and is not covered by the /dev device-ID check, so regular efivarfs entries can be served or mutated through the alias. The fresh evidence after the reported alias fix is that the new table still omits pseudo-filesystem types mounted beneath the blocked /sys and /dev trees.
AGENTS.md reference: AGENTS.md:L46-L47
Useful? React with 👍 / 👎.
Summary
Closes #3086
Adds an unconditional pseudo-filesystem and internal platform-path guard across all
execd/files/*and/directories/*HTTP APIs (including identity-scoped/v1/filesystem/:uid/:gid/*workers), updates the publicspecs/execd-api.yamlcontract, docs, and generated Python/JS SDK clients:/proc,/sys,/dev,/sys/fs/cgroup,/var/lib/execd,/etc/execd,/etc/opensandbox,/opt/opensandbox, and/var/log/opensandbox; across all platforms (including Windows), blocks dynamicupper_root,EXECD_ISOLATION_CONFIG,EXECD_LIFECYCLE_CONFIG/ default$HOME/.execd/lifecycle.toml,--lifecycle-startup-status-file,ebpf.audit_file, and operator-configured[filesystem]deny_paths/deny_globs, returning403 Forbidden(FORBIDDEN_PATH) on direct access without leaking target contents...against the resolved directory rather than lexically collapsing<symlink>/..), handles dangling symlinks and relative chains, and fails closed past 40 hops.DownloadFile,ReplaceContent,UploadFile,DeleteFile,ChmodFile,RenameFile,MakeDir,RemoveDirs,GetFileInfo) walk directory descriptors withO_NOFOLLOW— usingO_PATHfor directory traversal and metadata operations on Linux (preserving non-root identity worker access through traverse-only0733dirs andchmodon owned0200files / FIFOs / sockets),openat2(RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS)(withopenatfallback),renameat2(RENAME_NOREPLACE), chunkedReadDirremoval, and fail-closedfstatfspseudo-filesystem magic checks with warning logs.DELETE /directories) and rename (POST /files/mv) refuse/and any ancestor directory of a blocked root or glob-protected descendant.GET /directories/listandGET /files/searchperform zero-syscall lexical checks for ordinary entries, resolve only symlink-typed entries, and checkfstatfson directories to prune bind-mounted pseudo-filesystem aliases (filepath.SkipDir) instead of failing broad walks such aspath=/.--filesystem-workerover fd 4 so/v1/filesystem/:uid/:gid/*enforces the same rules as the parent daemon regardless of cwd.isolation.toml) & Windows normalization: Adds[filesystem]withdeny_paths(validated as absolute non-root subtree prefixes) anddeny_globs(doublestar patterns), with cleaned, separator- and case-normalized matching on Windows.403 Forbidden(FORBIDDEN_PATH) and behavior notes to all 22 filesystem operations inspecs/execd-api.yaml, regenerates Python & JavaScriptexecdAPI clients, and documents the guard and[filesystem]config indocs/guides/privilege-reduction.md,docs/architecture/data-plane/execd.md, andcomponents/execd/configs/isolation.example.toml.Testing
Verified:
components/execd:go test -race ./pkg/web/... .,go test -run TestLoadConfigFilesystem ./pkg/isolation(including FIFO rejection,chmodon FIFO &0200files, nested-..symlink targets, ancestor delete/rename for blocked roots and anchored globs, and concurrent symlink-swap TOCTOU tests for both reads and mutations)GOOS=linux GOARCH=amd64 go test -c ./pkg/web/controller ./pkg/webGOOS=linux GOARCH=amd64 go vet ./...&GOOS=windows GOARCH=amd64 go vet ./...sdks/sandbox/python:uv run python scripts/generate_api.py && uv run ruff check && uv run pytest tests/sdks/sandbox/javascript:pnpm run gen:api && pnpm run typecheck && pnpm run test(521/521)docs:pnpm docs:buildBreaking Changes
Intentional security hardening on
/files/*,/directories/*, and/v1/filesystem/{uid}/{gid}/*:/proc,/sys,/dev,/sys/fs/cgroup), internal platform paths (/var/lib/execd,/etc/execd,/etc/opensandbox,/opt/opensandbox,/var/log/opensandbox, and configured runtime/config/audit paths), or special non-regular files (FIFOs, devices, sockets on download/upload/replace) now return403 FORBIDDEN_PATH.DELETE /directoriesandPOST /files/mvrefuse/and any ancestor directory of a blocked root or glob-protected descendant (including shared directories such as/tmpwhen a blocked runtime file like the lifecycle status file resides beneath it)./directories/listand/files/searchomit blocked subtrees and symlinks whose target resolves to a blocked path instead of failing broad walks.Checklist