-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Json/Validator: add findNamedElements() to detect duplicate "bom-ref" definitions #240
base: main
Are you sure you want to change the base?
Conversation
… definitions Signed-off-by: Jim Klimov <jimklimov@gmail.com>
Sonatype Lift is retiringSonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console. |
006f613
to
10fef61
Compare
Now tested and works (complains) as expected! :)
Works reasonably fast (5s for an SBOM with ~1K components), despite the probably inefficient way to handle concatenation in the map of lists (using a single instance instead of passing it around could be faster -- but worse for reusability, parallel exec, etc, and cumbersome for the static-method nature of this class). That said, if there is a way in C# to pass dictionaries by reference, so the whole recursion would manipulate one (caller-provided?) instance of the map, follow-up to optimize this is welcome :) The first hit (for |
…tring representation of the JsonElement, not object (which is in fact unique for each node) Signed-off-by: Jim Klimov <jimklimov@gmail.com>
10fef61
to
3fea2a1
Compare
…ubleshooting Signed-off-by: Jim Klimov <jimklimov@gmail.com>
It would be nice to be able to check the bom-ref uniqueness, thus I appreciate your PR. If we could in addition check whether the bom-refs that are used in the SBOM, for instance in the dependencies section, actually exist, this would be the icing on the cake.
Specify "ref", both on the function definition as well as when calling it, see for instance |
Interesting point about the further checks, but so far I'm too entangled in making the merge work (add a level of spec-based awareness about squashing together equivalent objects with different contents, like different known aspects of same bom-ref after a merge of many docs) - hoping to finish and PR that soon-ish... |
Finally got around to try |
Signed-off-by: Jim Klimov <jimklimov@gmail.com>
And thanks for the suggestion, added a simple check that for each
|
There's also a |
For now I declare the PR done on my side ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, just one issue with it to resolve first.
11b62da
to
aff0ea5
Compare
@jimklimov Just FYI: in version 1.5 much more objects can have a bom-ref. |
What I meant was that as of recently, only |
just a side note, caused by https://cyclonedx.slack.com/archives/CVA0G10FN/p1692519065532109 CDX 1.5 made it pretty clear where a for XML, see the declarations and the usages. with these, you should be able to implement plausibility checks on the |
I'd rather say the Also the codebase I started from did not have a concept (nor a copy) of spec 1.5. Finally, is it right to impose new constraints on older-spec documents? (Do they change something allowed-relaxed before and required now)? |
Fine with me. I'd be happy if the piled up PRs (especially for the cli) were merged, and then we could continue from there. |
Thanks @jkowalleck for the clarification links and @andreas-hilti for suggestion to look at back-references to the Currently investigating if that is the culprit... |
For future reference: locations of bomrefs and bomlinks are highlighted in https://github.com/CycloneDX/specification/pull/236/files |
Signed-off-by: Jim Klimov <jimklimov@gmail.com>
As discussed on Slack, I found that for JSON SBOMs the
cyclonedx-cli validate
does not complain about resulting document fromcyclonedx-cli merge
(which has lots of duplicate "bom-ref" entities). Conversion of that document to XML and validating the result does rightfully fail.The PR below should hopefully fix this, but please note these are my first steps in C# and I have no idea how to force my
cyclonedx-cli
utility to actually build against the custom dll/nupkg created from this codebase. I guess I won't know until this is merged and released :(UPDATE: Now tested, see below.
The code intentionally introduces a method to recursively
findNamedElements(JsonElement element, string name)
so that the same approach can be easily used if more schema elements would be standardized to have unique values across the whole document, and to start iteration from any point in the JSON structure (not necessarily from document root). AFAIK as of the spec version 1.4 (looking at XML XSDxs:unique
constraint) there is just onebom-ref
so far.