Skip to content

fix(installer): install.sh umask, size check, signal traps, bin dir and HOME guards, noexec fallback #168 - #1416

Closed
nc9 wants to merge 1 commit into
mainfrom
fix/install-sh-hardening-168
Closed

nc9 wants to merge 1 commit into
mainfrom
fix/install-sh-hardening-168

Conversation

@nc9

@nc9 nc9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Closes #168 (part of #164).

All six items, in install.sh, with a new end to end test file that runs the whole installer against a shimmed curl, uname, mktemp and chmod and a fake release binary, in a throwaway HOME and TMPDIR.

  1. umask. Tightened to at least 022 before anything is created (umask OR 022, so a stricter 077 is kept, not loosened). Tested with an inherited 0000 (bin dir and binary not group or world writable, the binary itself runs under 022) and with 0077 (kept).
  2. Size check. The manifest's size (jq, or a new json_get_nested_number for the grep fallback) is compared with the downloaded byte count before the checksum: Size mismatch: the download is N bytes, the release manifest says M. A manifest with no size, or one that is not a whole number, skips it (older releases).
  3. Signal traps. (A download is waited on by polling kill -0 then wait: a plain wait lost a second signal on stock macOS bash 3.2 and left the installer spinning. A signal is the user stopping the run, so no failure report is sent, which keeps Ctrl-C out of the installer worker's alerts; private #3703 tracks the worker side.) INT, TERM and HUP exit 130, 143 and 129 through the existing EXIT trap, which now also names the cause in the report. Tested for all three with the whole process group signalled mid-download (as a terminal does): the exit code, no temp directory left, and the failure report POST naming download_binary. The download runs in the background and is waited on, so a signal sent to the installer PID alone is handled at once and the curl child is killed. (SIGINT already behaved on this shell; TERM and HUP fail on the old script.)
  4. Bin dir guard. SQUIRREL_BIN_DIR that is only whitespace or lexically resolves to / (/, //, /., /.., /usr/..) aborts before anything is downloaded. An empty value still means "not set" (a CI step with an empty variable should not start failing); documented.
  5. HOME guard. Unset or empty HOME stops with "HOME is not set" (needed even when SQUIRREL_BIN_DIR is set; message, docs and test now say so) and how to fix it, not HOME: unbound variable.
  6. noexec. The binary runs through run_self_install; exit 126 with "Permission denied" is the shell failing to exec, so the installer stages the binary under ~/.squirrel/tmp/install.XXXXXX and retries once, cleaning that directory on exit. If that also fails it stops with a message naming noexec, the two directories and TMPDIR= as the way out, reported under its own step self_install_noexec. Detection is exit 126 with a non-executable file, not the English text, so it works in any locale. If the staging dir cannot be created the message says that (step self_install_stage), not noexec. A binary that fails for another reason (exit 3) is not mistaken for it.

Tests: scripts/install-hardening-168.test.ts (36; at least 16 fail on the previous install.sh), two source-text assertions in scripts/install-contract.test.ts updated for run_self_install (139 pass), install-path-setup (29 pass). bash -n and shellcheck -S warning clean. Docs: a "What the installer protects" section in docs/quickstart.mdx and the SQUIRREL_BIN_DIR row. CHANGELOG under Unreleased / Changed. Skill: no change needed.

nik

Known and not done: the grep fallback for the manifest size reads 1.5e9 as 1; a failed copy into the staging directory is reported as the noexec cause; a signal in the first ~100 ms, before the traps are installed, can leave a 0-byte temp file and sends no report; a symlink to / is not followed by the SQUIRREL_BIN_DIR check (the docs say names, not links); the tests do not pin the ! -x half of the noexec check or that detection ignores the language.

@nc9
nc9 force-pushed the fix/install-sh-hardening-168 branch 4 times, most recently from af08676 to e0a6589 Compare October 31, 2026 13:42
…nd HOME guards, noexec temp fallback #168

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/install-sh-hardening-168 branch from e0a6589 to c09c5e6 Compare October 31, 2026 19:47
@nc9 nc9 mentioned this pull request Oct 31, 2026
@nc9

nc9 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

@nc9 nc9 closed this Oct 31, 2026
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.

feat(installer): install.sh runtime hardening (umask, size check, signal traps, bin-dir and HOME guards, noexec tmp)

2 participants