Repository navigation
Description
Found while auditing #1838 — this is adjacent to that PR's reserved-graph work but is its own thing, and that PR deliberately doesn't touch it.
A bulk TriG import that names a reserved graph isn't refused, and the triples are persisted in the commit — but they land outside the graph registry, so nothing can read them back. No error anywhere along the way.
Repro
# forged.trig
@prefix ex: <http://example.org/> .
@prefix f: <https://ns.flur.ee/db#> .
ex:seed ex:v "base" .
GRAPH <urn:fluree:imp:main#txn-meta> {
<fluree:commit:sha256:deadbeef…deadbeef> f:t 9999 ; f:size 1 ; f:time 1 .
}$ fluree create --direct imp:main --from forged.trig
Imported 0.0M flakes in 0.07s across 1 commits (t=1)
It commits. The base triple lands fine. But the three triples inside the GRAPH block are readable from nowhere: not from FROM <urn:fluree:imp:main#txn-meta>, not from GRAPH ?g, not from the default graph — and the same before and after a genuine fluree index.
They're not dropped, though, which is the part that makes this worth filing. A flake-count differential on two imports whose files differ only in the GRAPH block gives 1 flake without it and 4 with, and fluree show on the commit decodes all three, each tagged {"graph": "urn:fluree:imp:main#txn-meta"}. So they're written and persisted, just not reachable.
The control is what makes it specific to the reserved IRI rather than "TriG GRAPH blocks get ignored on this path": a user named graph in the same import file is enumerable via GRAPH ?g afterwards.
Mechanism (traced, not run — so I may have this wrong)
import.rs:545-580 builds its own graph_delta and bypasses stage() entirely. Reading it, imports allocate from FIRST_USER_GRAPH_ID via a session counter and never consult the ledger's GraphRegistry, so a block naming #txn-meta should get a user g_id rather than 1 — but apply_delta skips already-registered IRIs, which would leave the flakes under a g_id the registry never maps. That's consistent with every observation above, but I didn't confirm it in a debugger, so treat the mechanism as a hypothesis and the behavior as the finding.
Scope, and what this isn't
Worth saying plainly so nobody reads this as scarier than it is: bulk import is genesis-only — fluree create <L> --from <dir> is the only surface that reaches import_trig_commit, there's no fluree import, and there's no way to bulk-import into an existing ledger. So this needs control of the corpus at ledger creation, not merely write access.
It's also not a second route to the commit-prefix forgery that #1838 closes. I checked that specifically, since it would have been a blocker there: the imported record is indistinguishable from a prefix matching nothing, before and after indexing —
$ fluree show --ledger imp:main aaaaaaaaaaaa # matches nothing
error: Not found: No commit found with prefix: aaaaaaaaaaaa
$ fluree show --ledger imp:main deadbeefdead # the imported record
error: Not found: No commit found with prefix: deadbeefdead
— whereas the staged path on main resolves that prefix to a full base32 CID before failing at the content store. The resolvers scan g_id 1, and these flakes aren't there.
What we may want
The behavior I'd expect is one of two things, and I don't have a strong view on which:
- refuse the block at import the way
stage()now refuses it, which would make the import path consistent with every other write surface; or - allocate it to the reserved g_id properly, if importing into
#configis something we actually want to support (the ledger-config docs do describe maintaining config through a transaction, so it's not obviously wrong).
Either way, silently persisting flakes nobody can read seems like the one option we don't want. A cheap version of the first would be to run the same IRI-shape check stage() uses over graph_delta before apply_delta.
Happy to talk it through if you have a preference on the direction.
Activity
aaj3f commentedon Sep 16, 2026
I flagged the mechanism in this issue as "traced, not run — so I may have this wrong", and I did have it wrong. Audited it properly against
main@3d89e8f71with a release binary from that commit; the behavior reproduces exactly as filed, but nothing in the write path is broken and the cheap fix I suggested would not change anything.The import path allocates
g_id 1correctly. I assumed imports allocate fromFIRST_USER_GRAPH_IDvia a session counter and never consult the registry. They do consult one:fluree-db-transact/src/import.rs:565-575allocates a block's g_id through the spool whenever spooling is active, and only falls back to the session counter when it is not — andcreate --fromalways spools, because it builds the genesis index.SpoolContext::graph_g_id_for_iri(fluree-db-transact/src/import_sink.rs:544-547) returnsdict_id + 1out of the shared graph allocator thatfluree-db-api/src/import.rs:4424builds asSharedDictAllocator::new_graph(alias), and that constructor (fluree-db-indexer/src/run_index/resolve/global_dict.rs:596-610) pre-seeds the reserved IRIs — txn-meta at dict_id 0, config at dict_id 1. Sourn:fluree:imp:main#txn-metaresolves to g_id 1, exactly as it should.apply_deltais a red herring too.LedgerSnapshot::apply_envelope_deltas(fluree-db-core/src/db.rs:600-631) handsGraphRegistry::apply_deltaonly the IRI values ofgraph_delta— the commit's g_id keys are never used to place anything — so the registry ends up correct and consistent rather than "never mapping" the flakes. Which is why re-reading the allocator could not find the defect: the allocator doesn't have one.The loss is in the index builder, and it happens because index builds are graph-scoped.
build_indexes_from_commitsfilters every record against a singletarget_g_id(fluree-db-indexer/src/run_index/build/build_from_commits.rs:1168), andfluree-db-api/src/import.rs:6337-6435runs exactly three kinds of pass:std::slice::from_ref(meta_commit)— only the synthetic commit-metadata chunk, never the data chunks,FIRST_USER_GRAPH_ID..=graph_count(3 and up) over all chunks.A
GRAPH <…#txn-meta>block's flakes get spooled into a data chunk under g_id 1. The g0 pass rejects them for having the wrong g_id, the g1 pass never reads the chunk they are sitting in, and there is no pass for g_id 2 at all. They are filtered out of every index segment while the commit blob keeps them, sinceStreamingCommitWriter::push_flakeencodes the graph Sid unconditionally — which is exactly whyfluree showdecodes all three and the flake differential comes out 1 vs 4.So the one-line version is: the import path assigns the reserved g_id correctly, and then the index builder, which only ever builds g_id 1 from the metadata chunk and never builds g_id 2 at all, silently discards every reserved-graph record that arrived in data.
fluree-db-api/src/import.rs:5991-5997even documents the intent — "g_id 1 (txn-meta) is built separately; g_id 2 (config) is not populated by bulk RDF import" — it just never refuses the input that violates it. Correct-and-invisible, rather than misrouted.Consequence for the fix I proposed. I suggested "run the same IRI-shape check
stage()uses overgraph_deltabeforeapply_delta" as a cheap version. That check isvalidate_absolute_graph_iri(fluree-db-core/src/graph_registry.rs:65-105) — whitespace, control characters, RFC-3987 exclusions, missing scheme — andurn:fluree:imp:main#txn-metais a perfectly well-formed absolute IRI that passes it cleanly. Running it overgraph_deltawould change nothing at all. The check that actually bites is the reserved-graph guard,fluree-db-transact/src/stage.rs:768-783, the one #1838 added, which compares againsttxn_meta_graph_iri(ledger_id)and against what the IRI routes to in the registry. And "beforeapply_delta" is the wrong layer regardless —apply_deltaruns at ledger-load/commit-apply time, by which pointimport_trig_commithas already encoded the flakes and written the blob (fluree-db-transact/src/import.rs:713-762), so refusing there rejects someone else's already-durable commit at load rather than stopping the import.#confighas the identical defect, which the issue didn't test. Same file shape aimed at<urn:fluree:cfg:main#config>witha f:LedgerConfig ; f:indexing "forged": it commits, the flakes are in the blob, andgraph listreports the graph as empty.Evidence, for the record:
The user-graph control is unaffected and still enumerates through
GRAPH ?g, so this really is specific to the reserved IRIs rather than to TriGGRAPHblocks on this path.So of the two directions I offered, I'd now take the first without much hesitation — refuse the block at import, at the top of the named-graph loop in
fluree-db-transact/src/import.rs, for both reserved IRIs, reusingTransactError::ReservedGraphTargetfor#txn-metaso the message matches every other write surface, and a distinct message for#config(that one's a capability gap, not a security refusal, and the two shouldn't read alike). Option 2 is off the table for#txn-meta— letting an import write commit provenance is precisely what #1838 refused — and for#configit means teaching the index pipeline to build reserved graphs from data chunks: a fourth build pass, a g_id-2 root entry, per-graph stats, and a call on what happens when an imported config disagrees with the onenew_for_ledgerimplies. That's a feature nobody has asked for, andfluree create L --from data.trig && fluree update -l L …already gets you a configured ledger at genesis+1.The guard costs nothing measurable, incidentally — it belongs per graph block, not per triple or per flake, and a single-graph import never executes it at all because
import_trig_commitearly-returns before the loop exists when there are no named graphs (fluree-db-transact/src/import.rs:480-493).Keep system graphs out of --all-graphs, and report what export wrote
Refuse reserved system graphs on the bulk RDF import path
Drop commit-provenance flakes carried in a commit blob
Merge the import and delete half of the RDF 1.2 round-trip work