CycloneDX / specification

OWASP CycloneDX is a full-stack Bill of Materials (BOM) standard that provides advanced supply chain capabilities for cyber risk reduction. SBOM, SaaSBOM, HBOM, AI/ML-BOM, CBOM, OBOM, MBOM, VDR, and VEX
https://cyclonedx.org/
Apache License 2.0
365 stars 59 forks source link

BC: Address problems with v1.5 introducing arrays where items are "oneOf"different types #270

Open mrutkows opened 1 year ago

mrutkows commented 1 year ago

There are issues creating libraries/tools that implement as you need to do quite a bit of additional reflection to determine which "item" datatype to use. This problem is compound where one item is a primitive (e.g., string) and another an object (struct).

I plan to update this issue with all the cases that are (especially) problematic.

"environmentVars": {
          "title": "Environment variables",
          "description": "Inputs that have the form of parameters with names and values.",
          "type": "array",
          "uniqueItems": true,
          "items": {
            "oneOf": [
              {
                "$ref": "#/definitions/property"
              },
              {
                "type": "string"
              }
            ]
          }
   "source": {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "title": "URL",
                "type": "string",
                "format": "iri-reference"
              },
              {
                "title": "BOM-Link Element",
                "$ref": "#/definitions/bomLinkElementType"
              }
            ]
          },

Another issue concerns as "legacy" objects can be removed; however, again we have an array of object vs. a single object with arrays in it.

jkowalleck commented 1 year ago

[...] environmentVars [...]

this is the same as #249, right?

PS: #249's goal is to make environmentVars a dictionary, removing the option for a string entirely.


[...] source [...]

this should be no issue. it is an array of iri-reference. You will see that #/definitions/bomLinkElementType references also iri-reference, but with a regex. So the type is either a iri-reference or a special iri-reference -- so both are iri-reference, right?

however, the "bomLinkElementType" if changed to an "object" could cause typeing problems in impls.

i do not see an object. could you point me to it?

mrutkows commented 1 year ago

@jkowalleck This adds a new perspective/concern in addition to #249

mrutkows commented 1 year ago

this should be no issue. it is an array of iri-reference. You will see that #/definitions/bomLinkElementType references also iri-reference, but with a regex. So the type is either a iri-reference or a special iri-reference -- so both are iri-reference, right?

I acknowledged that both map to "string" now, however, since they are now both named types (definitions) and could easily be turned into "objects" with multiple fields which would cause similar issues.

jkowalleck commented 1 year ago

I acknowledged that both map to "string" now, however, since they are now both named types (definitions) and could easily be turned into "objects" with multiple fields which would cause similar issues.

I do not see any issues NOW nor is there a change for issues in the future. I'd suggest we clarify this in one of the upcoming meetings.

PS: all your concerns would be breaking changes anyway, so I don't see a reason for discussion. Nobody intended to change some "string" to "object". it is just not happening, no matter if "named types" or not ...

dn-scribe commented 10 months ago

Hi, Not sure this is the right place - please redirect me if not.

Wanted to note that there is already an ecosystem of tools that are starting to break due to these "breaking changes"; Take for exmple the Tools section. Syft producse the 1.5-introduced object:

    "metadata": {
        "timestamp": "2024-01-21T08:54:33+02:00",
        "tools": {
            "components": [
                {
                    "type": "application",
                    "author": "anchore",
                    "name": "syft",
                    "version": "0.100.0"
                }
            ]
        },

But tirvy fails on the decoding:

2024-01-21T08:56:33.671+0200    FATAL   sbom scan error: scan error: scan failed: failed analysis: SBOM decode error: failed to decode: CycloneDX decode error: CycloneDX decode error: json: cannot unmarshal object into Go struct field Metadata.metadata.tools of type []cyclonedx.Tool

I recommend trying super-hard to enable backward compatibility.

jkowalleck commented 10 months ago

re: https://github.com/CycloneDX/specification/issues/270#issuecomment-1902537330 @dn-scribe please open an extra issue for your topic. I will hide your post here, as it is off-topic.

PS: the discussion from https://github.com/CycloneDX/specification/issues/270#issuecomment-1902537330 was continued in https://github.com/CycloneDX/specification/issues/364