Skip to content

fix: validate version argument with semver regex to prevent URL injection (closes #75)#152

Merged
s2x merged 3 commits into
mainfrom
fix/issue-75-version-validation
Jul 6, 2026
Merged

fix: validate version argument with semver regex to prevent URL injection (closes #75)#152
s2x merged 3 commits into
mainfrom
fix/issue-75-version-validation

Conversation

@s2x

@s2x s2x commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #75

The CLI installer (bin/zvec-install) and Installer::install() accepted arbitrary version strings without validation. A crafted argument like ../../other/repo/v1.0.0 could manipulate the download URL structure.

Changes

  • Added preg_match validation with semver regex in both bin/zvec-install (CLI entry point) and Installer::install() (programmatic path)
  • CLI path: writes to STDERR and exits with code 1 on invalid version
  • Programmatic path: throws RuntimeException with descriptive message
  • Regex accepts standard semver with optional pre-release suffixes (v0.5.0-alpha1, v0.4.0-rc.2)
  • Regex rejects: path traversal, incomplete semver, empty strings, URL-unsafe characters (+), trailing dots/hyphens

Testing

  • Added tests/test_installer_version_validation.phpt - 15 test cases
    • 4 valid versions: v0.4.0, v1.2.3, v0.5.0-alpha1, v0.4.0-rc.2
    • 11 invalid versions: path traversal, incomplete semver, empty string, slashes, null bytes, just text, trailing dot/hyphen, plus sign
  • All existing installer tests continue to pass (7/10 pass; 3 pre-existing platform-specific failures)

Code Review

  • Passed subagent code review (2 rounds)
  • All review comments addressed (regex strictness, redundant null coalescing, additional test cases)

Files Changed

  • bin/zvec-install - version validation before Installer::install() call
  • src/Installer.php - version validation in install() before URL construction
  • tests/test_installer_version_validation.phpt - new test file
  • CHANGELOG.md - entry under Security section

@s2x s2x self-assigned this Jul 3, 2026
Piotr Hałas added 3 commits July 4, 2026 00:07
…tion (closes #75)

- Add preg_match validation in bin/zvec-install for CLI entry point
- Add preg_match validation in Installer::install() for programmatic path
- Reject path traversal, incomplete semver, empty strings, and URL-unsafe characters
- Accept standard semver with optional pre-release suffixes (e.g. v0.5.0-alpha1)
- Add tests/test_installer_version_validation.phpt with 12 test cases
- Fix regex to reject trailing dots/hyphens (require word char at end)
- Remove redundant ?? operator in bin/zvec-install
- Add test cases for trailing dot, hyphen, double hyphen
@s2x
s2x force-pushed the fix/issue-75-version-validation branch from cf51e52 to e79a1b4 Compare July 3, 2026 22:13
@s2x s2x changed the title fix: validate version argument with semver regex in CLI installer (closes #75) fix: validate version argument with semver regex to prevent URL injection (closes #75) Jul 3, 2026
@s2x
s2x merged commit 7e2e0db into main Jul 6, 2026
3 checks passed
@s2x
s2x deleted the fix/issue-75-version-validation branch July 6, 2026 19:00
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.

SEC-007: Version Argument Not Validated in CLI Installer

1 participant