Skip to content

feat(installer): enforce HTTPS-only, TLS 1.2+ and a redirect cap on every curl in install.sh - #212

Merged
nc9 merged 2 commits into
mainfrom
feat/165-install-sh-curl-tls
Sep 6, 2026
Merged

nc9 merged 2 commits into
mainfrom
feat/165-install-sh-curl-tls

Conversation

@nc9

@nc9 nc9 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Closes #165

Summary

curl follows a redirect from https to plain http by default and negotiates whatever TLS version the local build still allows. The downloaded binary is checksum-verified against the manifest, but the release-metadata fetches and the bash re-exec have nothing behind them but the transport itself.

Every curl the script runs now carries --proto '=https' --proto-redir '=https' --tlsv1.2 --max-redirs 3, held in one CURL_TLS_ARGS array: fetch_with_retry, both fetches in get_latest_version, and the failure-report POST in report_error. --proto and --proto-redir are separate settings and one does not imply the other, so the initial scheme and every redirect hop are pinned independently. The POSIX-sh re-exec at the top of the script repeats the flags inline, because it runs under /bin/sh above the bash-only preamble that defines the array.

install.ps1 is untouched: the sibling issue #166 is covered by #207.

Tests

scripts/install-contract.test.ts grows a static scan that fails on any curl call site which neither spells the flags out nor inherits them from CURL_TLS_ARGS, plus runtime tests that drive fetch_with_retry, get_latest_version (both the R2 endpoint and the GitHub API fallback) and report_error against a curl test double, which is what proves the flags reach a real argv rather than only the source text. One further test hands the flag set to the real curl against a closed loopback port, so a typo like --tlsv.1.2 cannot pass the suite.

Two existing report_error tests move from a plaintext loopback server to that same double. --proto '=https' refuses http, and a TLS stand-in would need a CA the child curl trusts, which the SecureTransport curl macOS ships does not read from CURL_CA_BUNDLE; that would have passed in CI and failed on half the development machines. Their payload assertions are unchanged, now read off the recorded --data.

Verification

Acceptance criteria, each checked:

Criterion Evidence
every curl refuses non-HTTPS, including after a redirect 5 call sites, all carrying --proto '=https' --proto-redir '=https'; the scan fails if one does not
every curl enforces TLS 1.2 minimum same 5 sites carry --tlsv1.2; the real curl accepts it
redirects capped at 3 same 5 sites carry --max-redirs 3; real release assets take exactly 1 hop
the one-liner still installs on macOS and Linux (glibc and musl) end-to-end installs below
bash -n install.sh                                  # clean
shellcheck install.sh                               # clean (2 pre-existing SC2016 notices on awk programs)
bun test scripts/install-contract.test.ts           # 53 pass, 0 fail
detect-secrets-hook --baseline .secrets.baseline …  # clean, baseline unchanged
bun run lint && bun run format:check                # clean

End-to-end installs, all exit 0 and the installed binary reports 0.0.90:

  • macOS arm64, both bash install.sh and the piped cat install.sh | bash form
  • ubuntu:24.04 (glibc, curl 8.5.0/OpenSSL) as a non-root test user
  • alpine:latest (musl, curl 8.22.0/OpenSSL) as a non-root test user
  • both POSIX-sh handoff branches under dash: piped (takes the hardened curl | bash re-exec) and dash /install.sh (takes exec bash "$0")

Redirect depth against the real endpoints under the hardened flags, confirming the cap of 3 is not tight:

URL redirects
install.squirrelscan.com/releases/stable 0
install.squirrelscan.com/install.sh 0
api.github.com/repos/…/releases 0
release manifest and all three binaries 1

Mutation-tested: seven separate mutations each turn the suite red, including dropping a flag from the array, dropping the array reference at each of the four bash call sites, unhardening the sh re-exec, adding an unhardened path-qualified curl, and typoing a flag name.

Reviewed

An adversarial review pass produced the second commit: the scan was letting five shapes of unhardened curl through, the harness could parse a half-written record, and it spread the ambient environment into the child, which put a GITHUB_TOKEN into an argv that a failing assertion would print. All fixed, with the scan's blind spots now pinned as their own test cases.

