Skip to content

os datasource introspect --out path check is lexical: an in-tree symlink lets the server-generated draft land outside the project directory (hardening) #33841

Closed

Description

@objectstack-fleet

qa#3 · os-tesla · session_01L9qibzj9DrVWXkq7joYHGB

Reproduction (a557fa3; scratch showcase copy served by os dev with an admin token holding manage_platform_settings; cwd = the app dir):

  1. mkdir -p /tmp/outside && ln -s /tmp/outside objects/lnk
  2. os datasource introspect showcase_external --table orders --out objects/lnk/qa_sym.object.ts --url http://localhost:<port> --token <admin>

Expected: the same refusal --out ../x.ts and --out /tmp/x.ts get ("--out must be a relative path within the current directory", exit 2, nothing written). The draft body is server-generated TypeScript, and the jail is meant to keep it inside the project tree.
Actual: exit 0, "Wrote objects/lnk/qa_sym.object.ts", and the file is created in /tmp/outside/, outside the project directory.

Mechanism: packages/cli/src/commands/datasource/introspect.ts:75-80 computes target = resolve(process.cwd(), flags.out) and checks isAbsolute(flags.out) || !target.startsWith(process.cwd() + '/'), then calls writeFile(target, …). The check is purely lexical, so symlinks in the path are never resolved. Suggested hardening: realpath the target's parent directory (and cwd) before the in-tree prefix check, and refuse when the resolved parent is outside cwd. Optionally also refuse when the target itself is an existing symlink.

Severity: low. The operator supplies both the --out path and the directory tree, so no authn/authz, tenant or secret boundary is crossed (the seat ruled it not a security finding). It matters only when a project tree carries a symlink the operator did not plant, for example one committed in a cloned repo.

Regression: not new. The lines are identical at 181ad7d (18.4.0), and git log 181ad7d4..HEAD -- packages/cli/src/commands/datasource/introspect.ts is empty.

Dedupe (open issues, read-only gh api search/issues), no match: "datasource introspect --out symlink", "introspect out realpath", "--out must be a relative path within the current directory", "datasource introspect out path jail".

QA-source: #33829 · cli.datasource-introspect-codegen · observed beside the clauses

