Skip to content

fix: fail closed when quantum-safety policy is not fully evaluated - #375

Open
AAH20 wants to merge 2 commits into
cbomkit:mainfrom
AAH20:fix-342-quantum-safety-evaluation-status
Open

AAH20 wants to merge 2 commits into
cbomkit:mainfrom
AAH20:fix-342-quantum-safety-evaluation-status

Conversation

@AAH20

@AAH20 AAH20 commented Sep 12, 2026

Copy link
Copy Markdown

Summary

  • Closes Quantum-safety compliance must not pass when policy evaluation is absent or incomplete #342: empty/missing OPA findings no longer produce a quantum-safe global verdict (Stream.noneMatch on an empty list was fail-open).
  • Adds evaluationStatus (evaluated | partial | not_evaluated | not_applicable | error) and evaluationSummary asset counts to the compliance API response.
  • globalComplianceStatus=true only when evaluation is complete and every applicable asset is conclusively quantum-safe.
  • Frontend shows Not evaluated / Partial evaluation / Not applicable instead of a green compliant banner in those cases.
  • Updates README to document the fail-closed semantics.

Test plan

  • Added ComplianceResultFactoryTest covering: missing/empty findings, service error, empty CBOM, NA-only, partial coverage, unknown, mixed, fully evaluated safe positive control, and the empty-list fail-open regression.
  • ./mvnw clean package (needs GitHub Packages auth for org.pqca:cbomkit-lib)
  • ./mvnw test -Dtest=ComplianceResultFactoryTest
  • Manual: POST /api/v1/compliance/check with a CBOM while OPA policy is missing → evaluationStatus=not_evaluated, globalComplianceStatus=false
  • Manual: fully evaluated quantum-safe CBOM → evaluationStatus=evaluated, globalComplianceStatus=true
  • Frontend: banners for not evaluated / partial / not applicable

Made with Cursor

Empty OPA findings / missing policies previously yielded globalComplianceStatus=true
via Stream.noneMatch on an empty list. Add evaluationStatus + evaluationSummary and
only mark quantum-safe when evaluation is complete and conclusive.

Closes cbomkit#342

Signed-off-by: Ahmed Hassan <[email protected]>
Co-authored-by: Cursor <[email protected]>

@n1ckl0sk0rtge n1ckl0sk0rtge left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this PR, Ahmed! I appreciate the work 💙

I reviewed the backend, frontend, API response, and tests against #342. The empty-findings regression is fixed, but several paths still report a complete or green evaluation when the requested OPA policy did not cover the CBOM or failed. The inline comments have concrete cases and suggested fixes. Frontend lint and production build pass. I could not run the Java tests: Maven gets a 401 for the private cbomkit-lib package because this environment has no GitHub Packages Maven credentials.

This review was generated with AI assistance; please verify the findings.

}
}

int evaluatedAssets = findings.size();

@n1ckl0sk0rtge n1ckl0sk0rtge Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we check coverage against the CBOM's actual bom-ref values instead of findings.size()? The bundled Rego policy can emit both an OID/name finding and a NIST-level finding for the same asset. With two components, two safe findings for A and none for B make this count 2/2 and set globalComplianceStatus=true. A malformed OPA finding with a safe result but no bom-ref can also satisfy a one-asset count. Pass the expected asset IDs into the factory, validate finding IDs, and add tests for duplicate and missing IDs.

} else if (findings.isEmpty()) {
// Missing policy, empty OPA result, or no findings key — never quantum-safe.
status = EvaluationStatus.NOT_EVALUATED;
} else if (applicableAssets <= 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we check incomplete coverage before choosing not_applicable? For a two-asset CBOM with one NA finding and no finding for the second asset, applicableAssets is zero, so this reports not_applicable and hides the unevaluated asset. That case should be partial; a test with one NA result and one missing asset would catch it.

}

