CycloneDX / cyclonedx-rust-cargo

Creates CycloneDX Software Bill of Materials (SBOM) from Rust (Cargo) projects
https://cyclonedx.org/
Apache License 2.0
106 stars 44 forks source link

XML de/serialization of `normalizedstring` fields is incorrect #737

Open justahero opened 4 months ago

justahero commented 4 months ago

Based on the findings in #733 it was concluded that the XML serialization code does not parse the XML type normalizedstring correctly. This does not only affect the license name field, but all occurrences of this string type.

There is a NormalizedString type in /external_models available that replaces a set of forbidden characters, e.g. line feed or tab, in NormalizedString::new with white space characters. All XML schemas in the specification repository use this standard XML type normalizedstring, while the JSON schemas do not use such a string type or put any associated restrictions on them. Therefore this type should only apply to the XML serialization code.

The cyclonedx-bom code handles the normalizedstring XML type as a String, only when converting the spec types to their model representations the NormalizedString type is used, but for both JSON and XML parsed objects. That is wrong, the normalizedstring XML type & therefore the NormalizedString model type are only relevant as part of the XML specification & should be used in this context only.

To fix the issue, the code should be adapted in the following way.

These are a lot of changes, but the outcome is

cc @Shnatsel, @lfrancke (thanks & also thanks to all others on Discord for their input)