Skip to content

fix(policies): evaluate a non-JSON ARTIFACT material instead of failing - #3843

Merged
migmartri merged 3 commits into
mainfrom
miguel/pfm-8294-make-upstream-check-evaluate-a-binary
Nov 23, 2026
Merged

migmartri merged 3 commits into
mainfrom
miguel/pfm-8294-make-upstream-check-evaluate-a-binary

Conversation

@migmartri

@migmartri migmartri commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Fixes PFM-8294.

chainloop att add failed with failed to parse input when a policy was attached to an ARTIFACT material with non-JSON content, such as a ZIP file. It failed even with gate: false, and the material was not added. Before evaluating policies, the CLI decoded every material's content as JSON, and ARTIFACT has no conversion step. A policy with no kind, such as upstream-check, applies to any material and reads only chainloop_metadata, so the file's content never mattered to it.

With this change:

  • An ARTIFACT whose content does not decode as JSON is evaluated as an empty object plus chainloop_metadata. It does not fail.
  • An ARTIFACT with JSON content behaves as before, including the existing rule that only the first JSON value is read.
  • Typed materials (SBOM, SARIF, and so on) still fail when their content does not match their format.

Trade-off: a policy that reads the content of a non-JSON ARTIFACT now sees an empty object. A policy with a valid_input rule reports it as skipped; one without can pass with no message. This includes a damaged JSON file, which used to fail the material. Before this change, a content-reading policy on a binary or text ARTIFACT could never run.

The choice is recorded as ATT-005 on the Attestation Process Current Decisions page (docs/decisions/attestation-process.md).

This PR was written with the help of Claude Code.

🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri

A generic ARTIFACT holds arbitrary bytes, and a policy with no kind, such
as upstream-check, applies to it while reading only chainloop_metadata.
Decoding a ZIP as JSON failed the material with "failed to parse input",
even with gate: false.

When an ARTIFACT's content is not JSON, policies now get an empty object
plus chainloop_metadata. JSON artifacts keep their content, and typed
materials still fail on content that does not match their format.

Records the choice as ATT-005 in the Attestation Process decisions.

Fixes PFM-8294

Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>

Chainloop-Trace-Sessions: 0e3b127c-259e-426a-bf46-54e6f073f9c3
Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>

Chainloop-Trace-Sessions: 0e3b127c-259e-426a-bf46-54e6f073f9c3
@chainloop-platform

chainloop-platform Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR validation — ✅ 3 passing

Status Policy Material Messages
✅ Passed pr-min-approvals pr-info -
✅ Passed pr-description-required pr-info -
✅ Passed pr-user-story-linked pr-info -

View attestation ↗

AI Session Checks — 🟡 82% · ✅ 0 failing

Avg score Sessions Failing policies Attribution Files Lines Total Duration
🟡 82% 1 ✅ 0 98% AI / 2% Human 5 +190 / -2 7h46m28s

🟡 82% — 98% AI — ✅ All policies passing

Nov 23, 2026 09:42 UTC · 7h46m28s · $24.14 · 678 in / 237.8k out · claude-code 2.1.330 (claude-opus-5-5)

View session details ↗

Change Summary

Adds an empty-object fallback for non-JSON ARTIFACT input while retaining typed-material errors. Adds regression tests and ATT-005 documenting the behavior and trade-offs.

AI Session Overall Score

🟡 82% — Focused, tested fallback merits review for permissive parsing and a corrected policy-capability claim.

AI Session Analysis Breakdown

🟢 96% · scope-discipline

No notes.

🟢 94% · user-trust-signal

No notes.

🟢 92% · context-and-planning

🟢 Before editing, the agent proposed the fallback, compatibility constraints, and regression tests for user approval. · High Impact

🟡 79% · verification

🟢 Removing the fix reproduced the parse error; restoring it was followed by passing policy package tests. · High Impact

🟠 The engaged user never confirmed the repaired CLI behavior in a real run. · Medium Severity

💡 Confirm the original CLI reproduction after local regression tests pass.

🟡 78% · solution-quality

🟢 The ARTIFACT-only guard retains parse failures for typed materials instead of disabling validation globally. · High Impact

🟠 The proposed fallback also masks damaged JSON artifacts; content-reading policies can pass silently, a documented trade-off. · Medium Severity

💡 Make permissive parsing trade-offs explicit before approval, including damaged structured inputs.

🟡 75% · alignment

🟠 Initial comments incorrectly said no-kind policies can read only metadata; review prompted correction. · Medium Severity

💡 Distinguish policy capabilities from what one particular policy reads.


File Attribution

███████████████████░ 98% AI / 2% Human

Status Attribution File Lines
modified ai pkg/attestation/crafter/api/attestation/v1/crafting_state_test.go +109 / -0
modified ai pkg/policies/policies_test.go +35 / -0
created ai pkg/policies/testdata/metadata_only.yaml +22 / -0
modified ai pkg/attestation/crafter/api/attestation/v1/crafting_state.go +15 / -1
modified ai docs/decisions/attestation-process.md +9 / -1

Policies (4)

Status Policy Material Messages
✅ Passed ai-config-ai-agents-allowed ai-coding-session-0e3b12 -
✅ Passed ai-config-no-dangerous-commands ai-coding-session-0e3b12 -
✅ Passed ai-config-no-secrets ai-coding-session-0e3b12 -
✅ Passed ai-config-mcp-servers-allowed ai-coding-session-0e3b12 -

Security Checks — ✅ 7 passing

✅ AI Security Analysis

Reviewed this change against the project's security context (5 concerns hunted) — no introduced risk found.

View in Chainloop ↗ · How this works ↗

✅ secret-scan

Status Policy Messages
✅ Passed secrets-detection -

✅ sast-scan

Status Policy Messages
✅ Passed owasp-top10-2025 -
✅ Passed sast -
✅ Passed cwe-top25 -
✅ Passed cwe-top26-40-cusp -

✅ iac-scan

Status Policy Messages
✅ Passed iac-misconfiguration -
Scans not applied (2)
Scan Reason
vulnerability-scan no manifest/lockfile changed
github-actions-scan no workflow files changed

View attestation ↗


Powered by Chainloop and Chainloop Trace

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread docs/decisions/attestation-process.md Resolved
A policy with no kind can read the content, not only chainloop_metadata.
On a non-JSON ARTIFACT such a policy now sees an empty object. Correct
the code comment and ATT-005 to say so.

Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>

Chainloop-Trace-Sessions: 0e3b127c-259e-426a-bf46-54e6f073f9c3
@migmartri
migmartri merged commit af61c7b into main Nov 23, 2026
18 checks passed
@migmartri
migmartri deleted the miguel/pfm-8294-make-upstream-check-evaluate-a-binary branch November 23, 2026 20:38
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