Skip to content

fix(installer): validate release metadata - #912

Merged
nc9 merged 3 commits into
squirrelscan:mainfrom
WilliamK112:codex/installer-metadata-validation-167
Oct 24, 2026
Merged

nc9 merged 3 commits into
squirrelscan:mainfrom
WilliamK112:codex/installer-metadata-validation-167

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Summary

  • validate release versions and asset filenames before constructing download URLs
  • reject malformed SHA-256 values from release manifests
  • normalize expected and computed checksums before comparing them in both installers
  • add shell and PowerShell contract coverage for accepted and rejected metadata

Testing

  • bash -n install.sh
  • bun test scripts/install-contract.test.ts (131 passed, 1 skipped)
  • bun test scripts/install-contract.test.ts --test-name-pattern "release metadata validation" (13 passed)
  • PowerShell contract execution deferred to CI because pwsh is not installed locally

Closes #167

@WilliamK112
WilliamK112 requested a review from nc9 as a code owner October 17, 2026 05:23
@nc9

nc9 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Thanks, this is close. The filename and SHA-256 guards and the case-insensitive comparison look right in both scripts. One change and one small hardening are needed.

1. The version pattern is looser than the CLI's, and lets a dot segment through. ^v?[0-9A-Za-z.-]+$ accepts . and ... A metadata version of .. therefore builds https://github.com/squirrelscan/squirrelscan/releases/download/../<asset>, which is the retargeting #167 is about. The comment says the guard is aligned with apps/cli/src/self/releases.ts, but the CLI validates versions with isValidReleaseVersion (apps/cli/src/self/paths.ts). That function requires canonical SemVer, so criterion 4 is not met yet.

Please use that pattern, with the tag's optional leading v. In install.sh, POSIX ERE has no \d, and keeping the pattern in a variable avoids bash quoting surprises:

valid_release_version() {
  local re='^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$'
  [[ "$1" =~ $re ]]
}

Use the same pattern in install.ps1. Please also add rejection cases for ., .. and v.. to both contract tests, next to the existing ../v1.2.3 case.

2. In PowerShell, $ also matches before a trailing newline. .NET's $ matches at the end of the string or just before a final \n, so a filename that ends in a newline passes -cmatch '^...$'. Please anchor the three PowerShell patterns with \z instead of $. Bash =~ and the JavaScript patterns are fine as they are.

@WilliamK112

Copy link
Copy Markdown
Contributor Author

Addressed both review items and merged current main. The Bash and PowerShell version guards now mirror the CLI canonical SemVer pattern with an optional leading v; the contract suites reject ., .., and v... All three PowerShell metadata regexes now use the absolute \z anchor, with trailing-newline regressions for version, filename, and SHA-256. Validation: bash syntax, 135 installer contract tests (1 platform skip), repository format check, and lint all pass locally; the PowerShell contract will run in CI.

@nc9

nc9 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Thanks, this matches #167: version, filename and sha256 are validated before any URL is built or binary downloaded, a bad manifest fails closed, and the new tests fail when install.sh is reverted. I could not find a bypass (trailing newline, CR, fullwidth digits, V1.2.3, empty). Two small things before merge: please rebase on main (the branch is behind) and add a ### Fixed line under ## [Unreleased] in CHANGELOG.md, for example "install.sh and install.ps1 validate the release version, asset filename and sha256 from release metadata before building download URLs (#167)". Optional: tests for the non-jq json_get_nested path and a trailing-newline case on the bash side.

@WilliamK112
WilliamK112 force-pushed the codex/installer-metadata-validation-167 branch from 0271ba4 to f46eac0 Compare October 22, 2026 18:24
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Rebased onto current main in f46eac0 and added the requested Unreleased ### Fixed changelog entry. I also added the optional Bash trailing-newline rejection case. Validation: the full install contract file passes (136 pass, 1 environment skip), and the focused release-metadata subset passes 18/18 after the rebase.

@WilliamK112
WilliamK112 force-pushed the codex/installer-metadata-validation-167 branch 4 times, most recently from d608579 to 6b341be Compare October 24, 2026 05:46
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Rebased again onto current main (9b30d8e) and resolved the new CHANGELOG overlap by retaining both the upstream robots.txt entry and this installer metadata entry. The branch is now based directly on current main; git diff --check and bash -n install.sh pass, and all three rebased commits retain their Signed-off-by trailers.

@WilliamK112
WilliamK112 force-pushed the codex/installer-metadata-validation-167 branch from 6b341be to 5f6d433 Compare October 24, 2026 06:00
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Follow-up: main advanced once more during the completed green CI run with the version-only Actions bump in #1099. I rebased cleanly onto c1fb9b3; the new head is 5f6d433. No source or changelog conflict occurred, diff/shell syntax checks still pass, and sign-off trailers are intact.

@WilliamK112
WilliamK112 force-pushed the codex/installer-metadata-validation-167 branch from 5f6d433 to 14629b8 Compare October 24, 2026 06:14
@WilliamK112

WilliamK112 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Final validation update: rebased onto current main at 37554dc; final head is 9b13552. All three commits are patch-equivalent to the reviewed implementation, git diff --check and bash -n install.sh pass, and every commit retains its Signed-off-by trailer.

The complete GitHub Actions suite is green on this head, including installer syntax and contract coverage, CLI tests, formatting/lint/typecheck, dependency audit, release tooling, secret scan, CodeQL, and DCO verification. GitHub reports the PR mergeable and clean.

@WilliamK112
WilliamK112 force-pushed the codex/installer-metadata-validation-167 branch 6 times, most recently from 9b13552 to 3025415 Compare October 24, 2026 13:57
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Rebased once more onto current main at 18065a3; the new head is 3025415. All three commits are patch-equivalent by git range-diff, git diff --check and bash -n install.sh pass, and all DCO trailers remain intact. Fresh CI is running.

@nc9
nc9 force-pushed the codex/installer-metadata-validation-167 branch from 3025415 to ebde05a Compare October 24, 2026 20:43
@nc9
nc9 merged commit 89ce4f2 into squirrelscan:main Oct 24, 2026
15 checks passed
@nc9

nc9 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Merged. Thank you @WilliamK112, rejecting dot, dot-dot and trailing-newline versions in both installers with contract tests for the shell and PowerShell sides is the careful kind of hardening an installer needs. (Nik)

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): validate manifest-derived version, filename and sha256 before building URLs

2 participants