Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions docs/experiments/c2pa-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Read-only experiment that detects [C2PA Content Credentials](https://c2pa.org/)

## Status

Experimental. Cryptographic verification and full JUMBF/CBOR decoding are deferred. The feature was assembled in reviewable layers (register → record → detection → reader/sidecar → hook → UI).
Experimental. The active manifest's claim generator, digital source type and action history are decoded from the JUMBF/CBOR store; cryptographic verification is deferred. The feature was assembled in reviewable layers (register → record → detection → reader/sidecar → hook → UI).

## What it does

Expand All @@ -27,7 +27,8 @@ On every successful image upload (`add_attachment` priority 20):
- PNG: a `caBX` chunk.
- WebP: a top-level RIFF chunk of type `C2PA`.
4. If found, stream the raw manifest bytes once, computing SHA-256 in flight, and persist the bytes to a sidecar file under `wp-content/uploads/ai-c2pa/`.
5. Write a structured `_wpai_monitor_record` postmeta entry pointing at the sidecar.
5. Decode the active manifest (claim generator, digital source type, action history) into `c2pa.decoded`. Decoding never verifies signatures or hashes.
6. Write a structured `_wpai_monitor_record` postmeta entry pointing at the sidecar.

The handler is wrapped in a `try / catch ( Throwable )` boundary and writes a record on every supported MIME type even if every stage fails. The upload itself never blocks.

Expand All @@ -40,6 +41,7 @@ The handler is wrapped in a `try / catch ( Throwable )` boundary and writes a re
- `Format_Detector`: walks containers and returns a location descriptor (segments + total length) without reading payload bytes.
- `Manifest_Reader`: streams the located bytes into a hash context and buffer, producing an immutable `Raw_Manifest` value object.
- `Sidecar_Writer`: persists the bytes and ensures the sidecar directory + hardening files exist.
- `Manifest_Decoder`: builds `c2pa.decoded` from the active manifest using `Jumbf_Reader` (walks the `LBox`/`TBox` superbox tree) and `Cbor_Decoder` (minimal, bounded RFC 8949 decoder for claims and assertions). Failures are appended to the record's `errors` array; it never throws.
- `Record`: normalizes the structured payload and persists it as JSON-encoded postmeta at `_wpai_monitor_record`.

**Media Library UI**
Expand Down Expand Up @@ -93,7 +95,19 @@ Stored at `_wpai_monitor_record` as a JSON-encoded string.
"manifest_sha256": "ab12...",
"manifest_length": 184213,
"sidecar_path_relative": "ai-c2pa/1234.jpeg.c2pa",
"decoded": null
"decoded": {
"manifest_label": "urn:c2pa:3fa6c8f2-…",
"claim_generator": { "name": "Example Generator", "version": "2.1" },
"digital_source_type": "http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia",
"actions": [
{
"action": "c2pa.created",
"when": "2026-04-22T19:29:58Z",
"softwareAgent": { "name": "Example Model", "version": "3" },
"digitalSourceType": "http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia"
}
]
}
},
"errors": []
}
Expand All @@ -103,7 +117,23 @@ The `@context` entry `https://w3id.org/openverifiable/v1` is a permanent [w3id.o

When no manifest is found, `c2pa` collapses to `{ "present": false, "format": <detected or null> }` and no sidecar is written.

`c2pa.decoded` is reserved for a follow-up (claim generator, `digitalSourceType`, action history). `traditional.*` are reserved for a future pass that promotes WordPress's existing EXIF / IPTC / XMP extraction into the same record.
`c2pa.decoded` is read from the active manifest (the last one in the store). It is `null` when the store cannot be parsed or contains no manifest, and on records captured before decoding was added (existing attachments are not re-scanned). A decode failure always adds a `decode_*` entry to `errors`, which tells the two apart.

- `manifest_label` — label of the active manifest superbox.
- `claim_generator` — `{ name, version }`, normalized from `claim_generator_info` (v2 claims, and v1 claims that carry it) or the v1 `claim_generator` string (as `name`, with `version: null`).
- `actions` — every entry of the `c2pa.actions` / `c2pa.actions.v2` assertions (including `__N` instances), reduced to `action`, `when`, `softwareAgent` (normalized like `claim_generator`, and resolved from the assertion's `softwareAgents` list when the action uses `softwareAgentIndex`) and `digitalSourceType`. Other keys are dropped; missing or non-string values are `null`. Capped at 100 entries, and strings at 256 characters. Actions from created and gathered assertions are not distinguished, although only created assertions are attributed to the signer (C2PA §10.2.2); v1 claims have no such split.
- `digital_source_type` — the `digitalSourceType` of the `c2pa.created` action. Source types on other actions describe those actions, not the asset's origin, so they are not used here. `null` means the origin is not recorded in the active manifest, **not** that the asset is not AI-generated. This is common: edited assets start with `c2pa.opened` and keep their origin in the parent manifest, and update manifests cannot contain `c2pa.created` (C2PA §18.15.2, §11.2.3).

These are **unverified claims read from the file** — no signature, certificate, or hash checks are made ([#954](https://github.com/WordPress/ai/issues/954), [#1071](https://github.com/WordPress/ai/issues/1071)). Per the [C2PA specification 2.4](https://spec.c2pa.org/specifications/specifications/2.4/specs/C2PA_Specification.html) §15.3, data from a manifest that has not been validated should not be displayed; if it is, the display must include both:

1. A warning that the data has not been validated.
2. A warning that the data must not be attributed to the manifest's signer.

The plugin cannot validate manifests yet, so this applies to everything in `c2pa.decoded`.

Decode problems are reported in `errors` with stage `decode_jumbf`, `decode_claim`, or `decode_assertion` (including an actions assertion with no `actions` list), and partial results are kept (e.g. actions still decode when the claim does not).

`traditional.*` are reserved for a future pass that promotes WordPress's existing EXIF / IPTC / XMP extraction into the same record.

## Sidecar layout

Expand Down Expand Up @@ -183,7 +213,6 @@ The badge intentionally does not use the Content Credentials "CR" trustmark or w

## Out of scope (this release)

- [#953](https://github.com/WordPress/ai/issues/953) — JUMBF box reader and CBOR decoder; populating `c2pa.decoded` with claim generator / digital source type / action history.
- [#954](https://github.com/WordPress/ai/issues/954) — Cryptographic verification in-browser via `@contentauth/sdk` (targeting 1.4.0); the verify link currently delegates to the CAI Verify tool.
- Using the Content Credentials "CR" trustmark for the grid badge, pending C2PA conformance and [#954](https://github.com/WordPress/ai/issues/954) (see [#955](https://github.com/WordPress/ai/issues/955)).
- [#956](https://github.com/WordPress/ai/issues/956) — Preserving manifests through WordPress's GD / Imagick subsize pipeline.
Expand Down
3 changes: 3 additions & 0 deletions includes/Experiments/C2pa_Monitor/C2pa_Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ public function capture_for_attachment( int $attachment_id ): void {
'message' => $e->getMessage(),
);
}

// Decode failures land in $errors and leave the raw capture intact.
$c2pa['decoded'] = ( new Manifest_Decoder() )->decode( $manifest->bytes, $errors );
} catch ( \RuntimeException $e ) {
$errors[] = array(
'stage' => 'scan',
Expand Down
Loading
Loading