Two follow-ups found in the same pass are deliberately out of scope here: npm/scripts/postinstall.js follows redirects by unbounded recursion with no cap (filed as #213), and install.ps1 has the same gap (#166 / #207).

Not covered

test-install.yml does not gate this PR: it is workflow_call/workflow_dispatch only, and it fetches install.sh from main on raw.githubusercontent.com rather than from the tree under test. The platform matrix above was run by hand instead.

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

nc9 added 2 commits September 7, 2026 09:02
…very curl

curl follows a redirect from https to plain http by default and negotiates
whatever TLS version the local build still allows. The downloaded binary is
checksum-verified against the manifest, but the release-metadata fetches and
the bash re-exec have nothing behind them but the transport itself.

Every curl the script runs now carries --proto '=https' --proto-redir '=https'
--tlsv1.2 --max-redirs 3, held in one CURL_TLS_ARGS array: fetch_with_retry,
both fetches in get_latest_version, and the failure-report POST. --proto and
--proto-redir are separate settings and one does not imply the other, so the
initial scheme and every redirect hop are pinned independently. The POSIX-sh
re-exec at the top repeats the flags inline because it runs above the
bash-only preamble that defines the array. All four options predate curl 7.34
(2013), below every platform we support.

The contract test grows a scan that fails on any curl call site which neither
spells the flags out nor inherits them from CURL_TLS_ARGS, pinned to the five
sites that exist so a refactor hiding one cannot pass vacuously. It also
drives fetch_with_retry, get_latest_version (both the R2 endpoint and the
GitHub API fallback) and report_error against a curl test double, which is
what proves the flags reach a real argv rather than only the source text.

The two report_error tests move from a plaintext loopback server to that same
double: --proto '=https' refuses http, and a TLS stand-in would need a CA the
child curl trusts, which the SecureTransport curl macOS ships does not read
from CURL_CA_BUNDLE. That would have passed in CI and failed on half the
development machines.

Closes #165

Signed-off-by: Nik Cubrilovic <[email protected]>
… test

Review of the first commit found the scan and the harness weaker than they
looked, and two comments saying things that are not true.

The scan let five shapes of unhardened curl through, each confirmed against a
crafted script: a path-qualified `/usr/bin/curl`, a second curl on a line whose
first one is hardened, a curl after a `command -v curl` probe on the same line,
a curl on a line that merely mentions a hardened array, and an array whose
later assignment drops the flags. It now walks every match on a line, judges
each on the text from its own curl onward, scopes the probe skip to the match
instead of the whole line, and requires every assignment of an argv array to
qualify. The four call-site shapes are pinned as their own cases.

The harness shimmed curl everywhere, so a typo like `--tlsv.1.2` would have
passed the whole suite and every other pre-merge gate: `bash -n` does not know
curl's option names, and the install-test workflow runs only on release and
fetches install.sh from main rather than from the tree under test. One test now
hands the real flag set to the real curl against a closed loopback port.

Also: the settle loop accepted a half-written record, so a slow detached POST
could parse as an argv with no --data; it now waits for the record separator,
and the shim writes the whole record through a single redirect. The harness
spread the ambient environment into the child, which put a GITHUB_TOKEN into
get_latest_version's auth header and therefore into the argv that a failing
expect() prints, so it now clears that and the endpoint seams. The third
detached-POST test was missing the 15s budget its two siblings carry.

The comment claiming all four options predate curl 7.34 was wrong: --tlsv1.2
landed in 7.34. The comment offering SQUIRREL_ERROR_ENDPOINT as a test seam no
longer holds either, since curl now refuses a plain-http override.

Closes #165

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the feat/165-install-sh-curl-tls branch from 6332822 to 1d5ab86 Compare September 6, 2026 23:02
@nc9
nc9 merged commit 3aa2e2d into main Sep 6, 2026
13 checks passed
@nc9
nc9 deleted the feat/165-install-sh-curl-tls branch September 6, 2026 23:08
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): enforce HTTPS-only, TLS 1.2+ and a redirect cap on every curl in install.sh

1 participant