Repository navigation
fix(dpp)!: refuse immutableAllowSetting on a deletableDocument reference (PV14) - #4983
Conversation
…nce (PV14) A replace may change an immutable property in two cases: a first-time set of an immutableAllowSetting property the stored document lacks, and clearing a deletableDocument reference whose target has been deleted. On one property they applied in sequence (set to A, A deleted, clear, set to B) and repointed the frozen reference. Generation 3 of the document type parser now refuses, under full validation, an immutableAllowSetting entry that is a deletableDocument reference by id, the only form the clear covers. A contract update re-parses the whole contract the same way, so updates are covered too. The clear is kept: every replace re-validates the reference, so without it such a document could never be replaced once its target is deleted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedNext included review available in 59 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-09-24T14:09:57.920Z |
|
⛔ Final review complete — 1 blocking finding(s) (commit 39a76d0) · triage: critical · Phase 2 only (queue backlog) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (queue backlog)
The parser change correctly rejects the unsafe combination for newly registered contracts and contract updates. However, PV14 contracts created before this fix are intentionally reparsed with full validation disabled, so their immutable deletableDocument declarations remain active and the existing replace-state exceptions still allow the reference to be cleared and later repointed. This leaves the stated security invariant unenforced for already deployed PV14 contracts.
🔴 1 blocking
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Pre-existing PV14 contracts can bypass the new immutable-reference protection
packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs:517-523
The new restriction runs only when full_validation is true. The stored-contract path deliberately reparses existing contracts with full_validation = false, and the added test explicitly confirms that this preserves immutableAllowSetting on the unsafe reference. Consequently, a contract registered by the pre-fix PV14 code remains usable after upgrade with the vulnerable declaration. The replace validator still reads that declaration at document_replace_transition_action/state_v1/mod.rs:85-107: it allows clearing the dead reference, and after the property is absent it allows the next replacement to set it again as an added_data_field. Thus the immutable reference can still be repointed from document A to document B on an already deployed PV14 contract, despite the PR's stated goal that no such reference can be set once. The compatibility decision to keep these contracts readable needs a corresponding migration/invalidation plan or write-time handling that prevents the second set for legacy contracts.
source: gpt-6-astra (phase2-reviewer: security-auditor)
Review provenance
Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)
- Triage:
criticalbygpt-6-astra(effort low) — The diff changes consensus validation rules for document contract registration and replace-transition behavior intry_from_schema/v3/mod.rsanddocument_replace_transition_action/state_v1/mod.rs, which is a critical consensus surface despite being a focused fix. - Phase 1 reviewers: not run (skipped for throughput: 18 PRs queued, above the 10 limit)
- Fresh verifier:
gpt-6-astra— final-verifier; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— security-auditor (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs:517-523: Pre-existing PV14 contracts can bypass the new immutable-reference protection
The new restriction runs only when `full_validation` is true. The stored-contract path deliberately reparses existing contracts with `full_validation = false`, and the added test explicitly confirms that this preserves `immutableAllowSetting` on the unsafe reference. Consequently, a contract registered by the pre-fix PV14 code remains usable after upgrade with the vulnerable declaration. The replace validator still reads that declaration at `document_replace_transition_action/state_v1/mod.rs:85-107`: it allows clearing the dead reference, and after the property is absent it allows the next replacement to set it again as an `added_data_field`. Thus the immutable reference can still be repointed from document A to document B on an already deployed PV14 contract, despite the PR's stated goal that no such reference can be set once. The compatibility decision to keep these contracts readable needs a corresponding migration/invalidation plan or write-time handling that prevents the second set for legacy contracts.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix. |
Issue being fixed or feature implemented
A document type (protocol version 14, schema generation 3) can list properties under
immutable(frozen after creation, presence included) and, among those, underimmutableAllowSetting(an absent immutable property may be set once, then it is frozen). The replace state validation lets an immutable property change in exactly two cases:immutableAllowSettingand the stored document has no value for it (added_data_fields);deletableDocumentreference by id whose target has been deleted. This exception exists because every replace re-validates adeletableDocumentreference, so a document whose immutable reference went dead could otherwise never be replaced again.On one property the two apply one after the other, and together they repoint a reference that is supposed to be frozen:
Before:
pinnedIdto draft A: accepted, a first-time set.pinnedId: accepted, a deaddeletableDocumentreference may be cleared. The stored post now has nopinnedId.pinnedIdto draft B: accepted, since the stored post has no value for it, so this counts as a first-time set.The "immutable"
pinnedIdnow points at draft B.What was done?
The combination is now refused at contract registration. Under full validation, the generation-3 document type parser refuses an
immutableAllowSettingentry whose property is adeletableDocumentreference by id. That is the only form the dead-reference clear covers. Every otherdeletableDocumentform (a typed array of them, one inside an object, one through a lookup, alone or in an expression) is already refused on any immutable property, and animmutableAllowSettingentry must also be immutable. So after this change, nodeletableDocumentreference can be set once.After, the same schema fails to register with a
BasicError::ContractError(InvalidContractStructure)consensus error:"immutable": ["author", "pinnedId"]withoutimmutableAllowSettingstill registers, and it keeps the clear as its one way out once the target is deleted.immutableAllowSettingon apermanentDocumentoridentityreference still registers too, because those targets are never deleted and such a reference is never cleared.Why refuse at registration instead of refusing the clear at write time: every replace re-validates a
deletableDocumentreference. If the clear were refused, a document whose frozen reference went dead could never be replaced again, which is the problem the clear was added to solve.Details:
validate_no_immutable_deletable_element_references(document type parser generation 3,try_from_schema/v3/mod.rs), at the branch that lets the single top-level reference through. It sits next to the related refusals and reuses their error,DataContractError::InvalidContractStructurethroughconsensus_or_protocol_data_contract_error. No new consensus error was needed.validate_update1 letsimmutableAllowSettinggain a property that becomes immutable in the same update, so an update could reach this combination. However, the update transition parses the whole new contract with full validation (DataContract::try_from_platform_versioned) before the update rules run, and that parse now refuses it.v14.rsdescribe the restriction.immutableAllowSetting(checkedpackages/*-contractand the dpp fixtures), so no system contract is affected.How Has This Been Tested?
New tests in
packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/immutable_tests.rs, in the moduledeletable_document_reference. All four usePlatformVersion::latest():should_refuse_allow_setting_on_a_deletable_document_reference: the schema above is refused under full validation with the consensusInvalidContractStructureerror and the message above. The non-validating (stored contract) parse still records the lists as declared.should_admit_an_immutable_deletable_document_reference_that_is_not_settable: an immutabledeletableDocumentreference with noimmutableAllowSettingentry still registers.should_admit_allow_setting_on_a_reference_that_is_never_cleared:immutableAllowSettingon apermanentDocumentreference and on anidentityreference still registers.should_refuse_an_update_making_a_deletable_document_reference_settable_once: a contract registers withpinnedIdmutable. Version 2 makes it immutable and lists it underimmutableAllowSetting.DataContract::validate_updatealone accepts that pair, so the update path really reaches it. The full-validation parse the update transition performs refuses it with the same error.Results, run locally:
cargo test -p dpp --lib immutable_tests: 26 passed;cargo test -p dpp --lib validate_update: 116 passed;cargo test -p dpp --lib reference: 147 passed.should_refuse_allow_setting_on_a_deletable_document_referenceandshould_refuse_an_update_making_a_deletable_document_reference_settable_oncefail and the two admission tests still pass.cargo test -p drive-abci --lib immutable(14 passed) andcargo test -p drive-abci --lib deletable(15 passed).cargo clippy -p dpp --all-features --all-targets -- -D warningsandcargo fmt --all -- --checkare clean.The drive-abci change is comment-only. Its immutable and
deletableDocumentreference tests are listed because they exercise both exceptions, and none of their contracts combines them.Breaking Changes
Consensus change at protocol version 14 only, which is unreleased. A contract that lists a
deletableDocumentreference by id underimmutableAllowSettingcan no longer be registered, and no update can introduce one. Earlier protocol versions do not know either keyword.On a devnet already running protocol version 14 from a 4.2 beta, a contract registered with this combination stays readable, because stored contracts are parsed without the registration rules. Any update to that contract will now be refused, since an update re-parses the whole contract.
In-place changes to shipped generations
None. The edited parser, document type parser generation 3 (
try_from_schema: 3, selected only byCONTRACT_VERSIONS_V6), is reached only from protocol version 14, which is unreleased. The only change to document replace state validation 1 (selected only byDRIVE_ABCI_VALIDATION_VERSIONS_V10, protocol version 14) is a comment.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
39a76d0/self-reviewedonce the bots are doneWhen every box is checked the
PR Hygienecheck passes and this can merge.