Skip to content

fix(storage): verify run write roots like reads; make Flutter init the default - #91

Merged
ElbertePlinio merged 5 commits into
mainfrom
fix/alpha2-security-normalize
Sep 4, 2026
Merged

ElbertePlinio merged 5 commits into
mainfrom
fix/alpha2-security-normalize

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Summary

Phase 1 of #89 (storage/product normalization): fixes #54 and removes the mobileIntegrationAlpha flag so Flutter integration is the normal pickforge init path.

#54: project-local writes share the read trust boundary

  • New packages/core/src/run-root.ts holds one trust-boundary implementation for both directions. The catalog's read-side verifiedRoot now delegates to it.
  • ensureVerifiedRunsRoot materializes <trusted>/…/runs one level at a time with a plain (non-recursive) mkdir, then lstat + realpath each level against the trusted ancestor's real path. Trusted ancestors: the project directory (project-local), the Pickforge home (home), the custom base (custom). A symlinked .picklab, .picklab/runs, projects/<id>, a dangling link, a regular file in the way, or a missing project directory raises RunStorageAccessError before anything is created.
  • createRun binds the run directory identity (dev/ino + real path) and re-verifies it before every manifest write; openRun does the same for adopted runs. beginEvidenceRun and finalizeActiveEvidenceRun use the bound handles.
  • No migration, replacement, or deletion of existing entries. The error names the offending path.
  • Docs: README run-storage section, SECURITY.md, docs/releases/UNRELEASED.md (reset to an alpha.2 draft since alpha.1 is published).

Flag removal

  • --mobile-integration-alpha and MOBILE_INTEGRATION_ALPHA_DEFAULT removed from the Rust CLI; InitRequest::new defaults to IntegrationPack::flutter(). IntegrationPack::base() stays as the receipt-only pack for tests.
  • Help text, receipt remediation, CLI tests, the live Flutter e2e test, INSTALL.md, README, and release notes updated. Legacy PICKLAB_* compatibility untouched.

Complexity gate

beginEvidenceRun (complexity 29, depth 6, 165 lines), finalizeActiveEvidenceRun (complexity 19) and validate_receipt (complexity 16, bool_ops 5) were touched, so they were split into named steps; complexity-gate check --changed is clean and the legacy eslint-disable markers on those two functions are gone.

Test evidence

  • New packages/core/test/run-root.test.ts: 16 adversarial cases (committed .picklab symlink outside/inside the project, dangling link, regular file, missing project, symlinked project path accepted, root swapped for a symlink between verification and mkdir, run dir swapped for a symlink or replaced before a manifest write, adopted handle binding, evidence run routing, home projects/<id> symlink, symlinked home accepted, custom runs symlink, custom base creation). 11 of them fail against the previous run.ts; all pass now.
  • bun run typecheck, bun run lint: pass.
  • bun run test: 94 files, 1186 passed, 4 skipped. bun run test:coverage: thresholds pass (82.69% lines overall). bun run build: pass.
  • cargo fmt --check, cargo clippy --workspace --all-targets --locked -- -D warnings, cargo test --workspace --locked: pass (86 tests).
  • complexity-gate check --changed: pass.

Limitations

  • Node.js has no directory-handle-relative mkdir, so a swap between verifying one level and creating the next is detected after the fact (identity/realpath re-check) rather than prevented. No manifest, journal, or artifact is written through a redirected path; an empty stray directory can remain and is reported, not removed.
  • resolveActivePointer / clearActivePointer still read and unlink the pointer file via the unverified resolver path. wx create, atomic rename, and unlink do not follow a final-component symlink, so they cannot be redirected, but their reads are not identity-bound. Out of scope for Verify write-path symlinks before creating run directories #54.
  • The opt-in live Flutter e2e test (PICKFORGE_LIVE_FLUTTER=1) was not run.

Closes #54
Refs #89

…e default

Run storage writes now go through the same lstat/realpath trust boundary
the run catalog applies on read (#54). `ensureVerifiedRunsRoot` creates
each directory between the trusted ancestor (project dir, Pickforge home,
or custom base) and the runs root one level at a time with a plain mkdir
and verifies it is a real directory resolving exactly where the ancestor
says it should. A committed `.picklab` symlink, a symlinked `runs`, a
symlinked `projects/<id>`, a dangling link, or a regular file in the way
raises `RunStorageAccessError` before anything is created. Run handles
carry the directory identity and re-verify it before every manifest
write; evidence runs adopt and finalize through the same bound handles.
Nothing on disk is migrated, replaced, or deleted.

Remove the `--mobile-integration-alpha` flag and its prerelease-only
default: `pickforge init` always plans the Flutter pack, stable and
prerelease alike, and the receipt remediation names plain `pickforge
init`. Legacy `PICKLAB_*` compatibility is untouched.

Refactor `beginEvidenceRun`, `finalizeActiveEvidenceRun`, and
`validate_receipt` into named steps to clear the complexity gate.

Closes #54
Refs #89
Re-checking a pathname before writing to it cannot stop an ancestor from
being swapped in between, so manifests, journals, pointers, and screenshots
could still be redirected out of the runs root after verification passed.

Every sensitive run-storage write now goes through a directory descriptor:
the directory is opened once with `O_DIRECTORY|O_NOFOLLOW`, verified through
that descriptor (its real path is read back from `/proc/self/fd/<fd>`), and
the writes of the operation are issued through the same descriptor. The runs
root itself is built descriptor by descriptor from the trusted ancestor, so a
symlinked `.picklab`, `runs`, or project-id component is refused rather than
followed, and no lookup re-traverses an ancestor that could have changed.

Screenshots and other producer-written artifacts are captured into a
process-private staging directory while the run directory's descriptor is
held, then published through it, since an external tool cannot be handed a
descriptor.

Run adoption stays internal: `openRun` is no longer exported, and the one
adoption helper requires a single-component run id naming a real directory
directly under the verified root plus a manifest that describes that run, so
a traversing id like `../../../outside` is refused instead of adopted.

The mechanism is Linux-only, like the lab; elsewhere run-storage writes fail
closed instead of falling back to redirectable pathname writes. Reads and
retention pruning keep the existing lstat/realpath boundary, and the docs now
say so instead of claiming more.

Refs #54
@ElbertePlinio ElbertePlinio mentioned this pull request Sep 4, 2026
56 of 58 tasks
@ElbertePlinio
ElbertePlinio merged commit cc7cc02 into main Sep 4, 2026
5 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/alpha2-security-normalize branch September 4, 2026 23:10
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.

Verify write-path symlinks before creating run directories

1 participant