Skip to content

fix(retention): narrower history refusal after a removal, audit tokens, endpoint anchors - #2377

Merged
bplatz merged 10 commits into
nextfrom
fix/retention-followups
Nov 15, 2026
Merged

bplatz merged 10 commits into
nextfrom
fix/retention-followups

Conversation

@bplatz

@bplatz bplatz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Three things turned up while the retention and erasure guides were written against next, and a fourth in review.

  1. One removal refused every-property history for every subject. After a removal of ex:email on ex:alice, a read of ex:bob ?p ?o at an earlier point answered 410, and so did fluree history ex:bob. A pattern with a variable predicate counted as reading everything, whatever its subject. The erasure cookbook's step "list the subject's history before you erase it" therefore failed for every data subject after the first one erased on a ledger.
  2. An erasure job's error could not be read on a server without data auth, and the CLI could not mint an audit token. GET /retention/{ledger} shows lastError, the requester, the commits and the removal journal only to an auditor. The route took the auditor from its bearer extractor, which ignores the token when data auth is off, so on such a server no request was an auditor. The docs said a token worked there. Separately, fluree token create had no flag for the fluree.ledger.audit.* claims.
  3. Links to path-parameter endpoints were dead on the built docs site. mdBook reads a heading's trailing {ledger} as heading attributes: the heading lost its parameter and got an id other than GitHub's, so #post-queryledger and the like resolved on GitHub only. Seven distinct anchors, sixteen links.
  4. A view policy could read removed history (since feat: TTL, history retention and proof-verified permanent erasure #2280). The refusal looked only at the query's own patterns, but a policy decides each row as of the read's point. Under a policy whose f:query condition reads a removed fact ({ex:alice ex:email "a@old"}, or a prefix filter on it), a read of an innocent fact answered or not according to the removed value, so a caller who can send an inline policy, or select a stored one, could confirm the value by guess or read it out a prefix at a time. A class policy did the same with a removed rdf:type: it hid a subject at that point exactly when the removed type had made it a member.

Changes

  • History refusal (retention/suppression.rs). A read's facts are now Fact::Of(subject?, predicate) or Fact::About(subject). A triple pattern with a constant subject and a variable predicate is About: refused when a removal of that subject, or one whose subject is not recorded, covers the point or range. Both-variable patterns, graph crawls, Cypher, wildcard paths and reasoning still read everything. A 410 names the removed property only to a read whose own pattern named it; a read of every property of a subject, or of everything, is told that a removed occurrence it could reach falls in its range, since which property was removed is audit data.
  • Policy reads (retention/suppression.rs, fluree_db_query::policy::for_each_condition_pattern). What the view's policies read counts toward the refusal: each f:query condition's patterns, parsed as the executor parses them (the two share jsonld_condition), and rdf:type for a class policy. ?$this stays a variable, so a condition reads its predicates for every subject. A Cypher condition, or one that does not parse, reads everything.
  • Status route (routes/audit.rs, routes/ledger.rs). The audit decision goes through audit::may_audit, which reads a presented token when the extractor ignored it, as require_audit already did for raw commits. The issuer must be trusted (--data-auth-trusted-issuer), or any issuer under --data-auth-insecure-accept-any-issuer.
  • CLI (fluree token create). New --audit-all and --audit-ledger. --all still leaves audit access out, since no other scope implies it. An audit grant with no read, write or storage access is refused at mint, because a server refuses that token; an audit grant alone gets that explanation, not "no permissions granted". fluree token inspect now lists read, write and audit scopes.
  • Docs. The fourteen brace-ending headings in api/endpoints.md escape their braces. The retention, erasure and time-travel guides, the history-retention reference, cli/token.md and the authentication page describe the behaviour above.

Behaviour change to weigh

The first change loosens a refusal that guards removed values. The grounds are the ones the code already relied on: a pattern naming a predicate of another constant subject was answered before this PR, because a triple pattern with a constant subject reads that subject's facts alone and the journal records each removal's subject. This extends the same rule from one predicate of the subject to all of them. A refused every-property read still confirms that a removal covers that subject at that point; the retention guide says so.

The fourth change refuses more: a historical read under a view policy whose condition reads a removed predicate, or under a class policy after a removed rdf:type, now answers 410 where it answered before.

Tests

  • a_removal_refuses_an_every_property_read_of_its_subject_only: JSON-LD point read, history range and SPARQL, for the removed subject, another subject and no subject; a crawl of the other subject stays refused. It fails with the old rule.
  • a_removals_subject_narrows_the_reads_it_refuses covers Fact::About, including a removal with no recorded subject.
  • a_server_without_data_auth_reads_an_audit_token: auditor, reader, untrusted issuer and no token against the status route, and the commit route alongside. It fails with the old route.
  • an_audit_grant_is_written_only_when_asked_for, an_audit_grant_without_data_access_is_refused_at_mint (now also an audit grant alone).
  • a_policy_condition_counts_toward_what_a_read_reads: a JSON-LD and a SPARQL condition that read a removed fact refuse an innocent read; a condition reading nothing removed is answered. a_class_policy_counts_as_a_read_of_types: on an indexed ledger, a class policy after a removed rdf:type refuses the earlier point and answers the head. Both fail without the change.
  • a_refusal_names_only_the_predicate_the_read_named, and a_conditions_patterns_are_told_or_refused (ask, an empty condition, an unparseable one, Cypher).

Not covered

  • A graph crawl of one constant subject at an earlier point is still refused for every subject. It follows references, so it needs more than a subject check.
  • The admin who requested an erasure still needs an audit token to read why it failed.
  • The docs site builds from main, so its links stay dead until next reaches main.
  • Refusing at the scan, against what a historical scan is actually bound to, rather than from the written query and its policies: this check has now missed a runtime read four times. Follow-up: Explore a single visibility gate for history hiding across read surfaces #2338.

mdBook reads a heading's trailing `{ledger}` as heading attributes. The
heading rendered without its parameter and got an id other than the one
GitHub derives, so every link to a path-parameter endpoint
(`#post-queryledger`, `#get-retentionledger-id`, ...) resolved on GitHub
and nowhere on the site.

Escaping the braces keeps the text and gives both renderers the same id.
…ubject only

A historical read with a variable predicate was treated as reading
everything, whatever its subject. One removal on one subject therefore
refused `ex:other ?p ?o` at an earlier point, and `fluree history <entity>`
without `-p`, for every subject of the ledger.

A triple pattern with a constant subject reads that subject's facts alone,
and the journal records each removal's subject. Such a pattern is now
refused when a removal of that subject, or one whose subject is not
recorded, covers the read; a pattern naming a predicate of another subject
was already answered on the same grounds.

A pattern with neither named, a graph crawl, a Cypher query, a wildcard
path and reasoning are refused for every subject as before.
…ta auth

The retention status route shows an erasure job's last error, requester
and commits, and the removal journal, only to an auditor. It took the
auditor from the route's bearer extractor, which ignores the token when
data auth is off, so on such a server nobody could read why a job failed.
The route now reads a presented token for its audit grant, as the raw
commit routes do; the issuer must still be trusted.

`fluree token create` had no flag for the audit claims. It gains
`--audit-all` and `--audit-ledger`. `--all` still leaves audit access out,
since no other scope implies it, and an audit grant without data access is
refused at mint because a server refuses such a token. `fluree token
inspect` lists read, write and audit scopes.
@bplatz bplatz added the bug Something isn't working as expected label Nov 13, 2026
@bplatz
bplatz requested a review from a team November 13, 2026 13:30

@aaj3f aaj3f 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.

@bplatz this is nice, and at a design level no pushback from me: Fact::About is the rule the named-predicate path already relied on, extended to every predicate of a constant subject, and the status route now decides audit through the same helper as the raw-commit routes. Claude threw 45 query shapes at a removal on a box (joins that bind the erased subject at runtime, VALUES/BIND, OPTIONAL/UNION/EXISTS/MINUS, subqueries, GRAPH ?g, paths, CONSTRUCT/DESCRIBE/ASK, history ranges, both JSON-LD and SPARQL), and nothing that was answered carried the removed value. Two headline notes:

(1) While hunting for a runtime read that slips past the check, Claude found one, just not in this diff: a policy condition. reads_of sees only the query's own patterns, but an f:query condition runs at the same earlier point, so a caller who can send an inline policy can confirm, or read out a prefix at a time, a removed value through an innocent row's visibility. It has been on next since #2280 (reproduced at the merge-base too), so it's not something this PR introduced. But this is the retention follow-up and it's the same check, so I'd like it fixed here (details below).

(2) That makes four times this check has missed a runtime read that no written pattern states: 9b7f6c679 (EXISTS in HAVING/ORDER BY), 1f5ba99cb (RDF list view), 7a7e0987d (Cypher properties() and hydration), and now policy conditions. Not for this PR, but I think it's worth adding to #2338 that the structural version is to refuse at the scan, against the subject and predicate a historical scan is actually bound to, rather than from the written query. That would also retire the exception list in reads_of. The point fixes are right here.

Approving so it isn't held, but I'd want the policy fix in before next goes to main, ideally in this PR.

Full review below:


✅ Approving to unblock: please get the policy-condition fix in before next reaches main, ideally in this PR.

All three of these are good fixes, @bplatz, and the first is the one that matters: the erasure cookbook's "list the subject's history first" step works again for every subject after the first. The narrowing is sound where it needs to be. A constant subject with a variable predicate reads only that subject's facts. Every shape where a subject is bound at runtime (a join, VALUES, BIND, a nested node, DESCRIBE's expansion) stays a variable subject and is still refused. Claude confirmed that on a box with 45 shapes: the 11 it answers are all reads that can't reach the removed value, and none carries it. With Fact::About made to refuse nothing, your unit test, your integration test and that probe all go red (the probe finds the removed value in 11 answers). The status route reading a presented token via presented_principal is the right altitude: one helper shared with require_audit. It honors D10, since only a verified, trusted, unexpired token with the audit claim for that ledger sees the journal and lastError. Expired, unsigned, forged, untrusted, wrong-ledger and audit-only tokens all get the redacted view. The CRITICAL item inline is pre-existing on next rather than this PR's doing, but it's the same check, which is why I'd like it here. The optional notes are small.

Adherence to repo commitments:

  • Patterns/abstractions: ✔ Fact::About reuses the about closure the named-predicate path already used; may_audit and require_audit share presented_principal; grant is extracted so claim writing is testable. Nothing parallel added.
  • Performance (speed first, memory second): ✔ the check runs once per historical request, only on a ledger with a removal (reads is lazy), never per row; the status route verifies one more token when data auth is off. No performance-degradation risk.
  • Deployment targets: ✔ the refusal change is host-neutral in-memory logic over the journal; the status-route change is server-only; the CLI signs locally. CI wasm32 and wasm-smoke are green on this head.
  • Testing: ✔ unit + integration tests for each change, wired (grp_retention, grp_policy, the CLI lib) and green in CI on this head; Claude mutation-checked each (seven mutations, each red). ⚠️ No test covers a policy condition at an earlier point (the CRITICAL item).
  • Conventions: ✔ self-describing subjects, multi-line bodies; clippy and fmt green; docs move with each behavior change (the mdBook anchor fix checked by building the book at the base and the head).

Verified at branch HEAD ac2f8eeed: CI run 43423650289 green (17,150 tests passed, 3 leaky, 49 skipped, all five new tests among them); on an EC2 box, the PR's five tests pass, seven mutations each turn a PR test red, and Claude's probes of the refusal, the status route and policy conditions ran at the head and at the merge-base.

Approving so you can merge when ready, but I'd really like the policy-condition fix to ride along, since it's the same check.

About(String),
}