private static int countCryptographicAssets(@Nonnull CBOM cbom) {
return Optional.ofNullable(cbom.cycloneDXbom().getComponents())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we count only components of type cryptographic-asset here and in the scanned-repository handler? This currently counts every CycloneDX component. With one evaluated crypto asset plus one ordinary library, the factory reports partial because it expects two findings, even though the policy covered every crypto asset. A library-only CBOM is likewise treated as unevaluated instead of having no applicable crypto assets.

@Nonnull List<ComplianceLevel> complianceLevels,
int defaultComplianceLevel,
int totalCryptographicAssets) {
if (checkResult.error()) {

@n1ckl0sk0rtge n1ckl0sk0rtge Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only detects an error from the selected service. If OPA is configured but unreachable at startup, Configuration.getComplianceService() catches that failure and selects BasicQuantumSafeComplianceService instead. Its successful result reaches this factory as error=false and can become evaluationStatus=evaluated, globalComplianceStatus=true, although the configured OPA policy never ran. Could we carry that fallback state into the response and keep the requested policy's evaluation from appearing successful?

evaluationStatus = "partial";
} else if (vulnerableAssets === 0 && unknownAssets === 0) {
evaluationStatus = "evaluated";
globalComplianceStatus = true;

@n1ckl0sk0rtge n1ckl0sk0rtge Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A backend OPA error can still produce a green banner. getRemoteComplianceReport() in api.js treats {error:true,evaluationStatus:'error'} as invalid and replaces it with this local report; one asset with nistQuantumSecurityLevel: 1 makes this branch return evaluated/true, which the UI renders as Compliant. Could we preserve the failed remote evaluation status in the overall verdict instead of letting the fallback overwrite it? A frontend deployed before the new backend also takes this fallback path for responses lacking evaluationStatus.


const globalComplianceStatus = findings.every(finding => finding.levelId !== 1 && finding.levelId !== 2);
const cryptoComponents = components.filter(component => component.type === "cryptographic-asset");
const totalCryptographicAssets = cryptoComponents.length || components.length;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we use cryptoComponents.length directly? For a CBOM containing only an ordinary library component, the loop above emits no findings, but || components.length reports one cryptographic asset and chooses not_evaluated. There are zero crypto assets, so this should be not_applicable with a total of zero. I reproduced this with a library-only CBOM.

false,
true,
EvaluationStatus.ERROR,
ComplianceEvaluationSummary.empty());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could the error result retain the CBOM's asset total? fromServiceResult() already receives totalCryptographicAssets, but this helper sets every summary count to zero. An OPA failure for a nonempty CBOM therefore reports totalCryptographicAssets: 0, which reads as an empty CBOM rather than an evaluation error.

@san-zrl

san-zrl commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Hi @AAH20 - Are you still interested it in PR? Here's another review in case you still want to go on.

Requesting changes

This is a well-motivated fix. The noneMatch-on-empty-stream bug is real, the factory abstraction is a good design move, the unit tests are thorough, and the frontend double-guard is a nice touch. I tested the cases below against a live OPA instance with quantum_safe.rego loaded, so these aren't theoretical.

Two correctness issues need to be addressed before merge.


1. Coverage is counted in findings, not assets, which allows a false evaluated + globalComplianceStatus=true (high)

Why it matters: ComplianceResultFactory.fromFindings treats evaluatedAssets = findings.size() as the number of assets that were checked. But OPA emits one finding per rule hit, not one per component. A single component that matches both asymmetric_quantum_safe and nist_qs_level produces two findings. So a CBOM with two components, where the first matches two rules and the second matches none, still satisfies evaluatedAssets (2) == totalCryptographicAssets (2). The factory then returns EVALUATED.

I ran this payload against OPA:

{ "components": [
  { "bom-ref": "mlkem", "name": "ml-kem",
    "cryptoProperties": { "assetType": "algorithm",
      "oid": "1.3.6.1.4.1.2.267.12.4.4",
      "algorithmProperties": { "primitive": "kem", "nistQuantumSecurityLevel": 3 } } },
  { "bom-ref": "cert", "name": "MyCert",
    "cryptoProperties": { "assetType": "certificate" } }
] }

OPA returns 2 findings, both for mlkem. The factory sees 2 findings and 2 total components, concludes EVALUATED, and sets globalComplianceStatus = true because both findings are safe. The certificate was never evaluated. I reproduced this by calling ComplianceResultFactory.fromFindings directly with those two findings and total=2: it returns EVALUATED / global=true. This is exactly the kind of fail-open result the PR is meant to eliminate.

Suggested fix: count distinct bom-ref values instead of raw findings:

long evaluatedAssets = findings.stream()
        .map(ComplianceFinding::identifier)
        .distinct()
        .count();

The totalCryptographicAssets denominator needs to be consistent with this. See item 2.


2. totalCryptographicAssets includes asset types that the policy never evaluates (medium)

Why it matters: both query handlers pass cbom.cycloneDXbom().getComponents().size() as the total. That counts every component in the BOM, including certificate, protocol and related-crypto-material. The Rego is_algorithm guard means OPA only produces findings for assetType == "algorithm", so non-algorithm components always have zero findings. The denominator is therefore inflated for any CBOM that contains them. Such a CBOM can never reach EVALUATED. It will always come back PARTIAL, even when every algorithm is fully and safely covered. That conflates "coverage is incomplete" with "non-algorithm assets are present".

This interacts with item 1. Once the numerator counts distinct bom-refs, the evaluatedAssets < totalCryptographicAssets check is only meaningful if the denominator counts the same population.

The frontend compliance-local.js already restricts its count to cryptographic-asset components. The handlers should apply an equivalent filter, counting only components whose assetType is ALGORITHM. That is what both the sample Rego policy and BasicQuantumSafeComplianceService actually evaluate.


Minor: no test covers the OPA path

All 11 tests in ComplianceResultFactoryTest exercise the factory in isolation with hand-built findings. Nothing covers OPAComplianceService.getFindings with an OPA-shaped response, the handler wiring, or the multiple-findings-per-asset case. Since the PR's motivation is a bug that only shows up end to end, I'd like a test that feeds an OPA-shaped response with two findings for one bom-ref (the shape that triggers item 1) through to the final ComplianceResult. That would pin the fix against regression.


What looks good

  • An empty or missing findings list can no longer produce globalComplianceStatus = true; the findings.isEmpty() guard is hit first.
  • The missing-policy and empty-OPA-response cases now map to not_evaluated.
  • checkValidComplianceResults rejects globalComplianceStatus=true without evaluationStatus='evaluated', which is a good second line of defence.
  • The UI no longer presents "not evaluated" as "Not compliant".

@AAH20

AAH20 commented Oct 13, 2026

Copy link
Copy Markdown
Author

Hi, yes, I’m still interested in getting this merged. Thanks for the detailed repros. I pushed a follow-up that deduplicates findings by bom-ref, treats conflicting outcomes conservatively, and scopes backend coverage to algorithm assets.

I’ve rechecked the remaining paths and don’t want to mark the review resolved yet. I still need to address the NA-plus-missing-asset case, preserve failed remote evaluation status instead of allowing the local fallback to show a green result, correct the library-only local count, retain asset totals on errors, and add coverage through the OPA response path.

I checked the latest CI state. The frontend and backend workflows are awaiting maintainer approval, and DCO-2 failed because the latest commit is missing a sign-off. I’ll correct the sign-off on the follow-up commit. The Java test run is also blocked locally by the private cbomkit-lib package credentials, so I can’t claim the backend tests pass yet. I’ll push a follow-up covering the remaining cases and ask for another review once CI can run.

@AAH20
AAH20 force-pushed the fix-342-quantum-safety-evaluation-status branch from 92620ad to 4dff3af Compare October 13, 2026 12:36
@san-zrl

san-zrl commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

The Java test run is also blocked locally by the private cbomkit-lib package credentials...

FYI: You need a GitHub Personal Access Token (see https://docs.github.com/en/[email protected]/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry) and put it into your ~/.m2/settings.xml

<settings>
  <servers>
    <server>
      <id>github</id>
      <username>YOUR_GITHUB_USERNAME</username>
      <password>YOUR_GITHUB_TOKEN</password>
    </server>
  </servers>
</settings>

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.

Quantum-safety compliance must not pass when policy evaluation is absent or incomplete

3 participants