Skip to content

check transient store pull requests against the ledger collection config - #5651

Merged
pfi79 merged 6 commits into
hyperledger:mainfrom
Nussu06:pvtdata-transient-config-match
Dec 1, 2026
Merged

pfi79 merged 6 commits into
hyperledger:mainfrom
Nussu06:pvtdata-transient-config-match

Conversation

@Nussu06

@Nussu06 Nussu06 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix

Description

When a peer serves a private data pull for a block it has not committed yet, dataRetriever.fromTransientStore in gossip/privdata/dataretriever.go returned the write sets of every transient store entry for the requested txID together with the collection config of one of them (highest EndorsedAt, ties to the last entry iterated), and puller.filterNotEligible checked the requesting peer against that config.

Any channel member peer can add transient store entries through a gossip private data push (GossipStateProviderImpl.privateDataMessage), and the collection config in that message is stored as sent, with EndorsedAt 0. On a peer that received the real private data by dissemination (also EndorsedAt 0), a channel member outside the collection can push entries for the same txID whose config lists its own org as a member, then pull that digest with a BlockSeq above the victim's ledger height to force the transient store path. When one of its entries wins the tie-break, eligibility is checked against the forged config and the response carries the real private write set.

A write set is now served only to a requester that is eligible under two configs:

  • the collection config committed to the ledger, from the config history (MostRecentCollectionConfigBelow for the digest's block, the same lookup fromLedger uses). This is what grants access, and it replaces the config picked from the entries.
  • the collection config the write set was stored under, returned alongside it in PrivateRWSetWithConfig.StoredConfigs. This cannot grant access, since whichever peer wrote the entry supplied it, but it can withhold it.

The second check is what keeps a peer that is behind a collection config update from releasing private data under the config the update replaced. The entry can already carry the new config, because the endorser that wrote it has committed the update, and gossip advertises LedgerHeight, so an org the update removed from the collection can pick such a peer deliberately. The same state is reached from the other direction, when the transaction was endorsed before an update that added the requesting org and the peer has committed that update; the peer cannot tell the two apart, so it withholds in both, and in the second reading the requester waits for the block to commit and then reads the data from the ledger. This window is a confidentiality decision, not only a latency trade-off.

The check is narrower than comparing the stored policy with the ledger's, which an earlier revision of this PR did: an entry whose config differs only in MaximumPeerCount, RequiredPeerCount or BlockToLive, or whose policy still names the requester, is served. Forged entries whose config copies the policy the ledger holds, which is public, pass both checks and are relayed to an eligible requester, which discards them against the hashes in the block. Validating the sender and the config when the push is received would stop the pollution itself and is left for a follow-up.

An entry whose stored config does not cover the digest's namespace and collection is still skipped, since its write sets cannot be checked against a stored config. Any channel member can push such an entry, so that is logged at debug level rather than Error, which otherwise produced a line per entry on every pull.

If the ledger has no config for the collection, there is nothing to grant access, so nothing is served from the transient store for that digest and filterNotEligible skips it. That case is reachable at will by pushing an entry for a collection that does not exist, so it is logged at debug level, while a failure of the lookup itself is logged as a warning and now carries the underlying error.

The config history lookup is cached by namespace and block sequence and the cache is pinned to the ledger height it was built at. The config history and the chaincode definitions behind implicit collections are only written when a block commits, which raises the height, so an entry stays valid for as long as the height does. A request for one block carries a digest per collection, createResponse calls CollectionRWSet once per block sequence, and the same block is pulled by several peers at commit time, so sharing the cache across calls at a fixed height reduces that to one lookup per (namespace, block sequence). The cache is bounded, since the block sequences a request asks about are the requester's choice, and a lookup only runs for a digest whose txID actually has transient entries, which already costs a store iteration. The transient store entries are read in their own function so that the iterator is closed before the ledger is queried.

On the requesting side, populateFromRemotePeers in gossip/privdata/pvtdataprovider.go now searches a response element for the write set whose hash is the one in the block instead of taking the first and deleting the key. A peer serving from its transient store returns every write set stored for the txID, so a pushed write set arriving first made the real one, later in the same element, be skipped and the digest be left to reconciliation.

Additional details

TestPullerTransientStoreConfigUpdateInFlight in pull_test.go covers the update window through the real puller, dataRetriever and transient store: with the ledger at {org1, org2} and the entry stored under {org1}, org2 receives no element and org1 receives the real write set; with the ledger at {org1} and the entry stored under {org1, org2}, the ledger config denies org2 and org1 is still served. The first case leaks the real write set to org2 without the stored config check.

TestPullerTransientStoreNonMemberWithForgedConfig and TestPullerTransientStoreMemberWithForgedEntries cover the reported attack with one disseminated entry plus entries pushed under a forged config, sending a pull request for a block above the ledger height through createResponse. On the old code the served config is that of the last entry iterated and the iteration order is random, so the non-member test runs the scenario over 5 fresh stores with 100 forged entries each; the real write set leaked to the non-member in all 5 against main. The member now receives only the real write set, since it is not eligible under the config the forged entries were pushed with. TestPullerTransientStoreForgedEntriesUnderLedgerPolicy pins the residual behaviour for forged entries that copy the ledger policy, and TestPullerTransientStoreNoLedgerCollectionConfig pins that no element reaches either a member or a non-member when the ledger holds no config for the collection.

TestRetrievePvtdataFromElementWithSeveralWriteSets in pvtdataprovider_test.go goes through RetrievePvtdata with a response element whose first write set is not the private data of the block, and fails on the previous requester loop.

In dataretriever_test.go, TestNewDataRetriever_TransientStoreEntriesWithDifferentConfigs checks that each write set comes back with the config of the entry it was stored in, TestNewDataRetriever_TransientStoreEntryUnderPreviousPolicy covers an entry stored under a policy the ledger no longer has, TestNewDataRetriever_TransientStoreEntryWithoutCollectionConfig covers the entries that are skipped for lack of a stored config for the digest, TestNewDataRetriever_TransientStoreNoLedgerCollectionConfig covers the four ways the ledger config can be unavailable (no config below the block, a config package without the collection, a retriever that cannot be obtained, and a failing lookup), and TestNewDataRetriever_TransientStoreLedgerConfigLookupCached covers the caching across digests and across CollectionRWSet calls.

go build ./gossip/..., go test ./gossip/... ./core/transientstore/..., go test -race ./gossip/privdata/..., go vet, gofmt, gofumpt and goimports pass locally.

EndorsedAt is still set by the endorser and persisted in the transient store, but no longer read by production code. It is kept as is: the field is part of the on-disk transient store record, and dropping the setter would leave entries without the height for a peer that is rolled back to a release that still selects by it.

Related issues

None

fromTransientStore merged the private write sets of every transient
store entry for a txID but kept the collection config of only one of
them, and the puller checks the requesting peer against that config.
Entries pushed over gossip carry a config supplied by the sending peer,
so a channel member outside the collection could push an entry whose
config names its own org and then pull the real private data for the
same txID before the block is committed.

Only return the write sets stored under the selected config.

Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
@Nussu06
Nussu06 requested a review from a team as a code owner October 27, 2026 19:38
@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

This pull request is merged.

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

Reviewed the change that limits fromTransientStore results to the selected collection config. Four comments are attached inline.

Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever_test.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
The collection config stored with a transient store entry is supplied
by whichever peer wrote the entry, so a config picked from those
entries cannot decide who may receive the private data: a channel
member outside the collection can push entries whose config names its
own org and, on a peer that only holds disseminated entries, make that
config win the EndorsedAt tie-break.

fromTransientStore now takes the collection config from the ledger's
config history, as fromLedger already does, and returns only the write
sets of entries whose member orgs policy matches it. Entries stored
under a different policy are dropped and counted in a debug log.
Entries that differ only in other fields, such as peer counts or BTL,
are still returned.

Add tests that go through the real puller, dataRetriever and transient
store: a non-member that pushed forged entries receives nothing, and a
member still receives exactly the real write set.

Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
@Nussu06 Nussu06 changed the title limit fromTransientStore results to the selected collection config check transient store pull requests against the ledger collection config Nov 23, 2026
@Nussu06

Nussu06 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 29598d6 covering the four comments: the requester is now checked against the collection config from the ledger rather than one picked from the transient store entries, the comparison is on the member orgs policy only, there are end-to-end tests through the real puller and transient store, and dropped entries are logged. Updated the title and description to match.

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

Reviewed the updated change that checks transient store pull requests against the ledger collection config. Five comments are attached inline.

Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/pull_test.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
…s tests

The member orgs policy comparison in fromTransientStore is defense in
depth on top of the ledger config check: entries pushed under a copy of
the ledger's public policy still pass and are left to the requester's
hash check, and an entry endorsed under a policy that a later
collection update replaced is dropped until its block commits. Say so
in the code, and add tests for both cases.

A missing ledger config on the transient path is expected for an
unknown or pushed collection, so log it as a warning and serve nothing
for the digest instead of returning an error that is logged at Error
level per request.

Run the non-member leak test over several fresh stores with more forged
entries, so that it fails in practice on code that serves the config of
the last iterated entry rather than passing in one of forgedEntries+1
runs.

Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
@Nussu06

Nussu06 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Pushed c7393d3 for the five comments: a test for an entry endorsed under a replaced policy (still dropped, now documented), the leak test runs over several fresh stores with 100 forged entries each, a test documenting that forged entries copying the real policy are relayed and left to the requester's hash check, EndorsedAt kept as is, and the missing ledger config case on the transient path logs a warning instead of an error. Description updated to match.

@pfi79 pfi79 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 the update. I reviewed the final diff and left inline comments.

Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever_test.go Resolved
The member orgs policy comparison cannot prevent disclosure, since the
requester is already evaluated against the collection config read from
the ledger and the policy it compares against is public, so an entry
pushed with a copy of it passes. All it did was drop entries, which
costs availability in two windows around a collection config update: an
entry endorsed under a policy a later update replaced, and an entry
endorsed under the new policy on a peer that has not committed the
update yet. Drop the comparison and return every write set stored for
the txID under the config from the ledger, which leaves eligibility
unchanged.

Cache the config history lookup by namespace and block sequence for the
lifetime of a CollectionRWSet call. The lookup creates a query executor
and reads the state DB for implicit collections, and a request for one
block carries a digest per collection, which repeated it per digest.

Read the transient store entries in their own function so that the
iterator is closed before the ledger is queried, and tell apart a
collection the ledger holds no config for, which a pushed entry can
cause at will and is now logged at debug level, from a failure of the
lookup itself, which stays a warning.

Cover the fallback that serves nothing without a ledger config for a
failing retriever, a failing lookup and a config package without the
collection, add a puller level test for the property that no element is
returned in that case, and one that the config is read from the ledger
once per namespace and block.

Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
@Nussu06

Nussu06 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Pushed b85546d for the five comments. The main one is that the member orgs policy filter is gone: the write sets stored for the txID are all returned under the collection config read from the ledger, so eligibility is unchanged and neither availability window drops a legitimate entry. The rest: the config history lookup is cached per (namespace, block sequence) for a CollectionRWSet call, the transient store iterator is closed before the ledger is queried, a collection the ledger holds no config for is logged at debug and a failing lookup at warning, and the serve-nothing fallback is covered for all four ways the config can be unavailable plus a puller level test that no element is returned. Description updated to match; the title still fits.

@pfi79 pfi79 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 the update. I reviewed the final diff and left inline comments on the transient-store eligibility path and its tests.

Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/pull_test.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
Taking the collection config only from the ledger lets a peer that is
behind a collection config update release private data under the config
the update replaced. The entry can already carry the new config, because
the endorser that wrote it has committed the update, and gossip
advertises the ledger height, so an org the update removed from the
collection can pick such a peer and pull the transaction with a block
sequence above its height.

Return the config each write set was stored under alongside the one read
from the ledger, and serve a write set only to a requester that is
eligible under both. The stored config is supplied by whichever peer
wrote the entry, so it still cannot grant access, but it can withhold
it. This is narrower than comparing the stored policy with the ledger's:
an entry whose config differs in MaximumPeerCount, RequiredPeerCount or
BlockToLive, or whose policy still names the requester, is served.

An entry whose stored config does not cover the digest's namespace and
collection cannot be checked against a stored config, so it stays
skipped, now at debug level rather than Error, since any channel member
can push one and make the peer log a line per entry on every pull.

Pin the config cache to the ledger height it was built at and share it
across CollectionRWSet calls. The config history and the chaincode
definitions behind implicit collections are only written when a block
commits, which raises the height, so an entry stays valid for as long as
the height does, and repeated pulls of the same block now cost one
lookup rather than one per request. The cache is bounded, since the block
sequences a request asks about are the requester's choice, and a lookup
failure is no longer cached or stripped of its cause.

On the requesting side, search a response element for the write set
whose hash is the one in the block instead of taking the first. A peer
serving from its transient store returns every write set stored for the
txID, and any channel member can add entries there, so a pushed write
set arriving first made the real one be skipped and the digest be left
to reconciliation.

Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
@Nussu06

Nussu06 commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 75040e8 for the five comments. The blocker is the main one: the ledger config no longer grants on its own. Each write set now comes back with the collection config it was stored under, and a requester is served only when both that config and the committed one make it a member, so a peer that is behind a collection config update doesn't release the data under the config the update replaced. The stored config still can't grant.

The rest: the entry whose stored config lacks the collection is still skipped but at debug level and for the fail-closed reason, the lookup errors carry their cause, the config cache is shared across CollectionRWSet calls at a fixed ledger height and bounded, and the requesting side searches a response element for the write set whose hash is in the block instead of taking the first. Description rewritten, including the part about eligibility being unchanged, which it isn't.

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

Reviewed the current PR head; leaving inline findings below.

Comment thread gossip/privdata/pull.go Resolved
Comment thread gossip/privdata/pull.go Resolved
Comment thread gossip/privdata/dataretriever.go Resolved
filterNotEligible checked the stored collection configs only when
StoredConfigs was not empty, so a result from the transient store whose
write sets came without one was served on the config read from the
ledger alone, which is the config-update-in-flight leak the stored check
exists for. A StoredConfigs shorter than RWSet also dropped the trailing
write sets silently, since the loop iterates StoredConfigs.

Decide by the path the result came from instead of by whether the field
is populated: a transient store result whose stored configs are not one
per write set is not served at all, and the digest is logged with both
counts. The ledger path is unchanged, and the invariant is recorded on
the field.

The stored configs are data another peer supplied, so treat a nil config
and a config that fails to marshal as ineligible for that write set
rather than passing either to the access policy or evaluating it
uncached. The stored config is the only thing that can withhold a write
set, so without a verdict from it there is nothing left to withhold by.

Keep the cause of the two config history lookup failures with Wrapf, so
errors.Is and errors.As still reach it.

Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
@Nussu06

Nussu06 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 70c2ec7 for the three comments. The main one is the fail-closed boundary: the stored config check is keyed on the path the result came from rather than on whether StoredConfigs is populated, so a transient store result that doesn't carry one stored config per write set serves nothing for the digest instead of falling back to the committed config, and the short-slice case no longer drops the trailing write sets quietly. The nil and unmarshalable stored configs are ineligible for their write set now rather than reaching the access policy, and the two config history lookup failures keep their cause through Wrapf.

Tests: TestPullerTransientStoreStoredConfigsOutOfStep covers no stored configs, fewer and more than the write sets, with a requester the committed config does make a member, and TestPullerTransientStoreNilStoredConfig covers a nil entry alongside a usable one. Description unchanged, since the behaviour it describes is the one this restores.

@pfi79
pfi79 merged commit 80349ae into hyperledger:main Dec 1, 2026
15 checks passed
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