/// What `query` reads, in IRIs: every pattern it evaluates, those in its

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.

CRITICAL (pre-existing on next, from #2280; not introduced by this PR). A policy condition reads removed history at an earlier point, and the refusal never sees it, so a caller who can send a policy can confirm, or extract, a removed value.

refuse_suppressed_view_history decides the refusal from reads_of(parsed, …): the query's own patterns. An f:query condition is evaluated per candidate flake against the same historical snapshot, but its patterns are never part of parsed. So a read that names an innocent predicate passes the check, and the policy decides each row's visibility from facts as of that point, the removed occurrence included. Anyone who can supply a policy can do this: opts.policy / the fluree-policy header on any unauthenticated request (every request on a server without data auth), a token with fluree.policy: request, or an embedder that passes a caller's policy through. On a server that requires data auth, an ordinary token's inline policy is refused with 403, so that setup is covered. A stored policy selected with policy-class should reach it the same way, though Claude didn't run that one.

Claude reproduced it on a box, at this head and at the merge-base e78a07b4e, through the API and over HTTP on a server without data auth. After removing ex:alice ex:email "a@old", the read ex:bob ex:name ?n at t1, with default-allow: false and one f:view policy whose condition is:

  • {"@id": ex:alice, ex:email: "a@old"} → ["Bob"];
  • {"@id": ex:alice, ex:email: "wrong@x"} → [];
  • ex:alice ex:email ?e + FILTER(strStarts(?e, "a@")) → ["Bob"]; with "z" → [].

A plain read of ex:alice ex:email ?e at t1 is refused (410) in the same run. So the value can be confirmed by guess, or read out a prefix at a time.

The fix that fits this check: when the view carries policies with f:query conditions, fold their patterns into what the read reads. Parse each condition (PolicyQuery { source, language }) against encoded_with and run read_by over its patterns. ?$this is a variable subject, so a condition lands on Of(None, p) or Everything, as it should. A Cypher condition, or one that doesn't parse, counts as Everything. It's lazy like the rest of reads, so it costs nothing for ledgers without a removal. I recognize this didn't come in with this PR, but this is the retention follow-up and it's the same check, so I'd like it fixed here, and at the latest before next reaches main.

Commenting here because fluree-db-api/src/view/query.rs is not in this diff.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 5ba0609 — also class policies: a class check reads the subject's rdf:type at the read's point, so after a removed type a class policy hid the subject exactly when the removed type had made it a member. A view with a class policy now counts as reading rdf:type.

.removed
.iter()
.find(|(_, of)| about(of, subject))
.map(|(p, _)| p.as_str()),

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 is more of a question than a suggestion. The 410 names the removed property ("a removed occurrence of <…/email> on … falls in the requested range"), and with Fact::About that now tells any reader which property of the subject they named was removed. Claude saw it on a server without data auth: a tokenless ex:alice ?p ?o @t:1 gets exactly that message back. By moving the point, the reader also gets the span. That's most of what D10 put behind audit on the status route ("which subject's which property was removed").

Some subject-level signal is inherent here. A refusal that is per subject says "this subject had a removal in this range", and that's the price of answering everyone else's every-property reads, which I think is right. Naming the property isn't needed for that, though. For a read that named its predicate, the message tells the reader nothing new. For About and Everything it's the only place the property leaks. Minimally, removal_needed could return the predicate only for Fact::Of, and the message could otherwise say "a removed occurrence this read could reach falls in the requested range". A sentence in history-retention.md's Status section, next to the fingerprint note, that a refusal confirms a removal covers that subject would make the rest explicit. It's minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 9ad201a

Comment thread docs/security/authentication.md Outdated
On a ledger with a [targeted removal](../transactions/history-retention.md#audit-access), the commit log still holds what its history no longer serves. Commit show, commit export, pack, storage-proxy reads of commits, transactions and history-index blobs, vended storage credentials, and merge-preview change details then need an audit scope as well as their usual one. Read, write and storage scopes do not imply it. On other ledgers it is not checked.
On a ledger with a [targeted removal](../transactions/history-retention.md#audit-access), the commit log still holds what its history no longer serves. Commit show, commit export, pack, storage-proxy reads of commits, transactions and history-index blobs, vended storage credentials, and merge-preview change details then need an audit scope as well as their usual one. Read, write and storage scopes do not imply it. On other ledgers it is not checked. [`fluree token create`](../cli/token.md) grants it with `--audit-all` or `--audit-ledger`.

A server that runs without data authentication keeps audit data behind this scope too. It reads a presented token for its audit grant alone, and only from an issuer it trusts (`--data-auth-trusted-issuer`).

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.

Not a big deal, but "only from an issuer it trusts (--data-auth-trusted-issuer)" leaves out --data-auth-insecure-accept-any-issuer. Under that flag any self-signed token counts. Claude checked: on a server without data auth started with it, a token signed by an unlisted key with fluree.ledger.audit.all sees the journal. So anyone with fluree token create and any key can read lastError, requesters and raw commits there. That follows from the flag, and the raw-commit routes already behaved this way, but the sentence now reads as a guarantee. Maybe: "…only from an issuer it trusts (--data-auth-trusted-issuer; under --data-auth-insecure-accept-any-issuer, from anyone)". Minor, but I'd rather see it in this PR than lost in the backlog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in dbc0655

@@ -103,6 +109,20 @@ fn run_create(
"no permissions granted; use --all, --events-ledger, --storage-ledger, --read-ledger/--read-all, --write-ledger/--write-all, or --graph-source".into(),
));

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.

Not a big deal, but the new audit-specific message never shows for the likeliest slip. fluree token create --private-key … --audit-ledger people:main with nothing else hits the first check, which doesn't count audit, and gets "no permissions granted; use --all, --events-ledger, …" (Claude ran it on the box). Someone who did ask for something is told they asked for nothing, and the hint doesn't mention audit. Letting the first check through when an audit grant is present, so the second one explains, is one line in the first condition:

        && permissions.graph_sources.is_empty()
        && !permissions.audit_all
        && permissions.audit_ledgers.is_empty()

Minor and non-blocking, but if you agree it's right, I'd rather see it in this PR than lost in the backlog.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 67fa51d

`fluree token create --audit-ledger people:main` with no other grant hit
the first check, which did not count audit, and was told it asked for
nothing. The first check now lets an audit grant through, so the second
explains that audit adds to data access.
…reads audit data

The sentence read as a guarantee that only a trusted issuer's audit token
is honored on a server without data auth; --data-auth-insecure-accept-any-issuer
trusts every issuer.
…hat named it

With Fact::About, a tokenless `ex:alice ?p ?o` at an earlier point was
told which of alice's properties was removed, and by moving the point its
span: most of what the status route keeps behind audit. A refusal of a read
that named the removed predicate still names it, since the reader learns
nothing new; a read of every property of a subject, or of everything, is
told only that a removed occurrence it could reach falls in its range. The
retention guide and the error reference say what a refusal still confirms.
…reads

A view policy decides each row as of the read's point, but the refusal
looked only at the query's own patterns. So a read of an innocent fact
under a policy that reads a removed one answered, and its rows told the
removed value: a condition such as {ex:alice ex:email "a@old"}, or one
filtering on a prefix, confirmed the value by guess or read it out a prefix
at a time; a class policy hid a subject at that point exactly when the
removed rdf:type had made it a member. Since #2280; anyone who can send an
inline policy, or select a stored one, could do this.

The refusal now adds what the view's policies read: each f:query
condition's patterns, parsed as the executor parses them
(for_each_condition_pattern, sharing jsonld_condition with evaluation), and
rdf:type for a class policy. ?$this stays a variable, so a condition reads
its predicates for every subject. A Cypher condition, or one that does not
parse, reads everything. The check is as lazy as before, so a ledger with
no removal pays nothing.
@bplatz

bplatz commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

(2) … worth adding to #2338 that the structural version is to refuse at the scan

Added to #2338: #2338 (comment)

@bplatz
bplatz merged commit 9b4c3a6 into next Nov 15, 2026
20 checks passed
@bplatz
bplatz deleted the fix/retention-followups branch November 15, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants