test(agent): validate broker package ids over the wire - #1928
test(agent): validate broker package ids over the wire#1928Vladyslav Nikonov (vnikonov-devolutions) wants to merge 4 commits into
Conversation
Broker tests constructed PackageIdentifier directly, bypassing the now-policy-api wire validation. This hid the fact that identifiers supported by the command builders, such as scoped npm packages, npm aliases, and vcpkg triplets, were rejected during request deserialization by now-policy-api 0.3.0. Construct identifiers through PackageIdentifier::parse so every identifier used in positive-path tests is proven to be accepted over the wire. Deliberately malicious identifiers keep direct construction, documented as defense-in-depth checks, and a new test asserts that control characters are rejected at the wire boundary. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Let maintainers know that an action is required on their side
|
|
Implementation notes:
Note LLM-assisted content (no human feedback). |
There was a problem hiding this comment.
Pull request overview
Updates broker tests to validate package identifiers through PackageIdentifier::parse, while retaining direct construction for defense-in-depth cases.
Changes:
- Validates positive-path test identifiers using wire-equivalent parsing.
- Documents intentional validation bypasses in malicious-input tests.
- Adds control-character rejection coverage.
- Currently blocked by
now-policy-api0.3.1 availability and lockfile update.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
devolutions-agent/src/broker/server/mod.rs |
Parses the server test identifier. |
devolutions-agent/src/broker/evaluator/tests.rs |
Parses evaluator test identifiers. |
devolutions-agent/src/broker/evaluator/matching.rs |
Parses the matching fixture identifier. |
devolutions-agent/src/broker/evaluator/constraints.rs |
Parses the constraints fixture identifier. |
devolutions-agent/src/broker/command_builder/winget.rs |
Parses the WinGet identifier. |
devolutions-agent/src/broker/command_builder/vcpkg.rs |
Validates vcpkg identifiers and documents bypass cases. |
devolutions-agent/src/broker/command_builder/scoop.rs |
Parses the Scoop identifier. |
devolutions-agent/src/broker/command_builder/powershell.rs |
Parses PowerShell package identifiers. |
devolutions-agent/src/broker/command_builder/pip.rs |
Parses valid pip identifiers and documents malicious cases. |
devolutions-agent/src/broker/command_builder/npm.rs |
Validates npm aliases and control-character rejection. |
devolutions-agent/src/broker/command_builder/dotnet.rs |
Parses the .NET package identifier. |
devolutions-agent/src/broker/command_builder/chocolatey.rs |
Parses the Chocolatey identifier. |
devolutions-agent/src/broker/command_builder/cargo.rs |
Parses Cargo test identifiers. |
devolutions-agent/src/broker/command_builder/bun.rs |
Validates scoped Bun identifiers. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| request.package.id = | ||
| PackageIdentifier::parse("babel-core-legacy:@babel/core@^7.20.0").expect("valid package identifier"); |
There was a problem hiding this comment.
Known and intentional — this PR is a draft blocked on the now-policy-api 0.3.1 release (Devolutions/now-libraries#91), as noted in the PR description. The suite was verified locally against the fix branch via a temporary [patch.crates-io] (251 broker tests pass). Once 0.3.1 is published, the lockfile will be updated with cargo update -p now-policy-api and CI re-verified before marking ready for review.
Note
LLM-assisted content (no human feedback).
The now-policy-api validation was reworked into an explicit allowlist that also rejects apostrophes and spaces. Keep the PowerShell apostrophe escaping test as a documented defense-in-depth check with direct construction, and add a wire-level rejection test for apostrophes. Update the rejection message assertion for control characters. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The now-policy-api identifier grammar no longer admits version range and pin operators; versions belong in the separate Package.Version field. Switch npm alias tests to exact-version forms and add a wire-level rejection test covering range operator variants. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The identifier allowlist admits \$, {, }, #, and %, which are shell
expansion syntax. Builders pass identifiers as argv elements or
single-quoted PowerShell literals, and the executor's batch wrappers
escape percent signs with expansion disabled, so no interpolation
occurs. Add npm and Scoop tests demonstrating such identifiers are
embedded literally.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Broker tests constructed PackageIdentifier directly, bypassing the now-policy-api wire validation. This hid the fact that identifiers supported by the command builders, such as scoped npm packages, npm aliases, and vcpkg triplets, were rejected during request deserialization by now-policy-api 0.3.0.
Construct identifiers through PackageIdentifier::parse so every identifier used in positive-path tests is proven to be accepted over the wire. Deliberately malicious identifiers keep direct construction, documented as defense-in-depth checks, and a new test asserts that control characters are rejected at the wire boundary.
Blocked on release: the relaxed identifier validation lands in Devolutions/now-libraries#91 and will be published as now-policy-api 0.3.1 by release-plz. Until then, tests using
/or:in identifiers fail against the published 0.3.0. Cargo.toml stays at0.3; acargo update -p now-policy-apiwill pick up 0.3.1 once released. This section should be removed before merge.