-
Notifications
You must be signed in to change notification settings - Fork 53
fix(dpp): add additionalProperties: false to document meta-schema #3475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
QuantumExplorer
merged 11 commits into
v3.1-dev
from
fix/document-schema-additional-properties
Apr 12, 2026
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
582af94
fix(dpp): add additionalProperties: false to document meta-schema
QuantumExplorer 538c847
fix(dpp): version-gate document meta-schema to reject unknown propert…
QuantumExplorer 66b862d
refactor(drive): move migration to Drive, add contract properties che…
QuantumExplorer 27e50d9
fix(drive): revert migration to inline query for PR scope
QuantumExplorer 130a664
Merge remote-tracking branch 'origin/v3.1-dev' into fix/document-sche…
QuantumExplorer ebe9b8d
refactor(drive): use fetch_contract_ids in migration
QuantumExplorer 36569c3
fix(drive): migrate all historical contract revisions, not just latest
QuantumExplorer d1cc64b
test(drive-abci): add multi-revision historical contract migration test
QuantumExplorer 0ade3fe
test(drive-abci): verify element flags preserved across historical re…
QuantumExplorer ee8a026
fix(dpp): use v1 schema URI for contracts created under protocol v12+
QuantumExplorer f0ccff7
test(dpp): add regression tests for schema URI version dispatch
QuantumExplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
645 changes: 645 additions & 0 deletions
645
packages/rs-dpp/schema/meta_schemas/document/v1/document-meta.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/rs-dpp/src/data_contract/document_type/schema/allowed_top_level_properties.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| use platform_value::Value; | ||
|
|
||
| /// The set of top-level property names allowed on a document type schema object | ||
| /// as defined by the v1 document meta-schema. | ||
| /// | ||
| /// Any key not in this list should be stripped from document type schemas | ||
| /// during the v12 protocol upgrade migration to prevent unknown properties | ||
| /// from changing storage semantics. | ||
| pub const ALLOWED_DOCUMENT_SCHEMA_V1_PROPERTIES: &[&str] = &[ | ||
| "type", | ||
| "$schema", | ||
| "$defs", | ||
| "indices", | ||
| "signatureSecurityLevelRequirement", | ||
| "documentsKeepHistory", | ||
| "documentsMutable", | ||
| "canBeDeleted", | ||
| "transferable", | ||
| "tradeMode", | ||
| "creationRestrictionMode", | ||
| "requiresIdentityEncryptionBoundedKey", | ||
| "requiresIdentityDecryptionBoundedKey", | ||
| "tokenCost", | ||
| "properties", | ||
| "transient", | ||
| "keywords", | ||
| "additionalProperties", | ||
| "required", | ||
| "$comment", | ||
| "description", | ||
| "minProperties", | ||
| "maxProperties", | ||
| "dependentRequired", | ||
| ]; | ||
|
QuantumExplorer marked this conversation as resolved.
|
||
|
|
||
| /// Strips any top-level key from the document type schema `Value::Map` that | ||
| /// is not in the allowed set. Returns `true` if any keys were removed. | ||
| pub fn strip_unknown_properties_from_document_schema(schema: &mut Value) -> bool { | ||
| let map = match schema { | ||
| Value::Map(map) => map, | ||
| _ => return false, | ||
| }; | ||
|
|
||
| let before = map.len(); | ||
| map.retain(|(key, _)| { | ||
| let key_str = match key { | ||
| Value::Text(s) => s.as_str(), | ||
| _ => return true, // keep non-string keys (shouldn't happen but safe) | ||
| }; | ||
| ALLOWED_DOCUMENT_SCHEMA_V1_PROPERTIES.contains(&key_str) | ||
|
QuantumExplorer marked this conversation as resolved.
|
||
| }); | ||
| map.len() != before | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use platform_value::platform_value; | ||
|
|
||
| #[test] | ||
| fn strips_unknown_properties() { | ||
| let mut schema = platform_value!({ | ||
| "type": "object", | ||
| "properties": {}, | ||
| "additionalProperties": false, | ||
| "unknownProp": true, | ||
| "anotherUnknown": 42 | ||
| }); | ||
|
|
||
| let changed = strip_unknown_properties_from_document_schema(&mut schema); | ||
| assert!(changed); | ||
|
|
||
| let map = schema.as_map().unwrap(); | ||
| let keys: Vec<&str> = map.iter().filter_map(|(k, _)| k.as_text()).collect(); | ||
| assert!(!keys.contains(&"unknownProp")); | ||
| assert!(!keys.contains(&"anotherUnknown")); | ||
| assert!(keys.contains(&"type")); | ||
| assert!(keys.contains(&"properties")); | ||
| assert!(keys.contains(&"additionalProperties")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn no_change_when_all_properties_are_known() { | ||
| let mut schema = platform_value!({ | ||
| "type": "object", | ||
| "properties": {}, | ||
| "additionalProperties": false, | ||
| "required": ["foo"], | ||
| "$comment": "test" | ||
| }); | ||
|
|
||
| let changed = strip_unknown_properties_from_document_schema(&mut schema); | ||
| assert!(!changed); | ||
| } | ||
|
|
||
| #[test] | ||
| fn handles_non_map_value() { | ||
| let mut schema = Value::Text("not a map".to_string()); | ||
| let changed = strip_unknown_properties_from_document_schema(&mut schema); | ||
| assert!(!changed); | ||
| } | ||
| } | ||
2 changes: 2 additions & 0 deletions
2
packages/rs-dpp/src/data_contract/document_type/schema/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| pub mod allowed_top_level_properties; | ||
|
|
||
| mod enrich_with_base_schema; | ||
|
|
||
| mod find_identifier_and_binary_paths; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.