Skip to content

fix(#8575)!: harden and tidy the .env-as-data launch loader - #8591

Merged
waynesun09 merged 6 commits into
mainfrom
agent/8575-harden-env-data-loader
Oct 20, 2026
Merged

waynesun09 merged 6 commits into
mainfrom
agent/8575-harden-env-data-loader

Conversation

@fullsend-ai-coder

@fullsend-ai-coder fullsend-ai-coder Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hardens and tidies the launch loader that reads the agent-writable .env as data (internal/runtime/env_data.go). These are the follow-ups from the #8565 reviews: loader fixes, the missing tests, and doc and comment corrections.

Related Issue

Follow-ups from #8565 / #8498. Two items are left for a maintainer decision (see below), so this PR does not close the issue.

Changes

Loader (env_data.go, binary_pin.go)

  • NUL values: a value containing a NUL byte is dropped with a warning naming the file and line. Before, it was dropped silently at output time.
  • Unreadable .env.d: a directory that exists but can't be listed (or whose entries can't be stat'ed, e.g. mode 000 or 0644) now records the error in failed and fails the launch, the same as an unreadable .env.d file already does. A missing directory is still read as empty.
  • Multi-line rejection resync: a rejected statement whose quotes span lines is skipped to where a shell would end it (quote- and comment-aware), so lines inside its value are no longer parsed as assignments. An unterminated quote still falls back to the line end.
  • python3 pin: the launch first records FULLSEND_TRUSTED_PATH: the launch PATH without relative entries, each entry recorded as its physical directory (cd -P), and without any directory the agent user owns or can write (checking every directory above it too). It then pins the first python3 on that PATH whose resolved file, and every directory above it, passes the same check, resolving symlinks with the first readlink on that PATH that is a regular file the agent user neither owns nor can write, run with only that PATH. The resolved path is pinned. With no such python3 (or readlink) the launch stops with exit 127 and says why. As root the PATH is used unchanged. FULLSEND_TRUSTED_PATH is read-only and never taken from .env.
  • FULLSEND_RUNNER_PATH: the loader script now takes the name from envDataRunnerPathVar (Go constant concatenation) instead of hardcoding it. The tautological test that only kept the two in step is removed.

Tests

  • -I behaviour test: a planted re/ package in the working directory and on PYTHONPATH is not imported.
  • LD_*, BASH_ENV and ENV set from .env.d, iteration.env, and via a separate export NAME line are all dropped.
  • NUL values, resync, unreadable .env.d, and the python3 pin (agent-writable and agent-owned PATH directories, relative and empty entries, a symlinked readlink, a symlinked PATH entry, a readlink that looks up a helper on PATH, and the exit-127 path). All fail on the old loader.
  • TestBuildPiRunCommand_LoaderEnvHygieneRuns runs the built pi launch under /bin/sh with a stub pi. Positive controls prove the .env, .env.d and iteration.env reads ran.
  • TestEnvDataControlLinesMatchRunner checks each control line exactly, and checks that the runner writes them in order, without indexing into harnessEnvLines().
  • TestClaudeLaunch_RefusesHooksChangedBetweenIterations skips when /bin/sh rejects unset -f [ (bash 3.2 on macOS).
  • Codex golden launch files regenerated. The only diff is the pin and the script.

Docs and comments

  • docs/runtimes/claude.md: the image needs python3 on every Claude run.
  • docs/runtimes/codex.md and the ADR 0100 implementation note: the launch evals [export ]NAME='value' lines, not only export lines. This is a minor wording fix to an implementation note on an Accepted ADR; Context, Decision and Consequences are untouched.
  • docs/reference/harness-reference.md and customizing-agents.md list the shell forms the loader drops (${NAME:-default}, export A=1 B=2, FOO=x; export FOO, NUL values), and note that an unreadable .env.d fails the launch. This follows triage's suggested default of documenting these forms rather than supporting them.
  • Stale "before/after . .env" comments in claude.go, pi_run.go and binary_pin.go updated, plus the envDataLoad comment.

Already done on main (no change needed): path escaping in warnings (%r, with an existing test), envDataRunnerPathVar inside the const block with a doc comment, and runtime-implementation.md listing PYTHON*.

Not done here; left for a maintainer decision:

  • Limiting $NAME expansion to names .env defines plus HOME/PATH: existing .env.d files that reference other launch variables (e.g. $SSL_CERT_FILE) would silently get empty values.
  • Denylist vs allowlist: the reserved plugin-env set in plugin_spec.go also covers PATH, HOME, GIT_* and *_TOKEN, which .env legitimately sets, so aligning the two needs its own design.
  • macOS: TestBuildRunCommand_GatewayReadonlyIgnored gets no skip. Its launch on main only runs unset -f claude (no [), so the bash-3.2 cause does not apply. The likely macOS failure is command -p flock in the gateway credential seed.

Breaking change

A non-root sandbox launch now needs python3 and a regular-file readlink in PATH directories the sandbox user neither owns nor can write (a virtualenv or a $HOME-managed interpreter does not count). Without them the launch exits 127 with python3 not found in a PATH directory the agent cannot write. The fullsend sandbox image meets this. A custom image whose only python3 or readlink lives in a sandbox-owned directory, or whose readlink is a symlink (BusyBox-style), needs a root-owned python3 and coreutils readlink on PATH.

Testing

  • Re-validated after the pin rework: go test ./internal/runtime/... ./internal/security/... as a non-root user on Linux (Debian, /bin/sh = dash; the earlier pin commits also on Fedora 44, /bin/sh = bash 5), and the pin fragment run in the fleet sandbox image as sandbox (pins /usr/bin/python3.12, leaves the sandbox-owned venv bin off the trusted PATH, exits 127 when no other directory is on PATH).
  • go test ./internal/runtime/... ./internal/cli/... pass, except tests that fail on main in this sandbox too: TestBuildRunCommand_ClaudeMissingExits127 (a real claude is in /usr/bin here), TestStartFetchService_* and TestPostScriptEnv_NoSchema*.
  • Tests added/updated for new or modified logic
  • make lint: pre-commit could not fetch its remote hook repos (TLS failure in the sandbox). gofmt, go vet ./..., the ADR status/number/frontmatter lints, broken-symlinks, docs-links, lychee and whitespace checks were run directly and pass; gitlint passes on the commit.

Checklist

  • PR title follows Conventional Commits (correct type, ! for breaking changes)
  • Commits are signed off (DCO): not applicable, autonomous agent commit
  • I wrote this contribution myself and can explain all changes in it

🤖 Generated with Claude Code


Related to #8575

Post-script verification

  • Branch is not main/master (agent/8575-harden-env-data-loader)
  • Secret scan passed (gitleaks — 5fc4c47a1d40c2ab0a748e3bd2f7b9f8a697ca50..HEAD)
  • PR body secret scan passed (gitleaks — no-git)

Follow-ups from the #8565 reviews of the loader that reads the
agent-writable .env as data (internal/runtime/env_data.go).

Loader:
- A value containing a NUL byte is dropped with a warning naming
  the file and line, like every other dropped line, instead of
  silently at output time.
- An .env.d directory that exists but cannot be listed (or whose
  files cannot be stat'ed) now records the error and fails the
  launch, as an unreadable .env.d file already did; a missing
  directory is still read as empty.
- A rejected statement whose quotes span lines is skipped to where
  a shell would end it, so lines inside its value are no longer
  parsed as assignments. An unterminated quote still falls back to
  the line end.
- python3 is pinned with `command -p -v python3` first, falling
  back to `command -v python3`, so a python3 early on the launch
  PATH is not used when the default PATH has one (new
  binaryPinLookup helper).
- The loader script takes FULLSEND_RUNNER_PATH from
  envDataRunnerPathVar instead of spelling it out.

Tests: a planted re/ package in the working directory and on
PYTHONPATH is not imported; LD_*, BASH_ENV and ENV from .env.d,
iteration.env and a separate `export NAME` line are dropped; NUL
values; the built pi launch run end to end with a stub pi; the
control-lines test no longer depends on harnessEnvLines()[0]; the
Claude hooks launch test skips where /bin/sh rejects `unset -f [`
(bash 3.2 on macOS). Codex golden launch files regenerated.

Docs: claude.md says the image needs python3; codex.md, the ADR
0100 implementation note and the envDataLoad comment no longer say
only `export` lines are evaluated; the harness reference lists the
shell forms the loader drops (${NAME:-default}, export A=1 B=2,
FOO=x; export FOO); stale `. .env` comments in claude.go and
pi_run.go updated.

Not done here: limiting $NAME expansion and replacing the drop
denylist with an allowlist both change what existing .env.d files
get and need a maintainer design decision.

Note: pre-commit could not fetch its remote hook repos (TLS
failure in the sandbox); gofmt, go vet, the ADR lints, broken
symlinks, docs-links, lychee and whitespace checks were run
directly and pass. Unrelated tests that fail on main in this
sandbox too: TestBuildRunCommand_ClaudeMissingExits127 (a real
claude is in /usr/bin), TestStartFetchService_* and
TestPostScriptEnv_NoSchema* in internal/cli.

Related to #8575

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 9:46 PM UTC · Completed 9:58 PM UTC

Commit: 058a8ab · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.51

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Site preview

Preview: https://05576bb2-site.fullsend-ai.workers.dev

Commit: ea2b8d9e722f58ee45426482023416e96cf2d5e7

@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Oct 19, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Moderate risk: the PR modifies existing launch behavior without a feature flag across 19 files in an area of recent churn, but closely matches the linked hardening issue and touches no protected or security-sensitive paths.

Previous run

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Moderate risk: the PR modifies existing launch behavior without a feature flag across 18 files in an area of recent churn, but closely matches the linked hardening issue and touches no protected or security-sensitive paths.

Previous run (2)

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Moderate risk: the PR modifies existing launch behavior without a feature flag across 17 files in an area of recent churn, but closely matches the linked hardening issue and touches no protected or security-sensitive paths.

Previous run (3)

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Moderate risk: the PR modifies existing launch behavior without a feature flag across 17 files in an area of recent churn, but closely matches the linked hardening issue and touches no protected or security-sensitive paths.

@fullsend-ai-review

fullsend-ai-review Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review

Findings

Low

  • [logic-error] internal/runtime/env_data.go:337 — A rejected NUL-containing assignment can still change whether an earlier value is exported. For example, A=private followed by export A='x<NUL>y' warns and preserves private, but statement() then adds A to exported, so the earlier shell-local value is exported to the CLI. The rejected statement is not fully dropped.
    Remediation: Have assign report whether it accepted the assignment and update exported only on success; add a regression test with a plain assignment followed by a rejected NUL-containing export.

Earlier findings

  • f_3fc74796de25479f — resolved_by_change: docs/contributing/runtime-implementation.md:888 now says "the .env load (envDataLoad)" instead of . .env.
Previous run

<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJjb21tZW50IiwiZmluZGluZ3MiOlt7InNldmVyaXR5IjoibWVkaXVtIiwiY2F0ZWdvcnkiOiJpbmplY3Rpb24tdnVsbiIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmX2ZhYTU5NTBmZmZiYjViZmMiLCJsaW5lIjoxMzQsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJsb2dpYy1lcnJvciIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmXzdiZWVhMTY1YjI4M2Q0YjQiLCJsaW5lIjozMTgsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJsb2dpYy1lcnJvciIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmXzViYzc5ZGM1YTk1ZjVjN2QiLCJsaW5lIjoyOTMsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJzdGFsZS1kb2MiLCJmaWxlIjoiZG9jcy9jb250cmlidXRpbmcvcnVudGltZS1pbXBsZW1lbnRhdGlvbi5tZCIsImlkIjoiZl8zZmM3NDc5NmRlMjU0NzlmIiwibGluZSI6ODg4LCJhY3Rpb25hYmxlIjpmYWxzZX0seyJzZXZlcml0eSI6ImxvdyIsImNhdGVnb3J5IjoibWlzbGVhZGluZy1sYWJlbCIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmX2E5NDA3NzVkY2MyMTU1YjIiLCJsaW5lIjoxMjAsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJsb2dpYy1lcnJvciIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmX2QwNmZhODFjOGU4ZTkzNTAiLCJsaW5lIjoyNTQsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJpbmplY3Rpb24tdnVsbiIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmXzU4NTI4YjRlNDgwZTUzNTIiLCJsaW5lIjoxMDUsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJsb2dpYy1lcnJvciIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmXzA0ZmU3MTg0N2ZiMzRkODYiLCJsaW5lIjoyNDgsImFjdGlvbmFibGUiOnRydWV9XSwiZGlzcG9zaXRpb25zIjpbeyJpZCI6ImZfN2JlZWExNjViMjgzZDRiNCIsInN0YXR1cyI6Im9wZW4ifSx7ImlkIjoiZl8zZmM3NDc5NmRlMjU0NzlmIiwic3RhdHVzIjoib3BlbiJ9LHsiaWQiOiJmX2QwNmZhODFjOGU4ZTkzNTAiLCJzdGF0dXMiOiJkaXNtaXNzZWRfYnlfaHVtYW4ifSx7ImlkIjoiZl81ODUyOGI0ZTQ4MGU1MzUyIiwic3RhdHVzIjoiZGlzbWlzc2VkX2J5X2h1bWFuIn0seyJpZCI6ImZfMDRmZTcxODQ3ZmIzNGQ4NiIsInN0YXR1cyI6InJlc29sdmVkX2J5X2NoYW5nZSJ9XX0= -->

Review

Findings

Medium

  • [injection-vuln] internal/runtime/env_data.go:134 — The interpreter pin runs readlink from FULLSEND_TRUSTED_PATH without validating it. The trusted-PATH filter checks only the directory and its ancestors, and the resolved-target check covers only python3. A protected PATH directory holding readlink -> <agent-writable file> would pass the filter, and the agent-controlled helper would run at launch before python validation. This needs an image-builder-placed symlink, so it is a defense-in-depth gap rather than a demonstrated exploit.
    Remediation: Resolve and validate the readlink helper and its symlink targets before running it, or use a trusted, immutable helper path from the image. Add a non-root regression fixture for it.

Low

  • [logic-error] internal/runtime/env_data.go:318 (f_7beea165b283d4b4) — A rejected NUL-containing export FOO="a\0b" still marks an earlier non-exported FOO=old as exported, because taken(name) stays true after assign() rejects the value. Still present at head.
    Remediation: Have assign() report acceptance and update exported only for accepted assignments. Add a regression test.
  • [logic-error] internal/runtime/env_data.go:293 — skip_statement() recognizes # comments only when its stack is empty and does not track backticks. In X=$(printf x # )\nexport INNER=1\n), the ) inside the comment ends the skip and INNER is taken from inside the rejected substitution. A multiline backtick substitution behaves the same way. The effect is limited to taking NAME=value lines as data; nothing runs as shell.
    Remediation: Track backtick boundaries and comments inside command substitutions. Add regression cases for both.
  • [stale-doc] docs/contributing/runtime-implementation.md:888 (f_3fc74796de25479f) — Still says the NODE_OPTIONS/NODE_PATH/JITI_* unset is emitted right after . .env. pi launches read .env as data via envDataLoad, and this PR updated the matching pi_run.go comment.
    Remediation: Change the wording to "immediately after the .env read (envDataLoad)".
  • [misleading-label] internal/runtime/env_data.go:120 — The PR description and first commit message still describe the python3 pin as command -p -v python3 || command -v python3 with a new binaryPinLookup. The last three commits replaced that with a trusted-PATH filter (FULLSEND_TRUSTED_PATH, readlink -f resolution, new exit-127 messages) and removed binaryPinLookup.
    Remediation: Update the PR description to describe the trusted-PATH pin.
Previous run (2)

<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJhcHByb3ZlIiwiZmluZGluZ3MiOlt7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJsb2dpYy1lcnJvciIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmX2QwNmZhODFjOGU4ZTkzNTAiLCJsaW5lIjoyNTQsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJsb2dpYy1lcnJvciIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmXzdiZWVhMTY1YjI4M2Q0YjQiLCJsaW5lIjoyODUsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJpbmplY3Rpb24tdnVsbiIsImZpbGUiOiJpbnRlcm5hbC9ydW50aW1lL2Vudl9kYXRhLmdvIiwiaWQiOiJmXzU4NTI4YjRlNDgwZTUzNTIiLCJsaW5lIjoxMDUsImFjdGlvbmFibGUiOmZhbHNlfSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJzdGFsZS1kb2MiLCJmaWxlIjoiZG9jcy9jb250cmlidXRpbmcvcnVudGltZS1pbXBsZW1lbnRhdGlvbi5tZCIsImlkIjoiZl8zZmM3NDc5NmRlMjU0NzlmIiwibGluZSI6ODg4LCJhY3Rpb25hYmxlIjpmYWxzZX0seyJzZXZlcml0eSI6ImxvdyIsImNhdGVnb3J5IjoibG9naWMtZXJyb3IiLCJmaWxlIjoiaW50ZXJuYWwvcnVudGltZS9lbnZfZGF0YS5nbyIsImlkIjoiZl8wNGZlNzE4NDdmYjM0ZDg2IiwibGluZSI6MjQ4LCJhY3Rpb25hYmxlIjp0cnVlfV0sImRpc3Bvc2l0aW9ucyI6W3siaWQiOiJmXzA0ZmU3MTg0N2ZiMzRkODYiLCJzdGF0dXMiOiJyZXNvbHZlZF9ieV9jaGFuZ2UifSx7ImlkIjoiZl8zZmM3NDc5NmRlMjU0NzlmIiwic3RhdHVzIjoib3BlbiJ9XX0= -->

Review

Findings

Low

  • [logic-error] internal/runtime/env_data.go:254 — skip_statement loses the surrounding double-quote context inside ${...}. In export X="${UNSET:-'a followed by lines and }", the apostrophe is literal in a shell, but the scanner opens a single-quote frame, never closes it, and falls back to the first line end. Lines inside the rejected value (e.g. export INNER=1) are then parsed as assignments. Backtick substitutions are not tracked either. Nothing from .env is executed; this is a fidelity gap in the rejection resync.
    Remediation: keep the enclosing quote context when scanning parameter expansions, track backticks, and add regression tests.
  • [logic-error] internal/runtime/env_data.go:285 — a rejected NUL-valued assignment still marks the name as exported. With A=previous followed by export A='x<NUL>y', assign() drops the new value but statement() still calls exported.add(name), so the earlier value is exported. TestEnvDataLoad_NulValueWarns uses export A=ok first, so it cannot catch this.
    Remediation: have assign() report success and set the export attribute only on success; add a test.
  • [injection-vuln] internal/runtime/env_data.go:105 — the python3 pin falls back to command -v python3 on the launch PATH when the default PATH has no python3. On a custom image with python3 only off the default PATH and an agent-writable directory ahead on the launch PATH, a planted python3 would run before cleanup. This narrows the previous behavior (launch PATH only), and the CLI pins already trust the launch PATH. It is a residual, pre-existing exposure.
    Remediation: resolve and retain the trusted interpreter during Bootstrap, or fail when the default PATH has none.
  • [stale-doc] docs/contributing/runtime-implementation.md:888 — still says the pi unset runs "right after . .env", while the PR updates the matching pi_run.go comment to say the .env read (envDataLoad). (Carried from the prior review.)
    Remediation: refer to the .env read (envDataLoad) instead of . .env.

Earlier findings

  • f_04fe71847fb34d86 — resolved_by_change: skip_statement now tracks nested ', ", ${, $( frames in a stack, and the test adds a nested-quote case (V="${UNSET:-"a ... }").
Previous run (3)

<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJyZXF1ZXN0LWNoYW5nZXMiLCJmaW5kaW5ncyI6W3sic2V2ZXJpdHkiOiJsb3ciLCJjYXRlZ29yeSI6ImxvZ2ljLWVycm9yIiwiZmlsZSI6ImludGVybmFsL3J1bnRpbWUvZW52X2RhdGEuZ28iLCJpZCI6ImZfMDRmZTcxODQ3ZmIzNGQ4NiIsImxpbmUiOjI0OCwiYWN0aW9uYWJsZSI6dHJ1ZX0seyJzZXZlcml0eSI6ImxvdyIsImNhdGVnb3J5Ijoic3RhbGUtZG9jIiwiZmlsZSI6ImRvY3MvY29udHJpYnV0aW5nL3J1bnRpbWUtaW1wbGVtZW50YXRpb24ubWQiLCJpZCI6ImZfM2ZjNzQ3OTZkZTI1NDc5ZiIsImxpbmUiOjg4OCwiYWN0aW9uYWJsZSI6ZmFsc2V9XX0= -->

Review

Findings

Low

  • [logic-error] internal/runtime/env_data.go:248 — skip_statement (the multi-line rejection resync added here) treats any unescaped " inside a double-quoted context as closing it, without tracking nested ${...}/$(...). For export X="${UNSET:-"a\nexport INSIDE=1\n"}" the rejected value is cut at the inner quote and export INSIDE=1 is then loaded as an independent assignment. Impact is limited: assign() still applies the denylist, readonly names and NUL check, and an agent that can write .env can already set any non-denylisted variable directly. The resync fix is incomplete for nested quoting only.
    Remediation: Track nested ${/$( depth in skip_statement, or conservatively skip to EOF with a warning when a quote appears inside an unclosed expansion. Add a regression case next to TestEnvDataLoad_RejectedMultiLineStatementSkippedWhole.
  • [stale-doc] docs/contributing/runtime-implementation.md:888 — Lines 888/895 ("right after . .env", "a function a rewritten .env defined cannot stand in for it") and 724, 727, 755, 1343, 1368 ("sourced") still describe .env as sourced, though it has been read as data via envDataLoad since fix(#8498)!: read the agent-writable .env as data at launch #8565. This predates the PR and the file is not in the diff, but the PR rewrites the matching comments in pi_run.go and claude.go. Advisory; could go in a Harden and tidy the .env-as-data launch loader (follow-ups from #8565) #8575 follow-up.
    Remediation: Update the cited passages to describe .env as read as data.

Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Finished Fix · ✅ Success · Started 10:00 PM UTC · Completed 10:06 PM UTC

Commit: 058a8ab · View workflow run →

Runtime: claude · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.41

…tement

skip_statement closed a double-quoted value at the first inner quote, even
inside ${...} or $(...), so a rejected multi-line statement could resync
inside its own value and load a later line as an assignment. Track a stack
of quote/expansion contexts instead. Regression case added next to
TestEnvDataLoad_RejectedMultiLineStatementSkippedWhole; its first case is
made well-formed (closing brace). Golden launch scripts regenerated.

Addresses review feedback on PR #8591.
Not changed: the docs/contributing/runtime-implementation.md 'sourced'
wording (advisory, pre-existing, outside this PR's diff).
Notes: pre-commit could not fetch hook repos (TLS failure); gofmt, go vet and
git diff --check were run directly. TestBuildRunCommand_ClaudeMissingExits127
fails in this sandbox on the base commit too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@fullsend-ai-coder

Copy link
Copy Markdown
Contributor Author

🔧 Fix agent — iteration 1 (bot-triggered)

Fixed the nested-quote resync gap in skip_statement with a regression test and regenerated golden files. Left the advisory stale-doc finding for a follow-up because it is pre-existing and outside this PR's diff.

Fixed (1):

  1. skip_statement closes a double-quoted value at an inner quote inside a nested expansion, so a rejected multi-line statement resyncs inside its own value (internal/runtime/env_data.go): Rewrote skip_statement to track a stack of quote and expansion contexts (single quote, double quote, ${...}, $(...)), so quotes inside an expansion no longer close the outer value. Added a nested-quote regression case to TestEnvDataLoad_RejectedMultiLineStatementSkippedWhole and made its first case well-formed (added the missing closing brace). Regenerated the four codex golden launch scripts that embed the loader.

Disagreed (1):

  1. docs/contributing/runtime-implementation.md still describes .env as sourced in several passages: The reviewer marked this advisory and non-actionable: the wording predates this PR, the file is not in the diff, and the reviewer suggested a follow-up. Editing it here would expand scope beyond the review fix.

Tests: passed

CI inspections (6):

  1. test (passing, success): Passed on the PR head before this fix.
  2. build (passing, success): Passed on the PR head before this fix.
  3. codecov/patch (passing, success): Patch coverage passed before this fix.
  4. commit-lint (passing, success): Passed on the PR head before this fix.
  5. behaviour (passing, success): Passed on the PR head before this fix.
  6. playback (passing, success): Passed on the PR head before this fix.
Decision points
  • How to handle quotes nested inside an expansion when skipping a rejected statement (alternatives: Skip to end of file when a quote appears inside an unclosed expansion, Track nested expansion and quote contexts like a shell; rationale: Tracking nesting keeps later valid assignments loadable while still keeping the nested value from being read as separate lines. Unterminated input still falls back to the line end, as before.)

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push
    Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:08 PM UTC · Completed 10:17 PM UTC

Commit: 77a3ad6 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.90

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-review fullsend-ai-review Bot added the ready-for-merge All reviewers approved — ready to merge label Oct 19, 2026
@waynesun09

Copy link
Copy Markdown
Member

/fs-fix-stop

@github-actions github-actions Bot added the fullsend-no-fix Skip bot-triggered fix agent runs label Oct 19, 2026
@github-actions

Copy link
Copy Markdown

Fix agent disabled for this PR. Remove the fullsend-no-fix label or use /fs-fix to re-engage.

The loader's python3 pin looked on the system default PATH first and fell
back to the launch PATH. Pin it from a trusted PATH instead: before .env is
read, the launch records the PATH without any directory the agent user can
write (or that has a writable ancestor) and without relative entries, and
takes the first python3 there whose resolved file and parent directories
the agent cannot write either, so a protected bin directory holding a
symlink to an agent-owned interpreter is skipped. The resolved path is
pinned; with none the launch stops with exit 127. Under root nothing could
be protected, so the PATH is kept as is.

Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 11:31 PM UTC · Completed 11:44 PM UTC

Commit: b948029 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.44

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-review
fullsend-ai-review Bot dismissed their stale review October 19, 2026 23:44

Superseded by updated review

@fullsend-ai-review fullsend-ai-review Bot added requires-manual-review Review requires human judgment and removed ready-for-merge All reviewers approved — ready to merge labels Oct 19, 2026
The interpreter lookup resolved python3 with the first readlink on the
trusted PATH, and a protected directory can still hold a readlink that
links into a directory the agent user writes. Take the first readlink
on the trusted PATH that is a regular file the agent user neither owns
nor can write, and run it with only the trusted PATH. A symlink is
refused, because its target's directories cannot be checked without
running something first. Without one, the launch says so and stops with
the python3 message (exit 127).

Record each trusted PATH entry as its physical directory (cd -P), so a
symlinked entry is judged by the directories it really lives in, and
leave out one whose physical path holds a colon, which would split.

Document the readlink requirement next to the python3 one, and update
two stale lines in the runtime implementation guide.

BREAKING CHANGE: a non-root sandbox launch now needs python3 and a
regular-file readlink in PATH directories the sandbox user neither owns
nor can write (a virtualenv or a $HOME-managed interpreter does not
count). Without them the launch exits 127 with "python3 not found in a
PATH directory the agent cannot write". The fullsend sandbox image meets
this; a custom image whose only python3 or readlink lives in a
sandbox-owned directory, or whose readlink is a symlink (BusyBox-style),
needs a root-owned python3 and coreutils readlink on PATH.

Assisted-by: Claude (fix), Codex (review)
Signed-off-by: Wayne Sun <gsun@redhat.com>
@waynesun09 waynesun09 changed the title fix(#8575): harden and tidy the .env-as-data launch loader fix(#8575)!: harden and tidy the .env-as-data launch loader Oct 20, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 4:03 AM UTC · Completed 4:14 AM UTC

Commit: ea2b8d9 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.78

@fullsend-ai-review fullsend-ai-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The following review comments could not be posted on the diff (GitHub returned 422) and are included here instead:

  • internal/runtime/env_data.go (file-level): Line 337 ·
    [low] logic-error

A rejected NUL-containing assignment can still change whether an earlier value is exported. For example, A=private followed by export A='x<NUL>y' warns and preserves private, but statement() then adds A to exported, so the earlier shell-local value is exported to the CLI. The rejected statement is not fully dropped.

Suggested fix: Have assign report whether it accepted the assignment and update exported only on success; add a regression test with a plain assignment followed by a rejected NUL-containing export.

@fullsend-ai-review fullsend-ai-review Bot added ready-for-merge All reviewers approved — ready to merge and removed requires-manual-review Review requires human judgment labels Oct 20, 2026

@waynesun09 waynesun09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated on Linux (non-root, dash) and in the sandbox image; bot approved ea2b8d9, checks green. Remaining LOWs tracked in #8604.

@waynesun09
waynesun09 added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit ec73130 Oct 20, 2026
102 checks passed
@waynesun09
waynesun09 deleted the agent/8575-harden-env-data-loader branch October 20, 2026 04:44
gklein pushed a commit to gklein/fullsend that referenced this pull request Oct 21, 2026
…usted PATH

The claude, codex, pi and OpenCode launches found their CLI with a bare
`command -v` on the launch PATH. A sandbox image can put a directory
the agent user owns first on PATH, so the launch could start a CLI the
agent planted there. pi's CLI and codex's npm launcher start with
`#!/usr/bin/env node`, so their node was looked up on whatever PATH the
launch shell had after .env was read.

Since fullsend-ai#8591 the loader's python3 follows a stricter rule, and the CLI
pins now follow it too:

- envDataBinaryPin generalises the python3 lookup. It takes the first
  name on FULLSEND_TRUSTED_PATH, resolves it with the pinned readlink,
  walks the resolved path for agent-writable or agent-owned ancestors,
  and pins the resolved path read-only. With none it exits 127 with
  "fullsend: <cli> not found in a PATH directory the agent cannot
  write". As root it takes the first match.
- envDataTrustedPin records FULLSEND_TRUSTED_PATH and a new read-only
  FULLSEND_READLINK once per launch. binaryPin runs it before the CLI
  pin, and envDataLoad now pins only python3, so no launch runs a
  second `readonly` of the same name (which aborts dash). EnvDataLoad
  and the codex and OpenCode env-read probes, which have no CLI pin,
  run envDataTrustedPin themselves.
- binaryPin reads the pinned CLI's first line with the `read` builtin.
  For `#!/usr/bin/env node` it pins node by the same rule, and the
  launch runs `"$NODE" "$CLI"` (cliLaunch); otherwise the node pin is
  empty and the CLI starts as before. The PATH the CLI and its tools
  inherit is unchanged. The new FULLSEND_<RUNTIME>_NODE pins are on
  each launch's .env drop list, like the other pins.

Tests run the pins under /bin/sh and dash as a non-root user. An
agent-writable CLI or node earlier on PATH is not pinned, a protected
symlink into an agent-writable directory is refused, and with no
qualifying file the launch exits 127. Replacing the trusted-PATH
lookup with `command -v` fails all 24 of those subtests. Existing
launch tests mark their stub directories protected through a `test`
shell function, as env_data_test.go already does. The codex goldens
are regenerated. The runtime docs state the new requirement.

Note: `pre-commit run` could not fetch its remote hook repositories
in the sandbox (TLS failure). The local hooks (gofmt, go vet,
broken-symlinks, docs-links, lychee) and the pre-commit-hooks v6.0.0
hooks were run directly and passed. gitleaks was covered by
scan-secrets.

BREAKING CHANGE: a custom sandbox image whose claude, codex, pi or
opencode CLI, or the node that runs a `#!/usr/bin/env node` CLI, is
found only through a PATH directory the sandbox user owns or can write
(or through a symlink into one) now fails the launch with exit 127.
Install the CLI and node in a directory the sandbox user cannot write.

Closes fullsend-ai#8626

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active and 1 inactive deployments
site-preview — ea2b8d9e Deployed Oct 20, 2026 by github-actions[bot]
dev — ea2b8d9e Deployed Oct 20, 2026 by waynesun09 via playback #17249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fullsend-no-fix Skip bot-triggered fix agent runs ready-for-merge All reviewers approved — ready to merge ready-for-review Triggers review agent dispatch risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant