Skip to content

fix(install): describe automatic setup and guard truncated downloads - #1902

Merged
morluto merged 3 commits into
morluto:mainfrom
larinyo:pr/install-script-hardening
Oct 11, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
larinyo:pr/install-script-hardening

Conversation

@larinyo

@larinyo larinyo commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes two problems in install.sh:

  1. The --help text says the installer only installs the CLI and that rea setup must be run separately. In fact, the installer starts rea setup interactively whenever a terminal is available.
  2. The script runs top to bottom as it streams through curl … | bash. If the download is cut off, bash runs a partial script.

Problem and expected behavior

  • Truncation trigger: the connection drops right after the npm install line. Bash then runs a prefix of the installer with whatever state that prefix leaves behind.
  • New behavior: the whole body is wrapped in main(), and main "$@" is the last line. A truncated download no longer parses, so nothing runs. The help text now describes the automatic interactive rea setup and the --no-setup/--no-prompt opt-outs.

Change and scope

  • install.sh: the main wrapper (the diff is mostly re-indentation) and the help text. Behavior is otherwise unchanged.
  • tests/boundary/filesystem/installScript.test.ts: a new scenario runs a copy truncated right after the npm install line. It requires that the copy prints nothing and never invokes npm.

Contract and boundary impact

  • Semantic owner and earliest changed stage: installer script.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: same supported platforms.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Process execution, authorization, cleanup, or containment impact: a partial download never executes.
  • Generated metadata, package, or installation impact: installer only. docs/user-visible-errors.csv messages are unchanged.

Evidence and regression coverage

  • Tests added or updated: the truncated-download scenario.
  • Base reproduction: with the base install.sh in place, the new test fails (× runs nothing from a download truncated after the npm install line; 1 failed, 28 passed). With this change, all 29 pass.

Validation performed

  • bash -n install.sh: OK.
  • npx vitest run tests/boundary/filesystem/installScript.test.ts: 29 passed. Against the base script: 1 failed, as expected.
  • npx tsc --noEmit: clean. npx oxlint: 0 errors. npm run verify:module-boundaries: passed. npm run format: no changes.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real OS coverage: the installer was not run end to end on macOS or a real Linux distribution here. The boundary tests use stubs.
  • Package or release metadata impact: none.
  • Security review: this hardens the curl | bash path against partial execution.

Limits / not verified

  • shellcheck was not available on this host for this rebase. It was run (0.10.0, clean) on the same change when it was originally written.
  • npm run verify:package was not run.

The help text said the installer only installs the CLI and that
`rea setup` must be run separately, but the installer starts
`rea setup` interactively whenever a terminal is available. Describe
that behaviour and the --no-setup/--no-prompt opt-out.

Wrap the installer body in `main` and call it on the last line, so a
truncated `curl | bash` download fails to parse instead of executing a
partial script. Behaviour is otherwise unchanged.

Add an installer scenario that runs a copy truncated right after the
npm install line and requires that it prints nothing and never invokes
npm; it fails against the previous script.

Validation: bash -n, shellcheck 0.10.0, installScript boundary tests.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T17:55:58.898945Z 677cad7 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e7d0605853

ℹ️ 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".

Comment thread install.sh
fi
}

main "$@"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the final invocation incomplete until the last byte

If the piped download is cut off immediately after the bytes main (or its following space) on this last line, Bash sees a syntactically complete command at EOF and runs the parsed function with no positional parameters. In the documented bash -s -- --dry-run/--version/--no-setup path this silently discards the caller's flags, so a supposed dry run can resolve the latest release, invoke npm, and potentially start setup—the partial-execution condition this wrapper is meant to prevent. Put the call inside a compound construct whose closing token must arrive before execution, and cover truncations of this tail as well.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Cutting the old script off right after main made a bash -s -- --dry-run run go ahead and invoke npm install; I reproduced this locally. 4d92e65 replaces the last line with a brace group ({, main "$@", exit $?, }, each on its own line) and adds a comment explaining why. Bash won't run the group until it reads the closing brace, so any truncation inside it is a parse error. A new boundary test pipes the script to bash -s -- --dry-run, cutting it at every byte offset from the end of main() to EOF. It asserts that npm and the installed binary are never invoked and that offsets inside the group exit non-zero with no stdout. bash -n and shellcheck 0.11.0 are clean.

Wrapping the installer in main() kept a truncated download from running
a partial body, but the last line was a bare `main "$@"`. If the piped
download stopped right after `main` (or `main `), bash saw a complete
command at EOF and ran main with no positional parameters. Under the
documented `curl ... | bash -s -- --dry-run` (or --version / --no-setup)
path that silently dropped the caller's flags, so a dry run could resolve
the latest release, run npm, and start setup.

The call now sits in a brace group:

  {
    main "$@"
    exit $?
  }

Bash does not run the group until it has read the closing brace, so
every truncation inside it is a syntax error and nothing executes; a
truncation before the group leaves only function definitions. A comment
in install.sh records why the bare call is not enough.

Validation: a new boundary test pipes install.sh to `bash -s --
--dry-run` truncated at every byte offset from the end of main() to EOF
and asserts that npm and the rea binary are never invoked; offsets
inside the group must exit non-zero with a bash parse error and no
stdout, offsets before it must print nothing, and the complete group
must finish the dry run. Reproduced the original bug by cutting the old
script after `main`: the dry run invoked npm install. `bash -n` and
shellcheck 0.11.0 are clean.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d92e65479

ℹ️ 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".

Comment thread install.sh Outdated
# `main` would be a complete command at EOF and run main without the caller's
# flags (so `bash -s -- --dry-run` could install). Inside this group, every
# truncation before the closing brace is a syntax error and nothing runs.
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Start the truncation guard before the preamble

On the documented curl ... | bash path (docs/installation.md:50), this brace is opened only after the top-level set -euo pipefail has already been streamed. If the transfer stops immediately after the bytes set, Bash reaches EOF with a valid no-argument builtin; Bash's help set states that when no arguments are given, all shell variables are printed, so inherited tokens can be emitted to stdout before this guard is ever seen. Start the incomplete compound command before line 2 and include preamble byte cutoffs in the truncation test.

AGENTS.md reference: AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 677cad7. A { now opens on line 2, right after the shebang, and the matching } is the last line. Everything in between, from set -euo pipefail through the final main "$@" / exit $?, sits inside that one group, so a download cut off after the bytes set is a syntax error and never a bare set. The truncation test now pipes every prefix of install.sh (byte 0 to EOF, about 6,100 cuts) into bash -s -- --dry-run with a minimal environment. For each cut it asserts empty stdout, no npm or rea invocation, a syntax error once the group is open, and a dry run only for the complete file. shellcheck 0.11.0 and bash -n are clean, and I checked by hand that set -e/-u still take effect inside the group.

The previous guard only wrapped the final `main "$@"` invocation, so the
preamble streamed on the `curl ... | bash` path before any incomplete
compound command was open. A download cut off right after the bytes
`set` reached EOF with a complete, argument-less `set`, which prints every
shell variable, so inherited tokens could reach stdout.

The brace group now opens on line 2, directly after the shebang, and
closes on the last line, enclosing `set -euo pipefail`, the constants, the
functions and the final `main "$@"` / `exit $?`. Bash must therefore read
the whole file before running anything; any earlier cut is a syntax error
at EOF. `set -euo pipefail` still applies inside the group (checked
manually for `false`, an unbound variable, and a failing function body),
and shellcheck 0.11.0 and `bash -n` are clean.

The truncation test now pipes every prefix of install.sh, from byte 0 to
EOF (about 6,100 cuts, run 16 at a time with a minimal environment that
includes a sentinel variable), into `bash -s -- --dry-run`. Before the
group opens it must exit quietly; inside the group it must fail with a
syntax error; in every case stdout stays empty and neither npm nor rea is
invoked. Only the complete script performs the dry run.
@morluto
morluto merged commit d802304 into morluto:main Oct 11, 2026
31 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: setup Setup, packaging, upgrade, install, Doctor, and client registration labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants