Problem
Several "validated" domain entities derive Deserialize and expose public fields, allowing validation invariants to be bypassed when instances are created outside their new(...) constructors.
Affected Types
RouteSummary and CommunityPick in the catalogue domain
Tag, Badge, and SafetyToggle in the descriptors domain (generated via macro)
References
backend/src/domain/catalogue/route_summary.rs:34
backend/src/domain/catalogue/route_summary.rs:55
backend/src/domain/catalogue/community_pick.rs:29
backend/src/domain/catalogue/community_pick.rs:47
backend/src/domain/descriptors/mod.rs:72
backend/src/domain/descriptors/mod.rs:85
Impact
Invalid slugs, negative numeric values, or other constraint violations can exist in memory if these types are instantiated via:
- Direct struct construction (public fields)
- JSON/CBOR deserialisation bypassing the constructor
This weakens the "validated domain type" contract and could allow invalid data to propagate through the system.
Possible Solutions
- Remove
Deserialize derives and implement custom deserialisation that delegates to the validating constructor
- Use
#[serde(try_from = "Draft")] pattern (as done for SafetyPreset) to enforce validation during deserialisation
- Make struct fields private and provide only getter methods
- Combine approaches: private fields + custom
TryFrom deserialisation
Related
This issue was flagged during PR #307 code review (catalogue and descriptor domain types).
Problem
Several "validated" domain entities derive
Deserializeand expose public fields, allowing validation invariants to be bypassed when instances are created outside theirnew(...)constructors.Affected Types
RouteSummaryandCommunityPickin the catalogue domainTag,Badge, andSafetyTogglein the descriptors domain (generated via macro)References
backend/src/domain/catalogue/route_summary.rs:34backend/src/domain/catalogue/route_summary.rs:55backend/src/domain/catalogue/community_pick.rs:29backend/src/domain/catalogue/community_pick.rs:47backend/src/domain/descriptors/mod.rs:72backend/src/domain/descriptors/mod.rs:85Impact
Invalid slugs, negative numeric values, or other constraint violations can exist in memory if these types are instantiated via:
This weakens the "validated domain type" contract and could allow invalid data to propagate through the system.
Possible Solutions
Deserializederives and implement custom deserialisation that delegates to the validating constructor#[serde(try_from = "Draft")]pattern (as done forSafetyPreset) to enforce validation during deserialisationTryFromdeserialisationRelated
This issue was flagged during PR #307 code review (catalogue and descriptor domain types).