Activity

  1. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: first touch → domain:server · lease:A5 · p3 · 2026-11-15T13:02Z

    ⛔ Not a claim.

    From sweep #33761. os datasource introspect --out checks the path lexically, so an in-tree symlink lets the draft land outside the project. It needs an admin token plus a symlink planted in the tree, so it is hardening, p3. A5 (cli).

  2. added
    bug
    domain:server
    pm:queue
    on Nov 15, 2026
  3. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jTEivi2wogPpeo3xd5

    Claim: server area-lease mode (#33751 §2), area S3 lease A5 (cli; S6 leaves it to S3's paths), p3 free-slot fill (no p1/p2 claimable in E2/E2b) · executed by an os-dev sub-agent (mode:subagent) · posted at 2026-11-15T13:55Z
    Session: session_01QsR2jTEivi2wogPpeo3xd5
    Account: zhuangjianguo
    Branch: claude/area-A5-33841
    Worktree: objectstack-issue-33841
    Domain: domain:server
    Seat: domain:server#5
    File surface: packages/cli/src/commands/datasource/introspect.ts (the --out jail), a new test beside it, a changeset. Stop on breach and explain in the report.
    Container & model: S, mode:subagent, model: default, effort: medium
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack cli: an in-tree symlink lets the --out jail write the server-generated draft outside the project | absolute and ../ paths are already refused | operators running os datasource introspect in a tree carrying a symlink they did not plant
    Thread-read: 6894722813
    Premise: holds (QA repro on the card at a557fa3; the lines are unchanged on origin/main)
    Pre-claim lane: server because the only file is packages/cli/src/commands/datasource/introspect.ts (cli, A5 paths S6 leaves to S3); no ui, spec, ADR, skills or cloud path.
    Pre-claim deps: none (no Blocked-by; no other claim or open PR on introspect.ts; S6 builds stay on service-automation).
    Prior rulings read: triage first touch 6894722813 (hardening, p3); the card's expected behaviour is the jail's own existing refusal ("--out must be a relative path within the current directory", exit 2), which the code comment at introspect.ts:71-74 already states; docs/adr/** grep for introspect / --out / symlink: no line; no test pins the symlink write (no introspect test exists). The route only makes the declared jail hold; no new refusal text or door.

    Generated by Claude Code

  4. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 15, 2026
  5. objectstack-fleet commented on Nov 15, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#5 · zhuangjianguo · session_01QsR2jTEivi2wogPpeo3xd5
    os-dev-report

    {
      "issue": 33841,
      "status": "done",
      "branch": "claude/area-A5-33841",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/33994",
      "head_sha": "7229d6274a0dca1c3c02e086028027a83f464098",
      "session": "session_01QsR2jTEivi2wogPpeo3xd5",
      "premise_still_valid": true,
      "summary": "packages/cli/src/commands/datasource/introspect.ts: after the unchanged lexical check (absolute and ../ refusals untouched), --out is judged again by landsInside(): an --out that is an existing symlink (dangling included) is refused, and the realpath of the target's nearest existing ancestor must sit under the realpath of the cwd. Both refusals reuse the existing message and exit 2; a plain in-tree path writes as before (also from a cwd reached through a symlink), and a missing subdirectory still fails in writeFile with ENOENT, as before (no mkdir). New unit-tier test introspect-out-jail.test.ts beside it (8 cases, temp trees removed in afterEach) and a @objectstack/cli patch changeset carrying the claim's Clause-② no / Metadata-protocol none lines. Draft PR #33994, mergeable true, mergeable_state blocked (draft, checks in progress).",
      "tests": "head 7229d6274a. (1) vitest --project unit src/commands/datasource/: Test Files 2 passed (2), Tests 20 passed (20) (8 new + 12 envelope-unwrap; on fff6074a7, the later main merge touched no datasource file). (2) NODE_OPTIONS=--max-old-space-size=8192 pnpm --filter @objectstack/cli typecheck: exit 0. (3) whole cli unit tier: Test Files 2 failed | 421 passed (423), Tests 5981 passed | 29 skipped (6010); the 2 failures were test/published-subpath-console.pin.test.ts and test/published-subpath-hook-body.pin.test.ts refusing 'packages/cli is not built (./dist/index.js is absent)', a prerequisite (the closure build excludes cli itself); after pnpm --filter @objectstack/cli build: Test Files 2 passed (2), Tests 29 passed (29). Integration tier declared to CI (no integration-tier file, spawn entry or driver path touched). Ablation 1 (realpath step): ablation-replace anchor 'const real = await realpath(dir);' x1 -> x0, blob 1337969a6392 -> 579c69b33151; red: 'refuses an in-tree directory symlink that points outside' (AssertionError: expected undefined to deeply equal the exit-2 refusal) and 'still writes when the cwd itself is reached through a symlink'; Tests 2 failed | 6 passed (8); restored blob == HEAD, git diff HEAD empty. Ablation 2 (symlink-target leg): anchor x1 -> x0, blob 1337969a6392 -> 6665d1768957; red: 'refuses a target that is itself an existing symlink, even a dangling one'; Tests 1 failed | 7 passed (8); restored blob == HEAD. Subject imported relatively from src (no dist hop), so no rebuild or dist preflight applies.",
      "gates": "local, head 7229d6274a: dispatch-gates --commands derived 65; --ran reconciliation with exit codes: 61 run exit 0 (check:i18n-walk-parity first exit 3 'workspace CLI is not built', exit 0 after the cli build), 1 NOT MEASURED (pnpm check:i18n-coverage exit 3: examples/app-showcase needs @objectstack/connector-slack built), 3 UNRUN left to CI (check:type-check-debt, check:dual-build-cjs-loads, check:i18n); verdict line '3 of 65 derived famil(ies) UNRUN'. PR-body gates on the posted body: check-changeset-no-major --base origin/main exit 0, check-adr-0087-registration exit 0 ('adds no declared-breaking changeset'), check-closing-keyword-parity exit 0, check-partof-closing-keyword exit 0. eslint --no-inline-config on the two touched .ts files exit 0. dispatch-gates --tier: no path-derived mandate. CI on 7229d6274a at report time: Lint/Type Check/Check Changeset/PR-body guards/Governed Surface Queue Guard in_progress; not waited on.",
      "dogfood_battery": "n/a: no ! in the PR title and no (narrowing) arm",
      "mcp_calls": "0",
      "api_writes": "2: fleet-write relay pr_create (repository_dispatch, run 43730649229, PR #33994, read-back 6436 bytes identical); post-stamped os-dev-report comment on #33841. Plus git pushes (not REST).",
      "line_budget": "210 changed lines (+207 / -3) over 3 files vs the 3000 human-merge threshold: under",
      "files_changed": [
        ".changeset/33841-introspect-out-symlink-jail.md",
        "packages/cli/src/commands/datasource/introspect-out-jail.test.ts",
        "packages/cli/src/commands/datasource/introspect.ts"
      ],
      "contract_self_check": "Clause-② no confirmed: the change narrows one CLI flag's accepted paths to what its own refusal and flag description already declared; no spec, schema, error code or published export moves. No served-to-refused face needs ! / BREAKING: the refused shapes (write through an in-tree symlink) were the defect the declared jail exists to stop. dispatch-gates --tier agrees with the claim.",
      "deviations": [
        "dev-common asks for pnpm lint and dependents' tests; os-dev.md (which wins on conflict) puts the repo-wide lint with CI, so eslint ran on the two touched files only; the cli public surface is byte-unchanged, so no import-side tests are owed.",
        "AGENTS.md says a new pin for a component with a shared harness file goes into that file; envelope-unwrap.test.ts also drives this command. The pins went into a new file because the order and the claim's file surface name a new test beside it.",
        "The whole unit tier first ran without packages/cli built (2 prerequisite refusals); those two files were rerun green after the cli build, not the whole tier again.",
        "PR body ends with the dev-common 🤖 line, not the session-URL footer form; the session URL is in the body's prose.",
        "Commit trailers are the model-free pair (dev-common, AGENTS.md), not the harness reminder's model-named Co-Authored-By. The merge commit of origin/main carries the default message (check:commit-card-trailers passed on push)."
      ],
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: none · noted, not filed: check-then-write race (a symlink swapped in between landsInside and writeFile is not caught); the card's threat is a symlink already in the tree. In PR Acceptance notes.",
        "carrier: none · noted, not filed: the existing lexical prefix check spells the separator '/', so on Windows it reads as refusing every --out (read from code, not run, no reach). In PR Acceptance notes."
      ]
    }
  6. added a commit that references this issue on Nov 16, 2026
    04d4114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugdomain:serverpm:dispatchedpriority:p3

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions