Skip to content

Add input parameter validation for --source and --minionversion on Windows and Linux#64

Merged
twangboy merged 5 commits into
mainfrom
input_validation
May 8, 2026
Merged

Add input parameter validation for --source and --minionversion on Windows and Linux#64
twangboy merged 5 commits into
mainfrom
input_validation

Conversation

@twangboy
Copy link
Copy Markdown
Contributor

@twangboy twangboy commented May 7, 2026

Neither svtminion.ps1 nor svtminion.sh validated the --source or --minionversion parameters before use. Both values reached
wget/curl/path operations unvalidated, and on Windows they reached Invoke-WebRequest and file system calls. This PR adds
explicit validation to both scripts, with consistent exit code 126 on failure — matching the existing Administrator privilege
check behavior.

Windows (windows/svtminion.ps1)

• Adds Test-SourceParameter: rejects empty values, control characters, shell injection characters ( ; & | < > ), and values that don't match a recognised scheme (HTTP/S, FTP, UNC, or local drive path). Uses [System.Uri]::TryCreate` for URL structural validation.
• Adds Test-MinionVersionParameter: validates against the Salt CalVer pattern (latest, 3006, 3006.2, 3008.0rc1, etc.).
• Adds control-character filtering to _parse_config to guard against YAML injection via key=value config options.
• Both validators are called after script initialisation but before Main, so they run in all production paths and are skipped during test imports.
• Parameter comments for -Source and -MinionVersion updated to document the exit 126 behaviour.

Linux (linux/svtminion.sh)

• Adds _validate_source_param: same checks as Windows adapted to bash — control characters via [[:cntrl:]], injection characters via grep -qE, and scheme-specific structural checks (HTTP/S/FTP, absolute path, file://).
• Adds _validate_minion_version_param: same CalVer regex as Windows expressed as a bash ERE.
• Both functions call _error_log on failure, which exits 126 consistently with all other error handling in the script.
• Both validators are called in the MAIN section immediately before _source_fn and _set_install_minion_version_fn.
• --help output updated to note that invalid values exit with code 126.

Tests

• tests/windows/functional/test_input_validation.ps1 — 32 table-driven unit test cases covering valid, invalid, and edge-case inputs for both validators.
• tests/windows/functional/test_parse_config.ps1 — extended with a test for control-character rejection in _parse_config.
• tests/windows/integration/test_input_validation.ps1 — 5 integration tests invoking svtminion.ps1 as a subprocess and asserting exit code 126 for invalid inputs.
• tests/linux/test-linux.sh — 5 integration test cases added (URL with space, unknown scheme, semicolon injection, version with space, version with semicolon), each asserting exit code 126.

Test plan

• Run powershell.exe -file tests\windows\runtests.ps1 -path tests\windows\functional\test_input_validation.ps1 — all cases
pass
• Run powershell.exe -file tests\windows\runtests.ps1 -path tests\windows\functional\test_parse_config.ps1 — all cases pass
• Run powershell.exe -file tests\windows\runtests.ps1 -path tests\windows\integration\test_input_validation.ps1 — all 5
integration cases exit 126
• Run Linux CI pipeline — new test-linux.sh validation cases pass before any install tests

twangboy added 5 commits May 7, 2026 15:15
Windows: Validate the Source and MinionVersion parameters early in the script
(after the test-mode guard, before Main) so malformed or potentially malicious
values are rejected with exit code 126 before any network or filesystem
activity occurs.
- Test-SourceParameter: rejects whitespace, control characters, and
  shell-injection characters; validates URL structure via System.Uri for
  HTTP/HTTPS/FTP; enforces UNC and local path format
- Test-MinionVersionParameter: validates against the known Salt CalVer
  format (latest, YYYY, YYYY.N, YYYY.N.N, YYYY.NrcN)
- _parse_config: skips any key or value containing a control character
  to prevent YAML injection via ConfigOptions
- Functional tests cover valid and invalid cases for both validators and
  the control-character config guard; integration tests verify exit
  code 126 end-to-end via subprocess invocation
Adds _validate_source_param and _validate_minion_version_param helper
functions to linux/svtminion.sh, mirroring the Windows validation added
in 681125a. Both functions exit 126 via _error_log on invalid input,
consistent with all other error handling in the script. Adds 5
integration test cases to tests/linux/test-linux.sh covering URL spaces,
unknown schemes, injection characters, and malformed version strings.
Changing SOURCE_PARAMS and MINION_VERSION_PARAMS from "$*" to "$1" in
the argument parser ensures the validators receive only the user-supplied
value, not the full remaining argument list. This allows
_validate_source_param to correctly detect spaces in HTTP/S/FTP URLs
rather than silently truncating to the first word. Removes the cut
workaround from both validator functions since the value is now
unambiguous.
Pre-3005 Linux Salt packages used a -N build suffix in their version
strings. The CalVer regex only allowed rc suffixes, causing
_validate_minion_version_param to reject 3004.2-1 and 3003.3-1 with
exit 126 and breaking existing CI tests that rely on those versions
defaulting to latest. Adds (-[0-9]+) as an alternative to (rc[0-9]+)
in the Linux validator only — Windows packages were not released with
this suffix format.
@twangboy twangboy self-assigned this May 8, 2026
Copy link
Copy Markdown

@PaTHml PaTHml left a comment

Choose a reason for hiding this comment

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

LGTM

@twangboy twangboy merged commit 9de8d22 into main May 8, 2026
24 checks passed
@twangboy twangboy deleted the input_validation branch May 8, 2026 20:58
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.

2 participants