Repository navigation
fix(sccm): harden server intake boundaries - #434
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe SCCM server intake parser now supports bounded opaque extensions, future roles, validated provenance, payload hashing, multiple text encodings, duplicate-field detection, metadata limits, and expanded scenario coverage. ChangesSCCM server intake
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Manifest
participant IntakePreflight
participant ArtifactNormalizer
participant PayloadDecoder
Manifest->>IntakePreflight: manifest bytes and metadata
IntakePreflight->>ArtifactNormalizer: validated declarations and extensions
ArtifactNormalizer->>PayloadDecoder: payload bytes and encoding
PayloadDecoder->>ArtifactNormalizer: decoded evidence and SHA-256 metadata
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
|
Exact reviewed head: Please review the complete seven-commit range, especially opaque extension admission, future-role coverage remaining inert across every state, manifest/topology/artifact error scope, path privacy, payload/limit coherence, and deterministic collision/rotation handling. A fresh independent executable review is GO; no merge will occur until hosted review is complete at this exact head. @coderabbitai review @github-copilot review |
|
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Pull request overview
This PR hardens the SCCM Server intake contract in cmtraceopen-parser by tightening resource boundaries, validating privacy-safe forward-compatible fields (opaque extensions / future roles), and expanding adversarial fixture coverage to ensure deterministic, conservative behavior under malformed or hostile manifests/payloads.
Changes:
- Added manifest/payload bounding and stricter metadata validation, including opaque v1 extension retention and “opaque future role” handling in server intake.
- Expanded server intake tests/fixtures to cover duplicate fields, malformed metadata scoping, encoding behaviors, collision safety, and deterministic output under reordering.
- Promoted
sha2to a non-dev dependency to support payload hashing in production intake.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs | Adds bounded intake limits, opaque extension preflight/normalization, future-role tolerance rules, payload decoding, and payload SHA-256 provenance. |
| crates/cmtraceopen-parser/tests/sccm_server_intake.rs | Adds extensive adversarial/intake-contract tests and deterministic assertions across scenarios. |
| crates/cmtraceopen-parser/tests/fixtures/sccm/server/intake/unsorted-manifest/expected.json | Updates expected contract to assert deterministic evidence IDs. |
| crates/cmtraceopen-parser/tests/fixtures/sccm/server/intake/collision-same-basename-configured-roots/expected.json | Tightens collision expectations and asserts relativePath + sha256 provenance. |
| crates/cmtraceopen-parser/Cargo.toml | Moves sha2 into runtime dependencies for production intake hashing. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (9)
crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs (6)
777-781: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename
synthetic_unclassified; it is not gated onsynthetic_fixture.
synthetic_unclassifiedonly testsproducer_role == SccmRole::Unknown("unclassified"). It does not readsynthetic_fixture. The testserver_intake_accepts_only_opaque_future_unsupported_provenancebuilds a production manifest throughbounded_manifestand relies on this flag, so the production path is intentional.The current name states the opposite. It also feeds the topology-observation bypass at Line 816, where the reader must know that production manifests reach that branch.
♻️ Proposed rename
- let synthetic_unclassified = - artifact.producer_role == SccmRole::Unknown("unclassified".to_owned()); + // The literal `unclassified` role is accepted in both synthetic and production manifests. + let unclassified_role = + artifact.producer_role == SccmRole::Unknown("unclassified".to_owned()); let opaque_future_role = !synthetic_fixture && is_opaque_future_role(&artifact.producer_role); - let retained_unknown = opaque_future_role - || (synthetic_unclassified && artifact.capture_state == SccmCoverageState::Unsupported); + let retained_unknown = opaque_future_role + || (unclassified_role && artifact.capture_state == SccmCoverageState::Unsupported);Update the two remaining uses at Lines 816 accordingly.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs` around lines 777 - 781, Rename synthetic_unclassified to reflect that it detects the unclassified producer role regardless of synthetic_fixture, and update both remaining references in the topology-observation bypass around the associated intake logic. Preserve the existing condition and behavior for production manifests and synthetic fixtures.
117-125: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReport a version mismatch with a distinct error.
validatereturnsInvalidNamewhenschema_version != 1. The name can be fully valid in that case. The publicSccmServerOpaqueExtensionErrorthen misreports the cause to callers, and the deserialization error text is misleading.Add a dedicated variant, or at minimum split the condition.
♻️ Proposed refactor
pub enum SccmServerOpaqueExtensionError { #[error("opaque extension name is invalid or unsafe")] InvalidName, #[error("opaque extension value is invalid or unsafe")] InvalidValue, + #[error("opaque extension schema version is unsupported")] + UnsupportedSchemaVersion, }fn validate(&self) -> Result<(), SccmServerOpaqueExtensionError> { - if self.schema_version != 1 || !safe_opaque_extension_name(&self.name) { + if self.schema_version != 1 { + return Err(SccmServerOpaqueExtensionError::UnsupportedSchemaVersion); + } + if !safe_opaque_extension_name(&self.name) { return Err(SccmServerOpaqueExtensionError::InvalidName); }Note:
opaque_extension_public_construction_and_serde_are_validatedonly assertsis_err()for theschemaVersion: 2case, so this change does not break the test.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs` around lines 117 - 125, Update SccmServerOpaqueExtensionError and validate so schema_version != 1 produces a distinct version-mismatch error instead of InvalidName; keep safe_opaque_extension_name validation mapped to InvalidName and preserve the existing value validation behavior.
1557-1574: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueThe synthetic branch in
safe_source_idis unreachable.
"unknown-db-supplement"already appears in the unconditionalmatches!list at Line 1567. Whensynthetic_fixtureis true and the value is"unknown-db-supplement", the first clause returnstrueand theallow_unknownbranch never runs. The branch cannot change any result.The redundancy suggests that synthetic retained-unknown sources are restricted to that one literal. They are not; the literal is accepted for every artifact in every manifest. Remove the dead arm so the real contract is visible.
♻️ Proposed simplification
| "unknown-db-supplement" - ) || (allow_unknown - && if synthetic_fixture { - value == "unknown-db-supplement" - } else { - opaque_sha256_handle(value, "cmtraceopen.source.sha256.v1:") - }) + ) || (allow_unknown + && !synthetic_fixture + && opaque_sha256_handle(value, "cmtraceopen.source.sha256.v1:")) }This mirrors the shape already used by
safe_source_kindat Lines 1580-1582. Confirm thatserver_intake_retains_unsupported_source_provenanceandserver_intake_rejects_unversioned_future_unsupported_source_labelsstill pass, since both drive this function.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs` around lines 1557 - 1574, Remove the synthetic_fixture conditional from safe_source_id because its only accepted value is already handled by the unconditional matches! list, making that branch unreachable. Keep allow_unknown behavior for non-synthetic values using opaque_sha256_handle, and verify the existing provenance and future-label tests still pass.
2242-2242: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPin
MAX_SCCM_SERVER_TOTAL_OPAQUE_EXTENSIONSwith an assertion.
EXPECTED_MAX_TOTAL_OPAQUE_EXTENSIONSduplicates the private constant so the test can detect a change to the bound. The duplicate never drives an equality check, so it cannot detect anything.The loop at Line 2399 divides by
MAX_SCCM_SERVER_OPAQUE_EXTENSIONSand produces 33 artifacts of 32 extensions each, which is 1056. If someone lowersMAX_SCCM_SERVER_TOTAL_OPAQUE_EXTENSIONSto 512, the total still exceeds the bound and the test still passes. The oracle is silent about the regression it exists to catch.Add the missing assertion.
💚 Proposed fix
const EXPECTED_MAX_TOTAL_OPAQUE_EXTENSIONS: usize = 1_024; + + #[test] + fn total_opaque_extension_bound_is_pinned() { + assert_eq!( + MAX_SCCM_SERVER_TOTAL_OPAQUE_EXTENSIONS, + EXPECTED_MAX_TOTAL_OPAQUE_EXTENSIONS, + "changing the aggregate extension bound is a public intake contract change" + ); + }Also applies to: 2399-2403
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs` at line 2242, Update the test using EXPECTED_MAX_TOTAL_OPAQUE_EXTENSIONS to assert equality with MAX_SCCM_SERVER_TOTAL_OPAQUE_EXTENSIONS, ensuring the duplicated expected value detects changes to the private bound. In the artifact-generation loop around MAX_SCCM_SERVER_OPAQUE_EXTENSIONS, retain the existing coverage while adding this assertion before relying on the configured limit.
1142-1149: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the unreachable
had_errorsbranch forwindows-1252.
encoding_rs::WINDOWS_1252.decodemaps every byte value and always returnshad_errors == false. Remove the branch or document this guarantee.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs` around lines 1142 - 1149, Update the "windows-1252" arm in the encoding dispatch to remove the unreachable had_errors check, and return the decoded owned content directly from encoding_rs::WINDOWS_1252.decode while preserving the existing Ok(Some(...)) result.
2164-2196: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse one convention for optional raw fields.
Missing
Option<T>fields already deserialize asNone;#[serde(flatten)]onextensionsdoes not change this. Remove the redundant annotations or apply them consistently across these raw structs.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs` around lines 2164 - 2196, Remove the redundant #[serde(default)] annotations from optional fields in RawServerArtifact, or apply the same convention consistently to optional raw fields across the related raw structs. Since Option<T> already defaults to None when absent, preserve deserialization behavior while eliminating the inconsistent annotations.crates/cmtraceopen-parser/tests/sccm_server_intake.rs (3)
49-97: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the duplicated scope-to-needle mapping.
manifest_with_duplicate_extensionandmanifest_with_duplicate_known_fieldcontain the same eight-armmatch scopeblock verbatim at Lines 56-66 and Lines 81-91. A new scope must be added in both places, and a mismatch between them produces a confusingassert_ne!failure rather than a clear error.Extract one helper and call it from both.
♻️ Proposed refactor
+fn scope_needle(scope: &str) -> &'static str { + match scope { + "manifest" => "{", + "privacy" => "\"privacy\":{", + "topology" => "\"topology\":{", + "artifact" => "\"artifacts\":[{", + "workflowSubject" => "\"workflowSubject\":{", + "configuredPathProvenance" => "\"configuredPathProvenance\":{", + "rotation" => "\"rotation\":{", + "collectionLimit" => "\"collectionLimit\":{", + _ => panic!("unknown extension scope: {scope}"), + } +} + fn manifest_with_duplicate_extension( manifest_json: &str, scope: &str, extension_name: &str, first_value: &str, second_value: &str, ) -> String { - let needle = match scope { - "manifest" => "{", - ... - }; + let needle = scope_needle(scope);Apply the same substitution in
manifest_with_duplicate_known_field.One note on the helpers themselves: for
scope == "manifest"the needle is"{", soassert_ne!can never fail. That assertion protects the seven nested scopes only.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/tests/sccm_server_intake.rs` around lines 49 - 97, Extract the duplicated scope-to-needle match into a shared helper, then update both manifest_with_duplicate_extension and manifest_with_duplicate_known_field to obtain their needle through it. Preserve all existing scope mappings and the current nested-scope assertion behavior, while keeping the manifest scope’s “{” handling unchanged.
377-392: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFind the
root-segment by prefix instead of by index.
distinctOpaqueRootSegmentsreadssplit('/').nth(5)and then filters on theroot-prefix. Index 5 is correct only when the relative path has no workflow-subject segment.validate_relative_pathinsertssubject-<role>and an optionalinstance-<handle>segment before the configured-root segment, so a subject-bearing artifact shifts the root to index 6 or 7.Today only the collision fixture uses this key and it has no workflow subject, so the assertion passes. If a later collision fixture adds a subject,
.expect("opaque configured-root segment")panics and the message points at a missing root segment rather than at the index assumption.♻️ Proposed fix
let root_segments = artifacts .iter() .map(|artifact| { artifact["relativePath"] .as_str() .expect("relative path") .split('/') - .nth(5) - .filter(|segment| segment.starts_with("root-")) + .find(|segment| segment.starts_with("root-")) .expect("opaque configured-root segment") }) .collect::<BTreeSet<_>>();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/tests/sccm_server_intake.rs` around lines 377 - 392, Update the distinctOpaqueRootSegments assertion in the sccm_server_intake test to locate the configured-root segment by finding the path component prefixed with “root-” rather than using split('/').nth(5). Preserve the existing expectation and distinct-count assertion while allowing subject- and instance-bearing paths.
589-616: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueThe synthetic branch assumes the fixture does not already use
LAB-MP01.To prove cross-bundle ID reuse, the branch changes
captureHostand then assertsassert_ne!(repeated["topology"], actual["topology"]). For a synthetic fixture it substitutes the literal"LAB-MP01".
normalize_topologyaccepts only"LAB-CM01"and"LAB-MP01"for synthetic fixtures, so there is exactly one alternative. If the fixture that carriescrossBundleArtifactIdReuseAllowedis ever changed to useLAB-MP01, the substitution becomes a no-op, the topologies match, andassert_ne!fails with a message about topology equality rather than about the fixture change.Select the other permitted host explicitly.
♻️ Proposed fix
second_manifest["topology"]["captureHost"] = if second_manifest["syntheticFixture"] == true { - Value::String("LAB-MP01".to_owned()) + // Synthetic topology is a closed two-value vocabulary. + if manifest["topology"]["captureHost"] == "LAB-CM01" { + Value::String("LAB-MP01".to_owned()) + } else { + Value::String("LAB-CM01".to_owned()) + } } else { Value::String(opaque_handle("cmtraceopen.host.sha256.v1:", 999)) };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/cmtraceopen-parser/tests/sccm_server_intake.rs` around lines 589 - 616, Update the synthetic branch in the crossBundleArtifactIdReuseAllowed test to choose the permitted host opposite to the fixture’s current captureHost, using LAB-CM01 when it is LAB-MP01 and LAB-MP01 otherwise. Keep the opaque-handle behavior for non-synthetic fixtures and preserve the topology inequality assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs`:
- Around line 1976-2066: Update the preflight validation around
validate_preserved_extensions to derive each known-field list from the
corresponding Serde struct declarations, using shared declarations or a macro
rather than maintaining separate literal lists. Apply this to the manifest,
privacy, topology, artifact, and nested artifact fields so adding a struct field
automatically updates validation and remains accepted as a known field.
In `@crates/cmtraceopen-parser/tests/sccm_server_intake.rs`:
- Around line 1587-1596: Update the reordering test around manifest_value and
serialize_manifest so the reordered manifest is constructed as raw JSON text,
matching the approach used by the duplicate-extension helper. Ensure extension
fields are emitted in a genuinely different arrival order before passing the
text to assess_server_intake, while preserving the existing normalized-output
assertion.
---
Nitpick comments:
In `@crates/cmtraceopen-parser/src/sccm/server/windows/intake.rs`:
- Around line 777-781: Rename synthetic_unclassified to reflect that it detects
the unclassified producer role regardless of synthetic_fixture, and update both
remaining references in the topology-observation bypass around the associated
intake logic. Preserve the existing condition and behavior for production
manifests and synthetic fixtures.
- Around line 117-125: Update SccmServerOpaqueExtensionError and validate so
schema_version != 1 produces a distinct version-mismatch error instead of
InvalidName; keep safe_opaque_extension_name validation mapped to InvalidName
and preserve the existing value validation behavior.
- Around line 1557-1574: Remove the synthetic_fixture conditional from
safe_source_id because its only accepted value is already handled by the
unconditional matches! list, making that branch unreachable. Keep allow_unknown
behavior for non-synthetic values using opaque_sha256_handle, and verify the
existing provenance and future-label tests still pass.
- Line 2242: Update the test using EXPECTED_MAX_TOTAL_OPAQUE_EXTENSIONS to
assert equality with MAX_SCCM_SERVER_TOTAL_OPAQUE_EXTENSIONS, ensuring the
duplicated expected value detects changes to the private bound. In the
artifact-generation loop around MAX_SCCM_SERVER_OPAQUE_EXTENSIONS, retain the
existing coverage while adding this assertion before relying on the configured
limit.
- Around line 1142-1149: Update the "windows-1252" arm in the encoding dispatch
to remove the unreachable had_errors check, and return the decoded owned content
directly from encoding_rs::WINDOWS_1252.decode while preserving the existing
Ok(Some(...)) result.
- Around line 2164-2196: Remove the redundant #[serde(default)] annotations from
optional fields in RawServerArtifact, or apply the same convention consistently
to optional raw fields across the related raw structs. Since Option<T> already
defaults to None when absent, preserve deserialization behavior while
eliminating the inconsistent annotations.
In `@crates/cmtraceopen-parser/tests/sccm_server_intake.rs`:
- Around line 49-97: Extract the duplicated scope-to-needle match into a shared
helper, then update both manifest_with_duplicate_extension and
manifest_with_duplicate_known_field to obtain their needle through it. Preserve
all existing scope mappings and the current nested-scope assertion behavior,
while keeping the manifest scope’s “{” handling unchanged.
- Around line 377-392: Update the distinctOpaqueRootSegments assertion in the
sccm_server_intake test to locate the configured-root segment by finding the
path component prefixed with “root-” rather than using split('/').nth(5).
Preserve the existing expectation and distinct-count assertion while allowing
subject- and instance-bearing paths.
- Around line 589-616: Update the synthetic branch in the
crossBundleArtifactIdReuseAllowed test to choose the permitted host opposite to
the fixture’s current captureHost, using LAB-CM01 when it is LAB-MP01 and
LAB-MP01 otherwise. Keep the opaque-handle behavior for non-synthetic fixtures
and preserve the topology inequality assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: dbaf2ca3-92a5-4b0b-9e7a-45cd77d9eca0
📒 Files selected for processing (5)
crates/cmtraceopen-parser/Cargo.tomlcrates/cmtraceopen-parser/src/sccm/server/windows/intake.rscrates/cmtraceopen-parser/tests/fixtures/sccm/server/intake/collision-same-basename-configured-roots/expected.jsoncrates/cmtraceopen-parser/tests/fixtures/sccm/server/intake/unsorted-manifest/expected.jsoncrates/cmtraceopen-parser/tests/sccm_server_intake.rs
|
Exact review-fix head Handled at this head:
Verification at the exact head: A fresh independent reviewer returned GO at |
What changed
This follow-up hardens the pure SCCM Server intake contract already integrated for issue #335.
Why
Independent review of the earlier server-intake slice found that forward-compatible fields were either rejected too broadly or could carry unsafe semantics, metadata errors were mis-scoped, and future roles could not preserve real coverage states. This correction keeps the reader tolerant only through a narrow, versioned, privacy-safe opaque form while remaining evidence-first and conservative.
Validation
cargo test --locked -p cmtraceopen-parser --test sccm_server_intake— 56 passedcargo test --locked -p cmtraceopen-parser --test sccm_spine_contract— 161 passedcargo test --locked -p cmtraceopen-parser— passedcargo clippy --locked -p cmtraceopen-parser --all-targets -- -D warnings— passedcargo check --locked -p cmtraceopen-parser --target wasm32-unknown-unknown— passedrustfmt --check— passedgit diff --check d1bb525b4462b4ea5e2f1426be23568ca469cc3f..ceb487e60d9b9d1de635c9eef5d83a054ffa3e2d— passedRepository-wide
cargo fmt --check --allstill reports pre-existing unrelated ESP/Tauri formatting drift identically at the base commit; this range does not change those files.No native server collection or live Windows acceptance is claimed here.
Refs #335 and #317.
Summary by CodeRabbit
New Features
Bug Fixes