Skip to content

Tighten install script version guard to full semver#225

Merged
jeremy merged 4 commits into
mainfrom
install-semver-guard
Mar 10, 2026
Merged

Tighten install script version guard to full semver#225
jeremy merged 4 commits into
mainfrom
install-semver-guard

Conversation

@jeremy

@jeremy jeremy commented Mar 9, 2026

Copy link
Copy Markdown
Member

Summary

  • Tighten the version regex in both scripts/install.sh and scripts/ensure-basecamp.sh from ^[0-9]+\.[0-9]+ to ^[0-9]+\.[0-9]+\.[0-9]+
  • A partial version like 0.2 would have passed the old guard and produced a guaranteed-to-fail download URL

Follow-up to #223 — addresses post-merge review feedback.

Test plan

  • make check passes
  • curl -fsSL -o /dev/null -w '%{url_effective}' https://github.com/basecamp/basecamp-cli/releases/latest still resolves v0.2.3 correctly

Summary by cubic

Tightened version checks in the install scripts to require full semver (X.Y.Z) with anchored regex and clearer diagnostics. get_latest_version remains strict (stable tags only), while env-supplied versions can include prereleases like 1.2.3-rc.1.

  • Bug Fixes
    • Anchored latest-tag regex to ^[0-9]+\.[0-9]+\.[0-9]+$ in scripts/install.sh and scripts/ensure-basecamp.sh; error messages now include the resolved tag/URL.
    • Validated VERSION/BASECAMP_VERSION with ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ to reject partials/trailing junk and allow prereleases.
    • Verified latest release resolution still returns v0.2.3.

Written for commit d283885. Summary will update on new commits.

The regex only checked major.minor, so a partial version like "0.2"
would pass and produce a guaranteed-to-fail download URL. Require
all three components to fail fast with a clear error message.
Copilot AI review requested due to automatic review settings March 9, 2026 22:57
@jeremy jeremy requested a review from a team as a code owner March 9, 2026 22:57
@github-actions github-actions Bot added the bug Something isn't working label Mar 9, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Copilot AI 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.

Pull request overview

This PR tightens the “latest version” guard in the installer and ensure script to require a full MAJOR.MINOR.PATCH semver, preventing partial versions (e.g., 0.2) from being accepted and generating invalid release download URLs.

Changes:

  • Update version validation regex in scripts/install.sh to require X.Y.Z.
  • Apply the same regex tightening in scripts/ensure-basecamp.sh.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
scripts/install.sh Require full semver when extracting the latest release version from the GitHub redirect URL.
scripts/ensure-basecamp.sh Require full semver when determining the latest version during auto-install.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@claude claude 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.

LGTM — straightforward regex tightening, two identical one-line changes.

Extended reasoning...

Overview

This PR changes a single regex pattern in two shell scripts (scripts/install.sh and scripts/ensure-basecamp.sh), tightening the version validation from ^[0-9]+\.[0-9]+ to ^[0-9]+\.[0-9]+\.[0-9]+ to require full semver (X.Y.Z) instead of accepting partial versions (X.Y).

Security risks

None. The change strictly tightens input validation in install scripts. No new code paths, no relaxed checks, no changes to authentication, permissions, or data handling.

Level of scrutiny

Minimal scrutiny warranted. This is a two-line mechanical change following established patterns, with clear intent documented in the PR description as a follow-up to #223. The regex modification is correct and easy to verify by inspection.

Other factors

The bug report identifies a pre-existing gap where BASECAMP_VERSION env var bypasses validation entirely. This is explicitly a pre-existing issue not introduced by this PR — the old code also had no validation on that path. While it would be nice to fix in this PR, its absence does not block approval of the current change. The PR has a test plan and make check passes.

Comment thread scripts/install.sh Outdated
The env var path bypassed get_latest_version() and its semver guard,
allowing partial versions like 0.2 to produce broken download URLs.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/install.sh">

<violation number="1" location="scripts/install.sh:310">
P2: Regex is missing a `$` end-anchor, so values like `1.2.3garbage` pass validation and produce a broken download URL. Consider anchoring with `$` (or `(-|$)` if you want to allow pre-release suffixes like `1.2.3-rc.1`).</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread scripts/install.sh Outdated
Values like 1.2.3garbage would pass the unanchored regex and produce
broken download URLs.
Copilot AI review requested due to automatic review settings March 9, 2026 23:48

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/install.sh Outdated
Comment thread scripts/install.sh Outdated
Comment thread scripts/ensure-basecamp.sh Outdated

@claude claude 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.

LGTM — regex tightening is correct and the env var validation gap is now closed.

Extended reasoning...

Overview

This PR makes a small, targeted change to two shell scripts (scripts/install.sh and scripts/ensure-basecamp.sh), tightening a version regex from ^[0-9]+\.[0-9]+ to ^[0-9]+\.[0-9]+\.[0-9]+ so that partial version strings like 0.2 are rejected early instead of producing broken download URLs. A third hunk adds the same validation to the BASECAMP_VERSION env var code path in main(), addressing feedback from my previous review.

Security risks

None. The change strictly narrows input validation — it rejects more inputs, not fewer. There is no auth, crypto, or permissions code involved.

Level of scrutiny

Low scrutiny is appropriate. This is a three-line regex tightening in install/setup scripts, following an established pattern already present in the codebase. The intent is clear from the PR description and the diff is trivially verifiable.

Other factors

The author addressed the pre-existing gap I flagged in my previous review (the BASECAMP_VERSION env var bypass). The inline comment thread is resolved. No bugs were found by the automated bug hunting system. The change is a direct follow-up to PR #223 and the commit history confirms the progression.

- Include resolved tag/URL in error messages for debuggability
- Accept prerelease suffixes (e.g. 1.2.3-rc.1) in BASECAMP_VERSION env var
- Keep strict X.Y.Z for get_latest_version (GitHub latest is always stable)
@jeremy jeremy merged commit dd79bee into main Mar 10, 2026
25 checks passed
@jeremy jeremy deleted the install-semver-guard branch March 10, 2026 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants