diff --git a/cve_bin_tool/cli.py b/cve_bin_tool/cli.py index ff50d8a9c2..4cfd2d9390 100644 --- a/cve_bin_tool/cli.py +++ b/cve_bin_tool/cli.py @@ -79,6 +79,7 @@ from cve_bin_tool.version import VERSION from cve_bin_tool.version_scanner import VersionScanner from cve_bin_tool.vex_manager.parse import VEXParse +from cve_bin_tool.vex_manager.validate import validate_vex_file sys.excepthook = excepthook # Always install excepthook for entrypoint module. @@ -394,6 +395,13 @@ def main(argv=None): default=False, help="Filter cves based on triage data from Vex file", ) + vex_output_group.add_argument( + "--vex-file-to-validate", + action="store", + help="VEX file path to validate (used with vex-validate command)", + default="", + ) + parser.add_argument( "-e", "--exclude", @@ -567,11 +575,37 @@ def main(argv=None): default=False, ) + parser.add_argument( + "command", + nargs="?", + choices=["vex-validate"], + help="Command to run: vex-validate to validate VEX files", + ) + + # Change directory to be optional when using commands + input_group.add_argument( + "directory", help="directory to scan", nargs="?", default="" + ) + with ErrorHandler(mode=ErrorMode.NoTrace): raw_args = parser.parse_args(argv[1:]) args = {key: value for key, value in vars(raw_args).items() if value} defaults = {key: parser.get_default(key) for key in vars(raw_args)} + # Handle vex-validate command early + if raw_args.command == "vex-validate": + if not raw_args.vex_file_to_validate and not raw_args.directory: + parser.error( + "vex-validate command requires either --vex-file-to-validate or a VEX file path as directory argument" + ) + + # Use directory as file path if vex_file_to_validate not provided + vex_file_path = raw_args.vex_file_to_validate or raw_args.directory + + # Import and run validation + exit_code = validate_vex_file(vex_file_path, offline=args.get("offline", False)) + return exit_code + configs = {} if args.get("config"): conf = ConfigParser(args["config"]) @@ -741,6 +775,26 @@ def main(argv=None): return 0 + # Handle vex-validate command + if args.get("command") == "vex-validate": + from cve_bin_tool.vex_manager.validate import validate_vex_file + + # Determine VEX file path + vex_file_path = args.get("vex_file_to_validate") or args.get("directory") + + if not vex_file_path: + LOGGER.error( + "Please provide a VEX file path using --vex-file-to-validate or as a positional argument" + ) + parser.print_usage() + return ERROR_CODES[InsufficientArgs] + + # Validate the VEX file + exit_code = validate_vex_file( + vex_file_path, LOGGER, offline=args.get("offline", False) + ) + return exit_code + # Offline processing if args["offline"]: # Override version check and database update arguments @@ -967,11 +1021,12 @@ def main(argv=None): and not args["merge"] and not args["sbom_file"] and not args["vex_file"] + and not raw_args.command ): parser.print_usage() with ErrorHandler(logger=LOGGER, mode=ErrorMode.NoTrace): raise InsufficientArgs( - "Please specify a directory to scan or an input file required" + "Please specify a directory to scan, an input file, or use vex-validate command" ) # Output validation diff --git a/cve_bin_tool/schemas/README.txt b/cve_bin_tool/schemas/README.txt index fda464f6c0..1ab97b0271 100644 --- a/cve_bin_tool/schemas/README.txt +++ b/cve_bin_tool/schemas/README.txt @@ -1,3 +1,21 @@ +CVE Binary Tool Local Schema Files +================================== + +This directory contains local schema files for various formats supported by CVE Binary Tool. +These schemas enable offline validation and faster processing by avoiding network downloads. + +Schema Files: +- bom-1.4.schema.json: CycloneDX BOM format schema +- csaf_json_schema.json: CSAF VEX format schema +- openvex_json_schema.json: OpenVEX format schema +- cyclonedx_gen.xsd: CycloneDX XML schema (generated) +- Various other XSD files for XML validation + +To update schemas, download the latest versions from official sources: +- CycloneDX: https://raw.githubusercontent.com/CycloneDX/specification/master/schema/ +- CSAF: https://raw.githubusercontent.com/oasis-tcs/csaf/master/csaf_2.0/json_schema/ +- OpenVEX: https://raw.githubusercontent.com/openvex/spec/main/.schemas/ + The cyclconedx_gen.xsd is an amalgamation of cyclonedx.xsd and cyclonedx_spdx.xsd. References to spdx namespace in the cyclonedx.xsd is changed to bom. diff --git a/cve_bin_tool/schemas/bom-1.4.schema.json b/cve_bin_tool/schemas/bom-1.4.schema.json new file mode 100644 index 0000000000..f376a42735 --- /dev/null +++ b/cve_bin_tool/schemas/bom-1.4.schema.json @@ -0,0 +1,1697 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://cyclonedx.org/schema/bom-1.4.schema.json", + "type": "object", + "title": "CycloneDX Software Bill of Materials Standard", + "$comment" : "CycloneDX JSON schema is published under the terms of the Apache License 2.0.", + "required": [ + "bomFormat", + "specVersion", + "version" + ], + "additionalProperties": false, + "properties": { + "$schema": { + "type": "string", + "enum": [ + "http://cyclonedx.org/schema/bom-1.4.schema.json" + ] + }, + "bomFormat": { + "type": "string", + "title": "BOM Format", + "description": "Specifies the format of the BOM. This helps to identify the file as CycloneDX since BOMs do not have a filename convention nor does JSON schema support namespaces. This value MUST be \"CycloneDX\".", + "enum": [ + "CycloneDX" + ] + }, + "specVersion": { + "type": "string", + "title": "CycloneDX Specification Version", + "description": "The version of the CycloneDX specification a BOM conforms to (starting at version 1.2).", + "examples": ["1.4"] + }, + "serialNumber": { + "type": "string", + "title": "BOM Serial Number", + "description": "Every BOM generated SHOULD have a unique serial number, even if the contents of the BOM have not changed over time. If specified, the serial number MUST conform to RFC-4122. Use of serial numbers are RECOMMENDED.", + "examples": ["urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79"], + "pattern": "^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" + }, + "version": { + "type": "integer", + "title": "BOM Version", + "description": "Whenever an existing BOM is modified, either manually or through automated processes, the version of the BOM SHOULD be incremented by 1. When a system is presented with multiple BOMs with identical serial numbers, the system SHOULD use the most recent version of the BOM. The default version is '1'.", + "default": 1, + "examples": [1] + }, + "metadata": { + "$ref": "#/definitions/metadata", + "title": "BOM Metadata", + "description": "Provides additional information about a BOM." + }, + "components": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/component"}, + "uniqueItems": true, + "title": "Components", + "description": "A list of software and hardware components." + }, + "services": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/service"}, + "uniqueItems": true, + "title": "Services", + "description": "A list of services. This may include microservices, function-as-a-service, and other types of network or intra-process services." + }, + "externalReferences": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/externalReference"}, + "title": "External References", + "description": "External references provide a way to document systems, sites, and information that may be relevant but which are not included with the BOM." + }, + "dependencies": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/dependency"}, + "uniqueItems": true, + "title": "Dependencies", + "description": "Provides the ability to document dependency relationships." + }, + "compositions": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/compositions"}, + "uniqueItems": true, + "title": "Compositions", + "description": "Compositions describe constituent parts (including components, services, and dependency relationships) and their completeness." + }, + "vulnerabilities": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/vulnerability"}, + "uniqueItems": true, + "title": "Vulnerabilities", + "description": "Vulnerabilities identified in components or services." + }, + "signature": { + "$ref": "#/definitions/signature", + "title": "Signature", + "description": "Enveloped signature in [JSON Signature Format (JSF)](https://cyberphone.github.io/doc/security/jsf.html)." + } + }, + "definitions": { + "refType": { + "$comment": "Identifier-DataType for interlinked elements.", + "type": "string" + }, + "metadata": { + "type": "object", + "title": "BOM Metadata Object", + "additionalProperties": false, + "properties": { + "timestamp": { + "type": "string", + "format": "date-time", + "title": "Timestamp", + "description": "The date and time (timestamp) when the BOM was created." + }, + "tools": { + "type": "array", + "title": "Creation Tools", + "description": "The tool(s) used in the creation of the BOM.", + "additionalItems": false, + "items": {"$ref": "#/definitions/tool"} + }, + "authors" :{ + "type": "array", + "title": "Authors", + "description": "The person(s) who created the BOM. Authors are common in BOMs created through manual processes. BOMs created through automated means may not have authors.", + "additionalItems": false, + "items": {"$ref": "#/definitions/organizationalContact"} + }, + "component": { + "title": "Component", + "description": "The component that the BOM describes.", + "$ref": "#/definitions/component" + }, + "manufacture": { + "title": "Manufacture", + "description": "The organization that manufactured the component that the BOM describes.", + "$ref": "#/definitions/organizationalEntity" + }, + "supplier": { + "title": "Supplier", + "description": " The organization that supplied the component that the BOM describes. The supplier may often be the manufacturer, but may also be a distributor or repackager.", + "$ref": "#/definitions/organizationalEntity" + }, + "licenses": { + "type": "array", + "title": "BOM License(s)", + "additionalItems": false, + "items": {"$ref": "#/definitions/licenseChoice"} + }, + "properties": { + "type": "array", + "title": "Properties", + "description": "Provides the ability to document properties in a name-value store. This provides flexibility to include data not officially supported in the standard without having to use additional namespaces or create extensions. Unlike key-value stores, properties support duplicate names, each potentially having different values. Property names of interest to the general public are encouraged to be registered in the [CycloneDX Property Taxonomy](https://github.com/CycloneDX/cyclonedx-property-taxonomy). Formal registration is OPTIONAL.", + "additionalItems": false, + "items": {"$ref": "#/definitions/property"} + } + } + }, + "tool": { + "type": "object", + "title": "Tool", + "description": "Information about the automated or manual tool used", + "additionalProperties": false, + "properties": { + "vendor": { + "type": "string", + "title": "Tool Vendor", + "description": "The name of the vendor who created the tool" + }, + "name": { + "type": "string", + "title": "Tool Name", + "description": "The name of the tool" + }, + "version": { + "type": "string", + "title": "Tool Version", + "description": "The version of the tool" + }, + "hashes": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/hash"}, + "title": "Hashes", + "description": "The hashes of the tool (if applicable)." + }, + "externalReferences": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/externalReference"}, + "title": "External References", + "description": "External references provide a way to document systems, sites, and information that may be relevant but which are not included with the BOM." + } + } + }, + "organizationalEntity": { + "type": "object", + "title": "Organizational Entity Object", + "description": "", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "title": "Name", + "description": "The name of the organization", + "examples": [ + "Example Inc." + ] + }, + "url": { + "type": "array", + "items": { + "type": "string", + "format": "iri-reference" + }, + "title": "URL", + "description": "The URL of the organization. Multiple URLs are allowed.", + "examples": ["https://example.com"] + }, + "contact": { + "type": "array", + "title": "Contact", + "description": "A contact at the organization. Multiple contacts are allowed.", + "additionalItems": false, + "items": {"$ref": "#/definitions/organizationalContact"} + } + } + }, + "organizationalContact": { + "type": "object", + "title": "Organizational Contact Object", + "description": "", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "title": "Name", + "description": "The name of a contact", + "examples": ["Contact name"] + }, + "email": { + "type": "string", + "format": "idn-email", + "title": "Email Address", + "description": "The email address of the contact.", + "examples": ["firstname.lastname@example.com"] + }, + "phone": { + "type": "string", + "title": "Phone", + "description": "The phone number of the contact.", + "examples": ["800-555-1212"] + } + } + }, + "component": { + "type": "object", + "title": "Component Object", + "required": [ + "type", + "name" + ], + "additionalProperties": false, + "properties": { + "type": { + "type": "string", + "enum": [ + "application", + "framework", + "library", + "container", + "operating-system", + "device", + "firmware", + "file" + ], + "title": "Component Type", + "description": "Specifies the type of component. For software components, classify as application if no more specific appropriate classification is available or cannot be determined for the component. Types include:\n\n* __application__ = A software application. Refer to [https://en.wikipedia.org/wiki/Application_software](https://en.wikipedia.org/wiki/Application_software) for information about applications.\n* __framework__ = A software framework. Refer to [https://en.wikipedia.org/wiki/Software_framework](https://en.wikipedia.org/wiki/Software_framework) for information on how frameworks vary slightly from libraries.\n* __library__ = A software library. Refer to [https://en.wikipedia.org/wiki/Library_(computing)](https://en.wikipedia.org/wiki/Library_(computing))\n for information about libraries. All third-party and open source reusable components will likely be a library. If the library also has key features of a framework, then it should be classified as a framework. If not, or is unknown, then specifying library is RECOMMENDED.\n* __container__ = A packaging and/or runtime format, not specific to any particular technology, which isolates software inside the container from software outside of a container through virtualization technology. Refer to [https://en.wikipedia.org/wiki/OS-level_virtualization](https://en.wikipedia.org/wiki/OS-level_virtualization)\n* __operating-system__ = A software operating system without regard to deployment model (i.e. installed on physical hardware, virtual machine, image, etc) Refer to [https://en.wikipedia.org/wiki/Operating_system](https://en.wikipedia.org/wiki/Operating_system)\n* __device__ = A hardware device such as a processor, or chip-set. A hardware device containing firmware SHOULD include a component for the physical hardware itself, and another component of type 'firmware' or 'operating-system' (whichever is relevant), describing information about the software running on the device.\n See also the list of [known device properties](https://github.com/CycloneDX/cyclonedx-property-taxonomy/blob/main/cdx/device.md).\n* __firmware__ = A special type of software that provides low-level control over a devices hardware. Refer to [https://en.wikipedia.org/wiki/Firmware](https://en.wikipedia.org/wiki/Firmware)\n* __file__ = A computer file. Refer to [https://en.wikipedia.org/wiki/Computer_file](https://en.wikipedia.org/wiki/Computer_file) for information about files.", + "examples": ["library"] + }, + "mime-type": { + "type": "string", + "title": "Mime-Type", + "description": "The optional mime-type of the component. When used on file components, the mime-type can provide additional context about the kind of file being represented such as an image, font, or executable. Some library or framework components may also have an associated mime-type.", + "examples": ["image/jpeg"], + "pattern": "^[-+a-z0-9.]+/[-+a-z0-9.]+$" + }, + "bom-ref": { + "$ref": "#/definitions/refType", + "title": "BOM Reference", + "description": "An optional identifier which can be used to reference the component elsewhere in the BOM. Every bom-ref MUST be unique within the BOM." + }, + "supplier": { + "title": "Component Supplier", + "description": " The organization that supplied the component. The supplier may often be the manufacturer, but may also be a distributor or repackager.", + "$ref": "#/definitions/organizationalEntity" + }, + "author": { + "type": "string", + "title": "Component Author", + "description": "The person(s) or organization(s) that authored the component", + "examples": ["Acme Inc"] + }, + "publisher": { + "type": "string", + "title": "Component Publisher", + "description": "The person(s) or organization(s) that published the component", + "examples": ["Acme Inc"] + }, + "group": { + "type": "string", + "title": "Component Group", + "description": "The grouping name or identifier. This will often be a shortened, single name of the company or project that produced the component, or the source package or domain name. Whitespace and special characters should be avoided. Examples include: apache, org.apache.commons, and apache.org.", + "examples": ["com.acme"] + }, + "name": { + "type": "string", + "title": "Component Name", + "description": "The name of the component. This will often be a shortened, single name of the component. Examples: commons-lang3 and jquery", + "examples": ["tomcat-catalina"] + }, + "version": { + "type": "string", + "title": "Component Version", + "description": "The component version. The version should ideally comply with semantic versioning but is not enforced.", + "examples": ["9.0.14"] + }, + "description": { + "type": "string", + "title": "Component Description", + "description": "Specifies a description for the component" + }, + "scope": { + "type": "string", + "enum": [ + "required", + "optional", + "excluded" + ], + "title": "Component Scope", + "description": "Specifies the scope of the component. If scope is not specified, 'required' scope SHOULD be assumed by the consumer of the BOM.", + "default": "required" + }, + "hashes": { + "type": "array", + "title": "Component Hashes", + "additionalItems": false, + "items": {"$ref": "#/definitions/hash"} + }, + "licenses": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/licenseChoice"}, + "title": "Component License(s)" + }, + "copyright": { + "type": "string", + "title": "Component Copyright", + "description": "A copyright notice informing users of the underlying claims to copyright ownership in a published work.", + "examples": ["Acme Inc"] + }, + "cpe": { + "type": "string", + "title": "Component Common Platform Enumeration (CPE)", + "description": "Specifies a well-formed CPE name that conforms to the CPE 2.2 or 2.3 specification. See [https://nvd.nist.gov/products/cpe](https://nvd.nist.gov/products/cpe)", + "examples": ["cpe:2.3:a:acme:component_framework:-:*:*:*:*:*:*:*"] + }, + "purl": { + "type": "string", + "title": "Component Package URL (purl)", + "description": "Specifies the package-url (purl). The purl, if specified, MUST be valid and conform to the specification defined at: [https://github.com/package-url/purl-spec](https://github.com/package-url/purl-spec)", + "examples": ["pkg:maven/com.acme/tomcat-catalina@9.0.14?packaging=jar"] + }, + "swid": { + "$ref": "#/definitions/swid", + "title": "SWID Tag", + "description": "Specifies metadata and content for [ISO-IEC 19770-2 Software Identification (SWID) Tags](https://www.iso.org/standard/65666.html)." + }, + "modified": { + "type": "boolean", + "title": "Component Modified From Original", + "description": "[Deprecated] - DO NOT USE. This will be removed in a future version. Use the pedigree element instead to supply information on exactly how the component was modified. A boolean value indicating if the component has been modified from the original. A value of true indicates the component is a derivative of the original. A value of false indicates the component has not been modified from the original." + }, + "pedigree": { + "type": "object", + "title": "Component Pedigree", + "description": "Component pedigree is a way to document complex supply chain scenarios where components are created, distributed, modified, redistributed, combined with other components, etc. Pedigree supports viewing this complex chain from the beginning, the end, or anywhere in the middle. It also provides a way to document variants where the exact relation may not be known.", + "additionalProperties": false, + "properties": { + "ancestors": { + "type": "array", + "title": "Ancestors", + "description": "Describes zero or more components in which a component is derived from. This is commonly used to describe forks from existing projects where the forked version contains a ancestor node containing the original component it was forked from. For example, Component A is the original component. Component B is the component being used and documented in the BOM. However, Component B contains a pedigree node with a single ancestor documenting Component A - the original component from which Component B is derived from.", + "additionalItems": false, + "items": {"$ref": "#/definitions/component"} + }, + "descendants": { + "type": "array", + "title": "Descendants", + "description": "Descendants are the exact opposite of ancestors. This provides a way to document all forks (and their forks) of an original or root component.", + "additionalItems": false, + "items": {"$ref": "#/definitions/component"} + }, + "variants": { + "type": "array", + "title": "Variants", + "description": "Variants describe relations where the relationship between the components are not known. For example, if Component A contains nearly identical code to Component B. They are both related, but it is unclear if one is derived from the other, or if they share a common ancestor.", + "additionalItems": false, + "items": {"$ref": "#/definitions/component"} + }, + "commits": { + "type": "array", + "title": "Commits", + "description": "A list of zero or more commits which provide a trail describing how the component deviates from an ancestor, descendant, or variant.", + "additionalItems": false, + "items": {"$ref": "#/definitions/commit"} + }, + "patches": { + "type": "array", + "title": "Patches", + "description": ">A list of zero or more patches describing how the component deviates from an ancestor, descendant, or variant. Patches may be complimentary to commits or may be used in place of commits.", + "additionalItems": false, + "items": {"$ref": "#/definitions/patch"} + }, + "notes": { + "type": "string", + "title": "Notes", + "description": "Notes, observations, and other non-structured commentary describing the components pedigree." + } + } + }, + "externalReferences": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/externalReference"}, + "title": "External References", + "description": "External references provide a way to document systems, sites, and information that may be relevant but which are not included with the BOM." + }, + "components": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/component"}, + "uniqueItems": true, + "title": "Components", + "description": "A list of software and hardware components included in the parent component. This is not a dependency tree. It provides a way to specify a hierarchical representation of component assemblies, similar to system → subsystem → parts assembly in physical supply chains." + }, + "evidence": { + "$ref": "#/definitions/componentEvidence", + "title": "Evidence", + "description": "Provides the ability to document evidence collected through various forms of extraction or analysis." + }, + "releaseNotes": { + "$ref": "#/definitions/releaseNotes", + "title": "Release notes", + "description": "Specifies optional release notes." + }, + "properties": { + "type": "array", + "title": "Properties", + "description": "Provides the ability to document properties in a name-value store. This provides flexibility to include data not officially supported in the standard without having to use additional namespaces or create extensions. Unlike key-value stores, properties support duplicate names, each potentially having different values. Property names of interest to the general public are encouraged to be registered in the [CycloneDX Property Taxonomy](https://github.com/CycloneDX/cyclonedx-property-taxonomy). Formal registration is OPTIONAL.", + "additionalItems": false, + "items": {"$ref": "#/definitions/property"} + }, + "signature": { + "$ref": "#/definitions/signature", + "title": "Signature", + "description": "Enveloped signature in [JSON Signature Format (JSF)](https://cyberphone.github.io/doc/security/jsf.html)." + } + } + }, + "swid": { + "type": "object", + "title": "SWID Tag", + "description": "Specifies metadata and content for ISO-IEC 19770-2 Software Identification (SWID) Tags.", + "required": [ + "tagId", + "name" + ], + "additionalProperties": false, + "properties": { + "tagId": { + "type": "string", + "title": "Tag ID", + "description": "Maps to the tagId of a SoftwareIdentity." + }, + "name": { + "type": "string", + "title": "Name", + "description": "Maps to the name of a SoftwareIdentity." + }, + "version": { + "type": "string", + "title": "Version", + "default": "0.0", + "description": "Maps to the version of a SoftwareIdentity." + }, + "tagVersion": { + "type": "integer", + "title": "Tag Version", + "default": 0, + "description": "Maps to the tagVersion of a SoftwareIdentity." + }, + "patch": { + "type": "boolean", + "title": "Patch", + "default": false, + "description": "Maps to the patch of a SoftwareIdentity." + }, + "text": { + "title": "Attachment text", + "description": "Specifies the metadata and content of the SWID tag.", + "$ref": "#/definitions/attachment" + }, + "url": { + "type": "string", + "title": "URL", + "description": "The URL to the SWID file.", + "format": "iri-reference" + } + } + }, + "attachment": { + "type": "object", + "title": "Attachment", + "description": "Specifies the metadata and content for an attachment.", + "required": [ + "content" + ], + "additionalProperties": false, + "properties": { + "contentType": { + "type": "string", + "title": "Content-Type", + "description": "Specifies the content type of the text. Defaults to text/plain if not specified.", + "default": "text/plain" + }, + "encoding": { + "type": "string", + "title": "Encoding", + "description": "Specifies the optional encoding the text is represented in.", + "enum": [ + "base64" + ] + }, + "content": { + "type": "string", + "title": "Attachment Text", + "description": "The attachment data. Proactive controls such as input validation and sanitization should be employed to prevent misuse of attachment text." + } + } + }, + "hash": { + "type": "object", + "title": "Hash Objects", + "required": [ + "alg", + "content" + ], + "additionalProperties": false, + "properties": { + "alg": { + "$ref": "#/definitions/hash-alg" + }, + "content": { + "$ref": "#/definitions/hash-content" + } + } + }, + "hash-alg": { + "type": "string", + "enum": [ + "MD5", + "SHA-1", + "SHA-256", + "SHA-384", + "SHA-512", + "SHA3-256", + "SHA3-384", + "SHA3-512", + "BLAKE2b-256", + "BLAKE2b-384", + "BLAKE2b-512", + "BLAKE3" + ], + "title": "Hash Algorithm" + }, + "hash-content": { + "type": "string", + "title": "Hash Content (value)", + "examples": ["3942447fac867ae5cdb3229b658f4d48"], + "pattern": "^([a-fA-F0-9]{32}|[a-fA-F0-9]{40}|[a-fA-F0-9]{64}|[a-fA-F0-9]{96}|[a-fA-F0-9]{128})$" + }, + "license": { + "type": "object", + "title": "License Object", + "oneOf": [ + { + "required": ["id"] + }, + { + "required": ["name"] + } + ], + "additionalProperties": false, + "properties": { + "id": { + "$ref": "spdx.schema.json", + "title": "License ID (SPDX)", + "description": "A valid SPDX license ID", + "examples": ["Apache-2.0"] + }, + "name": { + "type": "string", + "title": "License Name", + "description": "If SPDX does not define the license used, this field may be used to provide the license name", + "examples": ["Acme Software License"] + }, + "text": { + "title": "License text", + "description": "An optional way to include the textual content of a license.", + "$ref": "#/definitions/attachment" + }, + "url": { + "type": "string", + "title": "License URL", + "description": "The URL to the license file. If specified, a 'license' externalReference should also be specified for completeness", + "examples": ["https://www.apache.org/licenses/LICENSE-2.0.txt"], + "format": "iri-reference" + } + } + }, + "licenseChoice": { + "type": "object", + "title": "License(s)", + "additionalProperties": false, + "properties": { + "license": { + "$ref": "#/definitions/license" + }, + "expression": { + "type": "string", + "title": "SPDX License Expression", + "examples": [ + "Apache-2.0 AND (MIT OR GPL-2.0-only)", + "GPL-3.0-only WITH Classpath-exception-2.0" + ] + } + }, + "oneOf":[ + { + "required": ["license"] + }, + { + "required": ["expression"] + } + ] + }, + "commit": { + "type": "object", + "title": "Commit", + "description": "Specifies an individual commit", + "additionalProperties": false, + "properties": { + "uid": { + "type": "string", + "title": "UID", + "description": "A unique identifier of the commit. This may be version control specific. For example, Subversion uses revision numbers whereas git uses commit hashes." + }, + "url": { + "type": "string", + "title": "URL", + "description": "The URL to the commit. This URL will typically point to a commit in a version control system.", + "format": "iri-reference" + }, + "author": { + "title": "Author", + "description": "The author who created the changes in the commit", + "$ref": "#/definitions/identifiableAction" + }, + "committer": { + "title": "Committer", + "description": "The person who committed or pushed the commit", + "$ref": "#/definitions/identifiableAction" + }, + "message": { + "type": "string", + "title": "Message", + "description": "The text description of the contents of the commit" + } + } + }, + "patch": { + "type": "object", + "title": "Patch", + "description": "Specifies an individual patch", + "required": [ + "type" + ], + "additionalProperties": false, + "properties": { + "type": { + "type": "string", + "enum": [ + "unofficial", + "monkey", + "backport", + "cherry-pick" + ], + "title": "Type", + "description": "Specifies the purpose for the patch including the resolution of defects, security issues, or new behavior or functionality.\n\n* __unofficial__ = A patch which is not developed by the creators or maintainers of the software being patched. Refer to [https://en.wikipedia.org/wiki/Unofficial_patch](https://en.wikipedia.org/wiki/Unofficial_patch)\n* __monkey__ = A patch which dynamically modifies runtime behavior. Refer to [https://en.wikipedia.org/wiki/Monkey_patch](https://en.wikipedia.org/wiki/Monkey_patch)\n* __backport__ = A patch which takes code from a newer version of software and applies it to older versions of the same software. Refer to [https://en.wikipedia.org/wiki/Backporting](https://en.wikipedia.org/wiki/Backporting)\n* __cherry-pick__ = A patch created by selectively applying commits from other versions or branches of the same software." + }, + "diff": { + "title": "Diff", + "description": "The patch file (or diff) that show changes. Refer to [https://en.wikipedia.org/wiki/Diff](https://en.wikipedia.org/wiki/Diff)", + "$ref": "#/definitions/diff" + }, + "resolves": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/issue"}, + "title": "Resolves", + "description": "A collection of issues the patch resolves" + } + } + }, + "diff": { + "type": "object", + "title": "Diff", + "description": "The patch file (or diff) that show changes. Refer to https://en.wikipedia.org/wiki/Diff", + "additionalProperties": false, + "properties": { + "text": { + "title": "Diff text", + "description": "Specifies the optional text of the diff", + "$ref": "#/definitions/attachment" + }, + "url": { + "type": "string", + "title": "URL", + "description": "Specifies the URL to the diff", + "format": "iri-reference" + } + } + }, + "issue": { + "type": "object", + "title": "Diff", + "description": "An individual issue that has been resolved.", + "required": [ + "type" + ], + "additionalProperties": false, + "properties": { + "type": { + "type": "string", + "enum": [ + "defect", + "enhancement", + "security" + ], + "title": "Type", + "description": "Specifies the type of issue" + }, + "id": { + "type": "string", + "title": "ID", + "description": "The identifier of the issue assigned by the source of the issue" + }, + "name": { + "type": "string", + "title": "Name", + "description": "The name of the issue" + }, + "description": { + "type": "string", + "title": "Description", + "description": "A description of the issue" + }, + "source": { + "type": "object", + "title": "Source", + "description": "The source of the issue where it is documented", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "title": "Name", + "description": "The name of the source. For example 'National Vulnerability Database', 'NVD', and 'Apache'" + }, + "url": { + "type": "string", + "title": "URL", + "description": "The url of the issue documentation as provided by the source", + "format": "iri-reference" + } + } + }, + "references": { + "type": "array", + "items": { + "type": "string", + "format": "iri-reference" + }, + "title": "References", + "description": "A collection of URL's for reference. Multiple URLs are allowed.", + "examples": ["https://example.com"] + } + } + }, + "identifiableAction": { + "type": "object", + "title": "Identifiable Action", + "description": "Specifies an individual commit", + "additionalProperties": false, + "properties": { + "timestamp": { + "type": "string", + "format": "date-time", + "title": "Timestamp", + "description": "The timestamp in which the action occurred" + }, + "name": { + "type": "string", + "title": "Name", + "description": "The name of the individual who performed the action" + }, + "email": { + "type": "string", + "format": "idn-email", + "title": "E-mail", + "description": "The email address of the individual who performed the action" + } + } + }, + "externalReference": { + "type": "object", + "title": "External Reference", + "description": "Specifies an individual external reference", + "required": [ + "url", + "type" + ], + "additionalProperties": false, + "properties": { + "url": { + "type": "string", + "title": "URL", + "description": "The URL to the external reference", + "format": "iri-reference" + }, + "comment": { + "type": "string", + "title": "Comment", + "description": "An optional comment describing the external reference" + }, + "type": { + "type": "string", + "title": "Type", + "description": "Specifies the type of external reference. There are built-in types to describe common references. If a type does not exist for the reference being referred to, use the \"other\" type.", + "enum": [ + "vcs", + "issue-tracker", + "website", + "advisories", + "bom", + "mailing-list", + "social", + "chat", + "documentation", + "support", + "distribution", + "license", + "build-meta", + "build-system", + "release-notes", + "other" + ] + }, + "hashes": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/hash"}, + "title": "Hashes", + "description": "The hashes of the external reference (if applicable)." + } + } + }, + "dependency": { + "type": "object", + "title": "Dependency", + "description": "Defines the direct dependencies of a component. Components that do not have their own dependencies MUST be declared as empty elements within the graph. Components that are not represented in the dependency graph MAY have unknown dependencies. It is RECOMMENDED that implementations assume this to be opaque and not an indicator of a component being dependency-free.", + "required": [ + "ref" + ], + "additionalProperties": false, + "properties": { + "ref": { + "$ref": "#/definitions/refType", + "title": "Reference", + "description": "References a component by the components bom-ref attribute" + }, + "dependsOn": { + "type": "array", + "uniqueItems": true, + "additionalItems": false, + "items": { + "$ref": "#/definitions/refType" + }, + "title": "Depends On", + "description": "The bom-ref identifiers of the components that are dependencies of this dependency object." + } + } + }, + "service": { + "type": "object", + "title": "Service Object", + "required": [ + "name" + ], + "additionalProperties": false, + "properties": { + "bom-ref": { + "$ref": "#/definitions/refType", + "title": "BOM Reference", + "description": "An optional identifier which can be used to reference the service elsewhere in the BOM. Every bom-ref MUST be unique within the BOM." + }, + "provider": { + "title": "Provider", + "description": "The organization that provides the service.", + "$ref": "#/definitions/organizationalEntity" + }, + "group": { + "type": "string", + "title": "Service Group", + "description": "The grouping name, namespace, or identifier. This will often be a shortened, single name of the company or project that produced the service or domain name. Whitespace and special characters should be avoided.", + "examples": ["com.acme"] + }, + "name": { + "type": "string", + "title": "Service Name", + "description": "The name of the service. This will often be a shortened, single name of the service.", + "examples": ["ticker-service"] + }, + "version": { + "type": "string", + "title": "Service Version", + "description": "The service version.", + "examples": ["1.0.0"] + }, + "description": { + "type": "string", + "title": "Service Description", + "description": "Specifies a description for the service" + }, + "endpoints": { + "type": "array", + "items": { + "type": "string", + "format": "iri-reference" + }, + "title": "Endpoints", + "description": "The endpoint URIs of the service. Multiple endpoints are allowed.", + "examples": ["https://example.com/api/v1/ticker"] + }, + "authenticated": { + "type": "boolean", + "title": "Authentication Required", + "description": "A boolean value indicating if the service requires authentication. A value of true indicates the service requires authentication prior to use. A value of false indicates the service does not require authentication." + }, + "x-trust-boundary": { + "type": "boolean", + "title": "Crosses Trust Boundary", + "description": "A boolean value indicating if use of the service crosses a trust zone or boundary. A value of true indicates that by using the service, a trust boundary is crossed. A value of false indicates that by using the service, a trust boundary is not crossed." + }, + "data": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/dataClassification"}, + "title": "Data Classification", + "description": "Specifies the data classification." + }, + "licenses": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/licenseChoice"}, + "title": "Component License(s)" + }, + "externalReferences": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/externalReference"}, + "title": "External References", + "description": "External references provide a way to document systems, sites, and information that may be relevant but which are not included with the BOM." + }, + "services": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/service"}, + "uniqueItems": true, + "title": "Services", + "description": "A list of services included or deployed behind the parent service. This is not a dependency tree. It provides a way to specify a hierarchical representation of service assemblies." + }, + "releaseNotes": { + "$ref": "#/definitions/releaseNotes", + "title": "Release notes", + "description": "Specifies optional release notes." + }, + "properties": { + "type": "array", + "title": "Properties", + "description": "Provides the ability to document properties in a name-value store. This provides flexibility to include data not officially supported in the standard without having to use additional namespaces or create extensions. Unlike key-value stores, properties support duplicate names, each potentially having different values. Property names of interest to the general public are encouraged to be registered in the [CycloneDX Property Taxonomy](https://github.com/CycloneDX/cyclonedx-property-taxonomy). Formal registration is OPTIONAL.", + "additionalItems": false, + "items": {"$ref": "#/definitions/property"} + }, + "signature": { + "$ref": "#/definitions/signature", + "title": "Signature", + "description": "Enveloped signature in [JSON Signature Format (JSF)](https://cyberphone.github.io/doc/security/jsf.html)." + } + } + }, + "dataClassification": { + "type": "object", + "title": "Hash Objects", + "required": [ + "flow", + "classification" + ], + "additionalProperties": false, + "properties": { + "flow": { + "$ref": "#/definitions/dataFlow", + "title": "Directional Flow", + "description": "Specifies the flow direction of the data. Direction is relative to the service. Inbound flow states that data enters the service. Outbound flow states that data leaves the service. Bi-directional states that data flows both ways, and unknown states that the direction is not known." + }, + "classification": { + "type": "string", + "title": "Classification", + "description": "Data classification tags data according to its type, sensitivity, and value if altered, stolen, or destroyed." + } + } + }, + "dataFlow": { + "type": "string", + "enum": [ + "inbound", + "outbound", + "bi-directional", + "unknown" + ], + "title": "Data flow direction", + "description": "Specifies the flow direction of the data. Direction is relative to the service. Inbound flow states that data enters the service. Outbound flow states that data leaves the service. Bi-directional states that data flows both ways, and unknown states that the direction is not known." + }, + + "copyright": { + "type": "object", + "title": "Copyright", + "required": [ + "text" + ], + "additionalProperties": false, + "properties": { + "text": { + "type": "string", + "title": "Copyright Text" + } + } + }, + + "componentEvidence": { + "type": "object", + "title": "Evidence", + "description": "Provides the ability to document evidence collected through various forms of extraction or analysis.", + "additionalProperties": false, + "properties": { + "licenses": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/licenseChoice"}, + "title": "Component License(s)" + }, + "copyright": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/copyright"}, + "title": "Copyright" + } + } + }, + "compositions": { + "type": "object", + "title": "Compositions", + "required": [ + "aggregate" + ], + "additionalProperties": false, + "properties": { + "aggregate": { + "$ref": "#/definitions/aggregateType", + "title": "Aggregate", + "description": "Specifies an aggregate type that describe how complete a relationship is." + }, + "assemblies": { + "type": "array", + "uniqueItems": true, + "items": { + "type": "string" + }, + "title": "BOM references", + "description": "The bom-ref identifiers of the components or services being described. Assemblies refer to nested relationships whereby a constituent part may include other constituent parts. References do not cascade to child parts. References are explicit for the specified constituent part only." + }, + "dependencies": { + "type": "array", + "uniqueItems": true, + "items": { + "type": "string" + }, + "title": "BOM references", + "description": "The bom-ref identifiers of the components or services being described. Dependencies refer to a relationship whereby an independent constituent part requires another independent constituent part. References do not cascade to transitive dependencies. References are explicit for the specified dependency only." + }, + "signature": { + "$ref": "#/definitions/signature", + "title": "Signature", + "description": "Enveloped signature in [JSON Signature Format (JSF)](https://cyberphone.github.io/doc/security/jsf.html)." + } + } + }, + "aggregateType": { + "type": "string", + "default": "not_specified", + "enum": [ + "complete", + "incomplete", + "incomplete_first_party_only", + "incomplete_third_party_only", + "unknown", + "not_specified" + ] + }, + "property": { + "type": "object", + "title": "Lightweight name-value pair", + "properties": { + "name": { + "type": "string", + "title": "Name", + "description": "The name of the property. Duplicate names are allowed, each potentially having a different value." + }, + "value": { + "type": "string", + "title": "Value", + "description": "The value of the property." + } + } + }, + "localeType": { + "type": "string", + "pattern": "^([a-z]{2})(-[A-Z]{2})?$", + "title": "Locale", + "description": "Defines a syntax for representing two character language code (ISO-639) followed by an optional two character country code. The language code MUST be lower case. If the country code is specified, the country code MUST be upper case. The language code and country code MUST be separated by a minus sign. Examples: en, en-US, fr, fr-CA" + }, + "releaseType": { + "type": "string", + "examples": [ + "major", + "minor", + "patch", + "pre-release", + "internal" + ], + "description": "The software versioning type. It is RECOMMENDED that the release type use one of 'major', 'minor', 'patch', 'pre-release', or 'internal'. Representing all possible software release types is not practical, so standardizing on the recommended values, whenever possible, is strongly encouraged.\n\n* __major__ = A major release may contain significant changes or may introduce breaking changes.\n* __minor__ = A minor release, also known as an update, may contain a smaller number of changes than major releases.\n* __patch__ = Patch releases are typically unplanned and may resolve defects or important security issues.\n* __pre-release__ = A pre-release may include alpha, beta, or release candidates and typically have limited support. They provide the ability to preview a release prior to its general availability.\n* __internal__ = Internal releases are not for public consumption and are intended to be used exclusively by the project or manufacturer that produced it." + }, + "note": { + "type": "object", + "title": "Note", + "description": "A note containing the locale and content.", + "required": [ + "text" + ], + "additionalProperties": false, + "properties": { + "locale": { + "$ref": "#/definitions/localeType", + "title": "Locale", + "description": "The ISO-639 (or higher) language code and optional ISO-3166 (or higher) country code. Examples include: \"en\", \"en-US\", \"fr\" and \"fr-CA\"" + }, + "text": { + "title": "Release note content", + "description": "Specifies the full content of the release note.", + "$ref": "#/definitions/attachment" + } + } + }, + "releaseNotes": { + "type": "object", + "title": "Release notes", + "required": [ + "type" + ], + "additionalProperties": false, + "properties": { + "type": { + "$ref": "#/definitions/releaseType", + "title": "Type", + "description": "The software versioning type the release note describes." + }, + "title": { + "type": "string", + "title": "Title", + "description": "The title of the release." + }, + "featuredImage": { + "type": "string", + "format": "iri-reference", + "title": "Featured image", + "description": "The URL to an image that may be prominently displayed with the release note." + }, + "socialImage": { + "type": "string", + "format": "iri-reference", + "title": "Social image", + "description": "The URL to an image that may be used in messaging on social media platforms." + }, + "description": { + "type": "string", + "title": "Description", + "description": "A short description of the release." + }, + "timestamp": { + "type": "string", + "format": "date-time", + "title": "Timestamp", + "description": "The date and time (timestamp) when the release note was created." + }, + "aliases": { + "type": "array", + "items": { + "type": "string" + }, + "title": "Aliases", + "description": "One or more alternate names the release may be referred to. This may include unofficial terms used by development and marketing teams (e.g. code names)." + }, + "tags": { + "type": "array", + "items": { + "type": "string" + }, + "title": "Tags", + "description": "One or more tags that may aid in search or retrieval of the release note." + }, + "resolves": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/issue"}, + "title": "Resolves", + "description": "A collection of issues that have been resolved." + }, + "notes": { + "type": "array", + "additionalItems": false, + "items": {"$ref": "#/definitions/note"}, + "title": "Notes", + "description": "Zero or more release notes containing the locale and content. Multiple note objects may be specified to support release notes in a wide variety of languages." + }, + "properties": { + "type": "array", + "title": "Properties", + "description": "Provides the ability to document properties in a name-value store. This provides flexibility to include data not officially supported in the standard without having to use additional namespaces or create extensions. Unlike key-value stores, properties support duplicate names, each potentially having different values. Property names of interest to the general public are encouraged to be registered in the [CycloneDX Property Taxonomy](https://github.com/CycloneDX/cyclonedx-property-taxonomy). Formal registration is OPTIONAL.", + "additionalItems": false, + "items": {"$ref": "#/definitions/property"} + } + } + }, + "advisory": { + "type": "object", + "title": "Advisory", + "description": "Title and location where advisory information can be obtained. An advisory is a notification of a threat to a component, service, or system.", + "required": ["url"], + "additionalProperties": false, + "properties": { + "title": { + "type": "string", + "title": "Title", + "description": "An optional name of the advisory." + }, + "url": { + "type": "string", + "title": "URL", + "format": "iri-reference", + "description": "Location where the advisory can be obtained." + } + } + }, + "cwe": { + "type": "integer", + "minimum": 1, + "title": "CWE", + "description": "Integer representation of a Common Weaknesses Enumerations (CWE). For example 399 (of https://cwe.mitre.org/data/definitions/399.html)" + }, + "severity": { + "type": "string", + "title": "Severity", + "description": "Textual representation of the severity of the vulnerability adopted by the analysis method. If the analysis method uses values other than what is provided, the user is expected to translate appropriately.", + "enum": [ + "critical", + "high", + "medium", + "low", + "info", + "none", + "unknown" + ] + }, + "scoreMethod": { + "type": "string", + "title": "Method", + "description": "Specifies the severity or risk scoring methodology or standard used.\n\n* CVSSv2 - [Common Vulnerability Scoring System v2](https://www.first.org/cvss/v2/)\n* CVSSv3 - [Common Vulnerability Scoring System v3](https://www.first.org/cvss/v3-0/)\n* CVSSv31 - [Common Vulnerability Scoring System v3.1](https://www.first.org/cvss/v3-1/)\n* OWASP - [OWASP Risk Rating Methodology](https://owasp.org/www-community/OWASP_Risk_Rating_Methodology)", + "enum": [ + "CVSSv2", + "CVSSv3", + "CVSSv31", + "OWASP", + "other" + ] + }, + "impactAnalysisState": { + "type": "string", + "title": "Impact Analysis State", + "description": "Declares the current state of an occurrence of a vulnerability, after automated or manual analysis. \n\n* __resolved__ = the vulnerability has been remediated. \n* __resolved\\_with\\_pedigree__ = the vulnerability has been remediated and evidence of the changes are provided in the affected components pedigree containing verifiable commit history and/or diff(s). \n* __exploitable__ = the vulnerability may be directly or indirectly exploitable. \n* __in\\_triage__ = the vulnerability is being investigated. \n* __false\\_positive__ = the vulnerability is not specific to the component or service and was falsely identified or associated. \n* __not\\_affected__ = the component or service is not affected by the vulnerability. Justification should be specified for all not_affected cases.", + "enum": [ + "resolved", + "resolved_with_pedigree", + "exploitable", + "in_triage", + "false_positive", + "not_affected" + ] + }, + "impactAnalysisJustification": { + "type": "string", + "title": "Impact Analysis Justification", + "description": "The rationale of why the impact analysis state was asserted. \n\n* __code\\_not\\_present__ = the code has been removed or tree-shaked. \n* __code\\_not\\_reachable__ = the vulnerable code is not invoked at runtime. \n* __requires\\_configuration__ = exploitability requires a configurable option to be set/unset. \n* __requires\\_dependency__ = exploitability requires a dependency that is not present. \n* __requires\\_environment__ = exploitability requires a certain environment which is not present. \n* __protected\\_by\\_compiler__ = exploitability requires a compiler flag to be set/unset. \n* __protected\\_at\\_runtime__ = exploits are prevented at runtime. \n* __protected\\_at\\_perimeter__ = attacks are blocked at physical, logical, or network perimeter. \n* __protected\\_by\\_mitigating\\_control__ = preventative measures have been implemented that reduce the likelihood and/or impact of the vulnerability.", + "enum": [ + "code_not_present", + "code_not_reachable", + "requires_configuration", + "requires_dependency", + "requires_environment", + "protected_by_compiler", + "protected_at_runtime", + "protected_at_perimeter", + "protected_by_mitigating_control" + ] + }, + "rating": { + "type": "object", + "title": "Rating", + "description": "Defines the severity or risk ratings of a vulnerability.", + "additionalProperties": false, + "properties": { + "source": { + "$ref": "#/definitions/vulnerabilitySource", + "description": "The source that calculated the severity or risk rating of the vulnerability." + }, + "score": { + "type": "number", + "title": "Score", + "description": "The numerical score of the rating." + }, + "severity": { + "$ref": "#/definitions/severity", + "description": "Textual representation of the severity that corresponds to the numerical score of the rating." + }, + "method": { + "$ref": "#/definitions/scoreMethod" + }, + "vector": { + "type": "string", + "title": "Vector", + "description": "Textual representation of the metric values used to score the vulnerability" + }, + "justification": { + "type": "string", + "title": "Justification", + "description": "An optional reason for rating the vulnerability as it was" + } + } + }, + "vulnerabilitySource": { + "type": "object", + "title": "Source", + "description": "The source of vulnerability information. This is often the organization that published the vulnerability.", + "additionalProperties": false, + "properties": { + "url": { + "type": "string", + "title": "URL", + "description": "The url of the vulnerability documentation as provided by the source.", + "examples": [ + "https://nvd.nist.gov/vuln/detail/CVE-2021-39182" + ] + }, + "name": { + "type": "string", + "title": "Name", + "description": "The name of the source.", + "examples": [ + "NVD", + "National Vulnerability Database", + "OSS Index", + "VulnDB", + "GitHub Advisories" + ] + } + } + }, + "vulnerability": { + "type": "object", + "title": "Vulnerability", + "description": "Defines a weakness in an component or service that could be exploited or triggered by a threat source.", + "additionalProperties": false, + "properties": { + "bom-ref": { + "$ref": "#/definitions/refType", + "title": "BOM Reference", + "description": "An optional identifier which can be used to reference the vulnerability elsewhere in the BOM. Every bom-ref MUST be unique within the BOM." + }, + "id": { + "type": "string", + "title": "ID", + "description": "The identifier that uniquely identifies the vulnerability.", + "examples": [ + "CVE-2021-39182", + "GHSA-35m5-8cvj-8783", + "SNYK-PYTHON-ENROCRYPT-1912876" + ] + }, + "source": { + "$ref": "#/definitions/vulnerabilitySource", + "description": "The source that published the vulnerability." + }, + "references": { + "type": "array", + "title": "References", + "description": "Zero or more pointers to vulnerabilities that are the equivalent of the vulnerability specified. Often times, the same vulnerability may exist in multiple sources of vulnerability intelligence, but have different identifiers. References provide a way to correlate vulnerabilities across multiple sources of vulnerability intelligence.", + "additionalItems": false, + "items": { + "required": [ + "id", + "source" + ], + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "title": "ID", + "description": "An identifier that uniquely identifies the vulnerability.", + "examples": [ + "CVE-2021-39182", + "GHSA-35m5-8cvj-8783", + "SNYK-PYTHON-ENROCRYPT-1912876" + ] + }, + "source": { + "$ref": "#/definitions/vulnerabilitySource", + "description": "The source that published the vulnerability." + } + } + } + }, + "ratings": { + "type": "array", + "title": "Ratings", + "description": "List of vulnerability ratings", + "additionalItems": false, + "items": { + "$ref": "#/definitions/rating" + } + }, + "cwes": { + "type": "array", + "title": "CWEs", + "description": "List of Common Weaknesses Enumerations (CWEs) codes that describes this vulnerability. For example 399 (of https://cwe.mitre.org/data/definitions/399.html)", + "examples": [399], + "additionalItems": false, + "items": { + "$ref": "#/definitions/cwe" + } + }, + "description": { + "type": "string", + "title": "Description", + "description": "A description of the vulnerability as provided by the source." + }, + "detail": { + "type": "string", + "title": "Details", + "description": "If available, an in-depth description of the vulnerability as provided by the source organization. Details often include examples, proof-of-concepts, and other information useful in understanding root cause." + }, + "recommendation": { + "type": "string", + "title": "Details", + "description": "Recommendations of how the vulnerability can be remediated or mitigated." + }, + "advisories": { + "type": "array", + "title": "Advisories", + "description": "Published advisories of the vulnerability if provided.", + "additionalItems": false, + "items": { + "$ref": "#/definitions/advisory" + } + }, + "created": { + "type": "string", + "format": "date-time", + "title": "Created", + "description": "The date and time (timestamp) when the vulnerability record was created in the vulnerability database." + }, + "published": { + "type": "string", + "format": "date-time", + "title": "Published", + "description": "The date and time (timestamp) when the vulnerability record was first published." + }, + "updated": { + "type": "string", + "format": "date-time", + "title": "Updated", + "description": "The date and time (timestamp) when the vulnerability record was last updated." + }, + "credits": { + "type": "object", + "title": "Credits", + "description": "Individuals or organizations credited with the discovery of the vulnerability.", + "additionalProperties": false, + "properties": { + "organizations": { + "type": "array", + "title": "Organizations", + "description": "The organizations credited with vulnerability discovery.", + "additionalItems": false, + "items": { + "$ref": "#/definitions/organizationalEntity" + } + }, + "individuals": { + "type": "array", + "title": "Individuals", + "description": "The individuals, not associated with organizations, that are credited with vulnerability discovery.", + "additionalItems": false, + "items": { + "$ref": "#/definitions/organizationalContact" + } + } + } + }, + "tools": { + "type": "array", + "title": "Creation Tools", + "description": "The tool(s) used to identify, confirm, or score the vulnerability.", + "additionalItems": false, + "items": {"$ref": "#/definitions/tool"} + }, + "analysis": { + "type": "object", + "title": "Impact Analysis", + "description": "An assessment of the impact and exploitability of the vulnerability.", + "additionalProperties": false, + "properties": { + "state": { + "$ref": "#/definitions/impactAnalysisState" + }, + "justification": { + "$ref": "#/definitions/impactAnalysisJustification" + }, + "response": { + "type": "array", + "title": "Response", + "description": "A response to the vulnerability by the manufacturer, supplier, or project responsible for the affected component or service. More than one response is allowed. Responses are strongly encouraged for vulnerabilities where the analysis state is exploitable.", + "additionalItems": false, + "items": { + "type": "string", + "enum": [ + "can_not_fix", + "will_not_fix", + "update", + "rollback", + "workaround_available" + ] + } + }, + "detail": { + "type": "string", + "title": "Detail", + "description": "Detailed description of the impact including methods used during assessment. If a vulnerability is not exploitable, this field should include specific details on why the component or service is not impacted by this vulnerability." + } + } + }, + "affects": { + "type": "array", + "uniqueItems": true, + "additionalItems": false, + "items": { + "required": [ + "ref" + ], + "additionalProperties": false, + "properties": { + "ref": { + "$ref": "#/definitions/refType", + "title": "Reference", + "description": "References a component or service by the objects bom-ref" + }, + "versions": { + "type": "array", + "title": "Versions", + "description": "Zero or more individual versions or range of versions.", + "additionalItems": false, + "items": { + "oneOf": [ + { + "required": ["version"] + }, + { + "required": ["range"] + } + ], + "additionalProperties": false, + "properties": { + "version": { + "description": "A single version of a component or service.", + "$ref": "#/definitions/version" + }, + "range": { + "description": "A version range specified in Package URL Version Range syntax (vers) which is defined at https://github.com/package-url/purl-spec/blob/master/VERSION-RANGE-SPEC.rst", + "$ref": "#/definitions/range" + }, + "status": { + "description": "The vulnerability status for the version or range of versions.", + "$ref": "#/definitions/affectedStatus", + "default": "affected" + } + } + } + } + } + }, + "title": "Affects", + "description": "The components or services that are affected by the vulnerability." + }, + "properties": { + "type": "array", + "title": "Properties", + "description": "Provides the ability to document properties in a name-value store. This provides flexibility to include data not officially supported in the standard without having to use additional namespaces or create extensions. Unlike key-value stores, properties support duplicate names, each potentially having different values. Property names of interest to the general public are encouraged to be registered in the [CycloneDX Property Taxonomy](https://github.com/CycloneDX/cyclonedx-property-taxonomy). Formal registration is OPTIONAL.", + "additionalItems": false, + "items": { + "$ref": "#/definitions/property" + } + } + } + }, + "affectedStatus": { + "description": "The vulnerability status of a given version or range of versions of a product. The statuses 'affected' and 'unaffected' indicate that the version is affected or unaffected by the vulnerability. The status 'unknown' indicates that it is unknown or unspecified whether the given version is affected. There can be many reasons for an 'unknown' status, including that an investigation has not been undertaken or that a vendor has not disclosed the status.", + "type": "string", + "enum": [ + "affected", + "unaffected", + "unknown" + ] + }, + "version": { + "description": "A single version of a component or service.", + "type": "string", + "minLength": 1, + "maxLength": 1024 + }, + "range": { + "description": "A version range specified in Package URL Version Range syntax (vers) which is defined at https://github.com/package-url/purl-spec/blob/master/VERSION-RANGE-SPEC.rst", + "type": "string", + "minLength": 1, + "maxLength": 1024 + }, + "signature": { + "$ref": "jsf-0.82.schema.json#/definitions/signature", + "title": "Signature", + "description": "Enveloped signature in [JSON Signature Format (JSF)](https://cyberphone.github.io/doc/security/jsf.html)." + } + } +} diff --git a/cve_bin_tool/schemas/csaf_json_schema.json b/cve_bin_tool/schemas/csaf_json_schema.json new file mode 100644 index 0000000000..93ff152a2c --- /dev/null +++ b/cve_bin_tool/schemas/csaf_json_schema.json @@ -0,0 +1,1414 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://docs.oasis-open.org/csaf/csaf/v2.0/csaf_json_schema.json", + "title": "Common Security Advisory Framework", + "description": "Representation of security advisory information as a JSON document.", + "type": "object", + "$defs": { + "acknowledgments_t": { + "title": "List of acknowledgments", + "description": "Contains a list of acknowledgment elements.", + "type": "array", + "minItems": 1, + "items": { + "title": "Acknowledgment", + "description": "Acknowledges contributions by describing those that contributed.", + "type": "object", + "minProperties": 1, + "properties": { + "names": { + "title": "List of acknowledged names", + "description": "Contains the names of contributors being recognized.", + "type": "array", + "minItems": 1, + "items": { + "title": "Name of the contributor", + "description": "Contains the name of a single contributor being recognized.", + "type": "string", + "minLength": 1, + "examples": [ + "Albert Einstein", + "Johann Sebastian Bach" + ] + } + }, + "organization": { + "title": "Contributing organization", + "description": "Contains the name of a contributing organization being recognized.", + "type": "string", + "minLength": 1, + "examples": [ + "CISA", + "Google Project Zero", + "Talos" + ] + }, + "summary": { + "title": "Summary of the acknowledgment", + "description": "SHOULD represent any contextual details the document producers wish to make known about the acknowledgment or acknowledged parties.", + "type": "string", + "minLength": 1, + "examples": [ + "First analysis of Coordinated Multi-Stream Attack (CMSA)" + ] + }, + "urls": { + "title": "List of URLs", + "description": "Specifies a list of URLs or location of the reference to be acknowledged.", + "type": "array", + "minItems": 1, + "items": { + "title": "URL of acknowledgment", + "description": "Contains the URL or location of the reference to be acknowledged.", + "type": "string", + "format": "uri" + } + } + } + } + }, + "branches_t": { + "title": "List of branches", + "description": "Contains branch elements as children of the current element.", + "type": "array", + "minItems": 1, + "items": { + "title": "Branch", + "description": "Is a part of the hierarchical structure of the product tree.", + "type": "object", + "maxProperties": 3, + "minProperties": 3, + "required": [ + "category", + "name" + ], + "properties": { + "branches": { + "$ref": "#/$defs/branches_t" + }, + "category": { + "title": "Category of the branch", + "description": "Describes the characteristics of the labeled branch.", + "type": "string", + "enum": [ + "architecture", + "host_name", + "language", + "legacy", + "patch_level", + "product_family", + "product_name", + "product_version", + "product_version_range", + "service_pack", + "specification", + "vendor" + ] + }, + "name": { + "title": "Name of the branch", + "description": "Contains the canonical descriptor or 'friendly name' of the branch.", + "type": "string", + "minLength": 1, + "examples": [ + "10", + "365", + "Microsoft", + "Office", + "PCS 7", + "SIMATIC", + "Siemens", + "Windows" + ] + }, + "product": { + "$ref": "#/$defs/full_product_name_t" + } + } + } + }, + "full_product_name_t": { + "title": "Full product name", + "description": "Specifies information about the product and assigns the product_id.", + "type": "object", + "required": [ + "name", + "product_id" + ], + "properties": { + "name": { + "title": "Textual description of the product", + "description": "The value should be the product’s full canonical name, including version number and other attributes, as it would be used in a human-friendly document.", + "type": "string", + "minLength": 1, + "examples": [ + "Cisco AnyConnect Secure Mobility Client 2.3.185", + "Microsoft Host Integration Server 2006 Service Pack 1" + ] + }, + "product_id": { + "$ref": "#/$defs/product_id_t" + }, + "product_identification_helper": { + "title": "Helper to identify the product", + "description": "Provides at least one method which aids in identifying the product in an asset database.", + "type": "object", + "minProperties": 1, + "properties": { + "cpe": { + "title": "Common Platform Enumeration representation", + "description": "The Common Platform Enumeration (CPE) attribute refers to a method for naming platforms external to this specification.", + "type": "string", + "pattern": "^(cpe:2\\.3:[aho\\*\\-](:(((\\?*|\\*?)([a-zA-Z0-9\\-\\._]|(\\\\[\\\\\\*\\?!\"#\\$%&'\\(\\)\\+,/:;<=>@\\[\\]\\^`\\{\\|\\}~]))+(\\?*|\\*?))|[\\*\\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\\*\\-]))(:(((\\?*|\\*?)([a-zA-Z0-9\\-\\._]|(\\\\[\\\\\\*\\?!\"#\\$%&'\\(\\)\\+,/:;<=>@\\[\\]\\^`\\{\\|\\}~]))+(\\?*|\\*?))|[\\*\\-])){4})|([c][pP][eE]:/[AHOaho]?(:[A-Za-z0-9\\._\\-~%]*){0,6})$", + "minLength": 5 + }, + "hashes": { + "title": "List of hashes", + "description": "Contains a list of cryptographic hashes usable to identify files.", + "type": "array", + "minItems": 1, + "items": { + "title": "Cryptographic hashes", + "description": "Contains all information to identify a file based on its cryptographic hash values.", + "type": "object", + "required": [ + "file_hashes", + "filename" + ], + "properties": { + "file_hashes": { + "title": "List of file hashes", + "description": "Contains a list of cryptographic hashes for this file.", + "type": "array", + "minItems": 1, + "items": { + "title": "File hash", + "description": "Contains one hash value and algorithm of the file to be identified.", + "type": "object", + "required": [ + "algorithm", + "value" + ], + "properties": { + "algorithm": { + "title": "Algorithm of the cryptographic hash", + "description": "Contains the name of the cryptographic hash algorithm used to calculate the value.", + "type": "string", + "default": "sha256", + "minLength": 1, + "examples": [ + "blake2b512", + "sha256", + "sha3-512", + "sha384", + "sha512" + ] + }, + "value": { + "title": "Value of the cryptographic hash", + "description": "Contains the cryptographic hash value in hexadecimal representation.", + "type": "string", + "pattern": "^[0-9a-fA-F]{32,}$", + "minLength": 32, + "examples": [ + "37df33cb7464da5c7f077f4d56a32bc84987ec1d85b234537c1c1a4d4fc8d09dc29e2e762cb5203677bf849a2855a0283710f1f5fe1d6ce8d5ac85c645d0fcb3", + "4775203615d9534a8bfca96a93dc8b461a489f69124a130d786b42204f3341cc", + "9ea4c8200113d49d26505da0e02e2f49055dc078d1ad7a419b32e291c7afebbb84badfbd46dec42883bea0b2a1fa697c" + ] + } + } + } + }, + "filename": { + "title": "Filename", + "description": "Contains the name of the file which is identified by the hash values.", + "type": "string", + "minLength": 1, + "examples": [ + "WINWORD.EXE", + "msotadddin.dll", + "sudoers.so" + ] + } + } + } + }, + "model_numbers": { + "title": "List of models", + "description": "Contains a list of full or abbreviated (partial) model numbers.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "Model number", + "description": "Contains a full or abbreviated (partial) model number of the component to identify.", + "type": "string", + "minLength": 1 + } + }, + "purl": { + "title": "package URL representation", + "description": "The package URL (purl) attribute refers to a method for reliably identifying and locating software packages external to this specification.", + "type": "string", + "format": "uri", + "pattern": "^pkg:[A-Za-z\\.\\-\\+][A-Za-z0-9\\.\\-\\+]*/.+", + "minLength": 7 + }, + "sbom_urls": { + "title": "List of SBOM URLs", + "description": "Contains a list of URLs where SBOMs for this product can be retrieved.", + "type": "array", + "minItems": 1, + "items": { + "title": "SBOM URL", + "description": "Contains a URL of one SBOM for this product.", + "type": "string", + "format": "uri" + } + }, + "serial_numbers": { + "title": "List of serial numbers", + "description": "Contains a list of full or abbreviated (partial) serial numbers.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "Serial number", + "description": "Contains a full or abbreviated (partial) serial number of the component to identify.", + "type": "string", + "minLength": 1 + } + }, + "skus": { + "title": "List of stock keeping units", + "description": "Contains a list of full or abbreviated (partial) stock keeping units.", + "type": "array", + "minItems": 1, + "items": { + "title": "Stock keeping unit", + "description": "Contains a full or abbreviated (partial) stock keeping unit (SKU) which is used in the ordering process to identify the component.", + "type": "string", + "minLength": 1 + } + }, + "x_generic_uris": { + "title": "List of generic URIs", + "description": "Contains a list of identifiers which are either vendor-specific or derived from a standard not yet supported.", + "type": "array", + "minItems": 1, + "items": { + "title": "Generic URI", + "description": "Provides a generic extension point for any identifier which is either vendor-specific or derived from a standard not yet supported.", + "type": "object", + "required": [ + "namespace", + "uri" + ], + "properties": { + "namespace": { + "title": "Namespace of the generic URI", + "description": "Refers to a URL which provides the name and knowledge about the specification used or is the namespace in which these values are valid.", + "type": "string", + "format": "uri" + }, + "uri": { + "title": "URI", + "description": "Contains the identifier itself.", + "type": "string", + "format": "uri" + } + } + } + } + } + } + } + }, + "lang_t": { + "title": "Language type", + "description": "Identifies a language, corresponding to IETF BCP 47 / RFC 5646. See IETF language registry: https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry", + "type": "string", + "pattern": "^(([A-Za-z]{2,3}(-[A-Za-z]{3}(-[A-Za-z]{3}){0,2})?|[A-Za-z]{4,8})(-[A-Za-z]{4})?(-([A-Za-z]{2}|[0-9]{3}))?(-([A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-[A-WY-Za-wy-z0-9](-[A-Za-z0-9]{2,8})+)*(-[Xx](-[A-Za-z0-9]{1,8})+)?|[Xx](-[A-Za-z0-9]{1,8})+|[Ii]-[Dd][Ee][Ff][Aa][Uu][Ll][Tt]|[Ii]-[Mm][Ii][Nn][Gg][Oo])$", + "examples": [ + "de", + "en", + "fr", + "frc", + "jp" + ] + }, + "notes_t": { + "title": "List of notes", + "description": "Contains notes which are specific to the current context.", + "type": "array", + "minItems": 1, + "items": { + "title": "Note", + "description": "Is a place to put all manner of text blobs related to the current context.", + "type": "object", + "required": [ + "category", + "text" + ], + "properties": { + "audience": { + "title": "Audience of note", + "description": "Indicates who is intended to read it.", + "type": "string", + "minLength": 1, + "examples": [ + "all", + "executives", + "operational management and system administrators", + "safety engineers" + ] + }, + "category": { + "title": "Note category", + "description": "Contains the information of what kind of note this is.", + "type": "string", + "enum": [ + "description", + "details", + "faq", + "general", + "legal_disclaimer", + "other", + "summary" + ] + }, + "text": { + "title": "Note content", + "description": "Holds the content of the note. Content varies depending on type.", + "type": "string", + "minLength": 1 + }, + "title": { + "title": "Title of note", + "description": "Provides a concise description of what is contained in the text of the note.", + "type": "string", + "minLength": 1, + "examples": [ + "Details", + "Executive summary", + "Technical summary", + "Impact on safety systems" + ] + } + } + } + }, + "product_group_id_t": { + "title": "Reference token for product group instance", + "description": "Token required to identify a group of products so that it can be referred to from other parts in the document. There is no predefined or required format for the product_group_id as long as it uniquely identifies a group in the context of the current document.", + "type": "string", + "minLength": 1, + "examples": [ + "CSAFGID-0001", + "CSAFGID-0002", + "CSAFGID-0020" + ] + }, + "product_groups_t": { + "title": "List of product_group_ids", + "description": "Specifies a list of product_group_ids to give context to the parent item.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "$ref": "#/$defs/product_group_id_t" + } + }, + "product_id_t": { + "title": "Reference token for product instance", + "description": "Token required to identify a full_product_name so that it can be referred to from other parts in the document. There is no predefined or required format for the product_id as long as it uniquely identifies a product in the context of the current document.", + "type": "string", + "minLength": 1, + "examples": [ + "CSAFPID-0004", + "CSAFPID-0008" + ] + }, + "products_t": { + "title": "List of product_ids", + "description": "Specifies a list of product_ids to give context to the parent item.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "$ref": "#/$defs/product_id_t" + } + }, + "references_t": { + "title": "List of references", + "description": "Holds a list of references.", + "type": "array", + "minItems": 1, + "items": { + "title": "Reference", + "description": "Holds any reference to conferences, papers, advisories, and other resources that are related and considered related to either a surrounding part of or the entire document and to be of value to the document consumer.", + "type": "object", + "required": [ + "summary", + "url" + ], + "properties": { + "category": { + "title": "Category of reference", + "description": "Indicates whether the reference points to the same document or vulnerability in focus (depending on scope) or to an external resource.", + "type": "string", + "default": "external", + "enum": [ + "external", + "self" + ] + }, + "summary": { + "title": "Summary of the reference", + "description": "Indicates what this reference refers to.", + "type": "string", + "minLength": 1 + }, + "url": { + "title": "URL of reference", + "description": "Provides the URL for the reference.", + "type": "string", + "format": "uri" + } + } + } + }, + "version_t": { + "title": "Version", + "description": "Specifies a version string to denote clearly the evolution of the content of the document. Format must be either integer or semantic versioning.", + "type": "string", + "pattern": "^(0|[1-9][0-9]*)$|^((0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?)$", + "examples": [ + "1", + "4", + "0.9.0", + "1.4.3", + "2.40.0+21AF26D3" + ] + } + }, + "required": [ + "document" + ], + "properties": { + "document": { + "title": "Document level meta-data", + "description": "Captures the meta-data about this document describing a particular set of security advisories.", + "type": "object", + "required": [ + "category", + "csaf_version", + "publisher", + "title", + "tracking" + ], + "properties": { + "acknowledgments": { + "title": "Document acknowledgments", + "description": "Contains a list of acknowledgment elements associated with the whole document.", + "$ref": "#/$defs/acknowledgments_t" + }, + "aggregate_severity": { + "title": "Aggregate severity", + "description": "Is a vehicle that is provided by the document producer to convey the urgency and criticality with which the one or more vulnerabilities reported should be addressed. It is a document-level metric and applied to the document as a whole — not any specific vulnerability. The range of values in this field is defined according to the document producer's policies and procedures.", + "type": "object", + "required": [ + "text" + ], + "properties": { + "namespace": { + "title": "Namespace of aggregate severity", + "description": "Points to the namespace so referenced.", + "type": "string", + "format": "uri" + }, + "text": { + "title": "Text of aggregate severity", + "description": "Provides a severity which is independent of - and in addition to - any other standard metric for determining the impact or severity of a given vulnerability (such as CVSS).", + "type": "string", + "minLength": 1, + "examples": [ + "Critical", + "Important", + "Moderate" + ] + } + } + }, + "category": { + "title": "Document category", + "description": "Defines a short canonical name, chosen by the document producer, which will inform the end user as to the category of document.", + "type": "string", + "pattern": "^[^\\s\\-_\\.](.*[^\\s\\-_\\.])?$", + "minLength": 1, + "examples": [ + "csaf_base", + "csaf_security_advisory", + "csaf_vex", + "Example Company Security Notice" + ] + }, + "csaf_version": { + "title": "CSAF version", + "description": "Gives the version of the CSAF specification which the document was generated for.", + "type": "string", + "enum": [ + "2.0" + ] + }, + "distribution": { + "title": "Rules for sharing document", + "description": "Describe any constraints on how this document might be shared.", + "type": "object", + "minProperties": 1, + "properties": { + "text": { + "title": "Textual description", + "description": "Provides a textual description of additional constraints.", + "type": "string", + "minLength": 1, + "examples": [ + "Copyright 2021, Example Company, All Rights Reserved.", + "Distribute freely.", + "Share only on a need-to-know-basis only." + ] + }, + "tlp": { + "title": "Traffic Light Protocol (TLP)", + "description": "Provides details about the TLP classification of the document.", + "type": "object", + "required": [ + "label" + ], + "properties": { + "label": { + "title": "Label of TLP", + "description": "Provides the TLP label of the document.", + "type": "string", + "enum": [ + "AMBER", + "GREEN", + "RED", + "WHITE" + ] + }, + "url": { + "title": "URL of TLP version", + "description": "Provides a URL where to find the textual description of the TLP version which is used in this document. Default is the URL to the definition by FIRST.", + "type": "string", + "default": "https://www.first.org/tlp/", + "format": "uri", + "examples": [ + "https://www.us-cert.gov/tlp", + "https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/Kritis/Merkblatt_TLP.pdf" + ] + } + } + } + } + }, + "lang": { + "title": "Document language", + "description": "Identifies the language used by this document, corresponding to IETF BCP 47 / RFC 5646.", + "$ref": "#/$defs/lang_t" + }, + "notes": { + "title": "Document notes", + "description": "Holds notes associated with the whole document.", + "$ref": "#/$defs/notes_t" + }, + "publisher": { + "title": "Publisher", + "description": "Provides information about the publisher of the document.", + "type": "object", + "required": [ + "category", + "name", + "namespace" + ], + "properties": { + "category": { + "title": "Category of publisher", + "description": "Provides information about the category of publisher releasing the document.", + "type": "string", + "enum": [ + "coordinator", + "discoverer", + "other", + "translator", + "user", + "vendor" + ] + }, + "contact_details": { + "title": "Contact details", + "description": "Information on how to contact the publisher, possibly including details such as web sites, email addresses, phone numbers, and postal mail addresses.", + "type": "string", + "minLength": 1, + "examples": [ + "Example Company can be reached at contact_us@example.com, or via our website at https://www.example.com/contact." + ] + }, + "issuing_authority": { + "title": "Issuing authority", + "description": "Provides information about the authority of the issuing party to release the document, in particular, the party's constituency and responsibilities or other obligations.", + "type": "string", + "minLength": 1 + }, + "name": { + "title": "Name of publisher", + "description": "Contains the name of the issuing party.", + "type": "string", + "minLength": 1, + "examples": [ + "BSI", + "Cisco PSIRT", + "Siemens ProductCERT" + ] + }, + "namespace": { + "title": "Namespace of publisher", + "description": "Contains a URL which is under control of the issuing party and can be used as a globally unique identifier for that issuing party.", + "type": "string", + "format": "uri", + "examples": [ + "https://csaf.io", + "https://www.example.com" + ] + } + } + }, + "references": { + "title": "Document references", + "description": "Holds a list of references associated with the whole document.", + "$ref": "#/$defs/references_t" + }, + "source_lang": { + "title": "Source language", + "description": "If this copy of the document is a translation then the value of this property describes from which language this document was translated.", + "$ref": "#/$defs/lang_t" + }, + "title": { + "title": "Title of this document", + "description": "This SHOULD be a canonical name for the document, and sufficiently unique to distinguish it from similar documents.", + "type": "string", + "minLength": 1, + "examples": [ + "Cisco IPv6 Crafted Packet Denial of Service Vulnerability", + "Example Company Cross-Site-Scripting Vulnerability in Example Generator" + ] + }, + "tracking": { + "title": "Tracking", + "description": "Is a container designated to hold all management attributes necessary to track a CSAF document as a whole.", + "type": "object", + "required": [ + "current_release_date", + "id", + "initial_release_date", + "revision_history", + "status", + "version" + ], + "properties": { + "aliases": { + "title": "Aliases", + "description": "Contains a list of alternate names for the same document.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "Alternate name", + "description": "Specifies a non-empty string that represents a distinct optional alternative ID used to refer to the document.", + "type": "string", + "minLength": 1, + "examples": [ + "CVE-2019-12345" + ] + } + }, + "current_release_date": { + "title": "Current release date", + "description": "The date when the current revision of this document was released", + "type": "string", + "format": "date-time" + }, + "generator": { + "title": "Document generator", + "description": "Is a container to hold all elements related to the generation of the document. These items will reference when the document was actually created, including the date it was generated and the entity that generated it.", + "type": "object", + "required": [ + "engine" + ], + "properties": { + "date": { + "title": "Date of document generation", + "description": "This SHOULD be the current date that the document was generated. Because documents are often generated internally by a document producer and exist for a nonzero amount of time before being released, this field MAY be different from the Initial Release Date and Current Release Date.", + "type": "string", + "format": "date-time" + }, + "engine": { + "title": "Engine of document generation", + "description": "Contains information about the engine that generated the CSAF document.", + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "title": "Engine name", + "description": "Represents the name of the engine that generated the CSAF document.", + "type": "string", + "minLength": 1, + "examples": [ + "Red Hat rhsa-to-cvrf", + "Secvisogram", + "TVCE" + ] + }, + "version": { + "title": "Engine version", + "description": "Contains the version of the engine that generated the CSAF document.", + "type": "string", + "minLength": 1, + "examples": [ + "0.6.0", + "1.0.0-beta+exp.sha.a1c44f85", + "2" + ] + } + } + } + } + }, + "id": { + "title": "Unique identifier for the document", + "description": "The ID is a simple label that provides for a wide range of numbering values, types, and schemes. Its value SHOULD be assigned and maintained by the original document issuing authority.", + "type": "string", + "pattern": "^[\\S](.*[\\S])?$", + "minLength": 1, + "examples": [ + "Example Company - 2019-YH3234", + "RHBA-2019:0024", + "cisco-sa-20190513-secureboot" + ] + }, + "initial_release_date": { + "title": "Initial release date", + "description": "The date when this document was first published.", + "type": "string", + "format": "date-time" + }, + "revision_history": { + "title": "Revision history", + "description": "Holds one revision item for each version of the CSAF document, including the initial one.", + "type": "array", + "minItems": 1, + "items": { + "title": "Revision", + "description": "Contains all the information elements required to track the evolution of a CSAF document.", + "type": "object", + "required": [ + "date", + "number", + "summary" + ], + "properties": { + "date": { + "title": "Date of the revision", + "description": "The date of the revision entry", + "type": "string", + "format": "date-time" + }, + "legacy_version": { + "title": "Legacy version of the revision", + "description": "Contains the version string used in an existing document with the same content.", + "type": "string", + "minLength": 1 + }, + "number": { + "$ref": "#/$defs/version_t" + }, + "summary": { + "title": "Summary of the revision", + "description": "Holds a single non-empty string representing a short description of the changes.", + "type": "string", + "minLength": 1, + "examples": [ + "Initial version." + ] + } + } + } + }, + "status": { + "title": "Document status", + "description": "Defines the draft status of the document.", + "type": "string", + "enum": [ + "draft", + "final", + "interim" + ] + }, + "version": { + "$ref": "#/$defs/version_t" + } + } + } + } + }, + "product_tree": { + "title": "Product tree", + "description": "Is a container for all fully qualified product names that can be referenced elsewhere in the document.", + "type": "object", + "minProperties": 1, + "properties": { + "branches": { + "$ref": "#/$defs/branches_t" + }, + "full_product_names": { + "title": "List of full product names", + "description": "Contains a list of full product names.", + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/$defs/full_product_name_t" + } + }, + "product_groups": { + "title": "List of product groups", + "description": "Contains a list of product groups.", + "type": "array", + "minItems": 1, + "items": { + "title": "Product group", + "description": "Defines a new logical group of products that can then be referred to in other parts of the document to address a group of products with a single identifier.", + "type": "object", + "required": [ + "group_id", + "product_ids" + ], + "properties": { + "group_id": { + "$ref": "#/$defs/product_group_id_t" + }, + "product_ids": { + "title": "List of Product IDs", + "description": "Lists the product_ids of those products which known as one group in the document.", + "type": "array", + "minItems": 2, + "uniqueItems": true, + "items": { + "$ref": "#/$defs/product_id_t" + } + }, + "summary": { + "title": "Summary of the product group", + "description": "Gives a short, optional description of the group.", + "type": "string", + "minLength": 1, + "examples": [ + "Products supporting Modbus.", + "The x64 versions of the operating system." + ] + } + } + } + }, + "relationships": { + "title": "List of relationships", + "description": "Contains a list of relationships.", + "type": "array", + "minItems": 1, + "items": { + "title": "Relationship", + "description": "Establishes a link between two existing full_product_name_t elements, allowing the document producer to define a combination of two products that form a new full_product_name entry.", + "type": "object", + "required": [ + "category", + "full_product_name", + "product_reference", + "relates_to_product_reference" + ], + "properties": { + "category": { + "title": "Relationship category", + "description": "Defines the category of relationship for the referenced component.", + "type": "string", + "enum": [ + "default_component_of", + "external_component_of", + "installed_on", + "installed_with", + "optional_component_of" + ] + }, + "full_product_name": { + "$ref": "#/$defs/full_product_name_t" + }, + "product_reference": { + "title": "Product reference", + "description": "Holds a Product ID that refers to the Full Product Name element, which is referenced as the first element of the relationship.", + "$ref": "#/$defs/product_id_t" + }, + "relates_to_product_reference": { + "title": "Relates to product reference", + "description": "Holds a Product ID that refers to the Full Product Name element, which is referenced as the second element of the relationship.", + "$ref": "#/$defs/product_id_t" + } + } + } + } + } + }, + "vulnerabilities": { + "title": "Vulnerabilities", + "description": "Represents a list of all relevant vulnerability information items.", + "type": "array", + "minItems": 1, + "items": { + "title": "Vulnerability", + "description": "Is a container for the aggregation of all fields that are related to a single vulnerability in the document.", + "type": "object", + "minProperties": 1, + "properties": { + "acknowledgments": { + "title": "Vulnerability acknowledgments", + "description": "Contains a list of acknowledgment elements associated with this vulnerability item.", + "$ref": "#/$defs/acknowledgments_t" + }, + "cve": { + "title": "CVE", + "description": "Holds the MITRE standard Common Vulnerabilities and Exposures (CVE) tracking number for the vulnerability.", + "type": "string", + "pattern": "^CVE-[0-9]{4}-[0-9]{4,}$" + }, + "cwe": { + "title": "CWE", + "description": "Holds the MITRE standard Common Weakness Enumeration (CWE) for the weakness associated.", + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "title": "Weakness ID", + "description": "Holds the ID for the weakness associated.", + "type": "string", + "pattern": "^CWE-[1-9]\\d{0,5}$", + "examples": [ + "CWE-22", + "CWE-352", + "CWE-79" + ] + }, + "name": { + "title": "Weakness name", + "description": "Holds the full name of the weakness as given in the CWE specification.", + "type": "string", + "minLength": 1, + "examples": [ + "Cross-Site Request Forgery (CSRF)", + "Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')", + "Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" + ] + } + } + }, + "discovery_date": { + "title": "Discovery date", + "description": "Holds the date and time the vulnerability was originally discovered.", + "type": "string", + "format": "date-time" + }, + "flags": { + "title": "List of flags", + "description": "Contains a list of machine readable flags.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "Flag", + "description": "Contains product specific information in regard to this vulnerability as a single machine readable flag.", + "type": "object", + "required": [ + "label" + ], + "properties": { + "date": { + "title": "Date of the flag", + "description": "Contains the date when assessment was done or the flag was assigned.", + "type": "string", + "format": "date-time" + }, + "group_ids": { + "$ref": "#/$defs/product_groups_t" + }, + "label": { + "title": "Label of the flag", + "description": "Specifies the machine readable label.", + "type": "string", + "enum": [ + "component_not_present", + "inline_mitigations_already_exist", + "vulnerable_code_cannot_be_controlled_by_adversary", + "vulnerable_code_not_in_execute_path", + "vulnerable_code_not_present" + ] + }, + "product_ids": { + "$ref": "#/$defs/products_t" + } + } + } + }, + "ids": { + "title": "List of IDs", + "description": "Represents a list of unique labels or tracking IDs for the vulnerability (if such information exists).", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "ID", + "description": "Contains a single unique label or tracking ID for the vulnerability.", + "type": "object", + "required": [ + "system_name", + "text" + ], + "properties": { + "system_name": { + "title": "System name", + "description": "Indicates the name of the vulnerability tracking or numbering system.", + "type": "string", + "minLength": 1, + "examples": [ + "Cisco Bug ID", + "GitHub Issue" + ] + }, + "text": { + "title": "Text", + "description": "Is unique label or tracking ID for the vulnerability (if such information exists).", + "type": "string", + "minLength": 1, + "examples": [ + "CSCso66472", + "oasis-tcs/csaf#210" + ] + } + } + } + }, + "involvements": { + "title": "List of involvements", + "description": "Contains a list of involvements.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "Involvement", + "description": "Is a container, that allows the document producers to comment on the level of involvement (or engagement) of themselves or third parties in the vulnerability identification, scoping, and remediation process.", + "type": "object", + "required": [ + "party", + "status" + ], + "properties": { + "date": { + "title": "Date of involvement", + "description": "Holds the date and time of the involvement entry.", + "type": "string", + "format": "date-time" + }, + "party": { + "title": "Party category", + "description": "Defines the category of the involved party.", + "type": "string", + "enum": [ + "coordinator", + "discoverer", + "other", + "user", + "vendor" + ] + }, + "status": { + "title": "Party status", + "description": "Defines contact status of the involved party.", + "type": "string", + "enum": [ + "completed", + "contact_attempted", + "disputed", + "in_progress", + "not_contacted", + "open" + ] + }, + "summary": { + "title": "Summary of the involvement", + "description": "Contains additional context regarding what is going on.", + "type": "string", + "minLength": 1 + } + } + } + }, + "notes": { + "title": "Vulnerability notes", + "description": "Holds notes associated with this vulnerability item.", + "$ref": "#/$defs/notes_t" + }, + "product_status": { + "title": "Product status", + "description": "Contains different lists of product_ids which provide details on the status of the referenced product related to the current vulnerability. ", + "type": "object", + "minProperties": 1, + "properties": { + "first_affected": { + "title": "First affected", + "description": "These are the first versions of the releases known to be affected by the vulnerability.", + "$ref": "#/$defs/products_t" + }, + "first_fixed": { + "title": "First fixed", + "description": "These versions contain the first fix for the vulnerability but may not be the recommended fixed versions.", + "$ref": "#/$defs/products_t" + }, + "fixed": { + "title": "Fixed", + "description": "These versions contain a fix for the vulnerability but may not be the recommended fixed versions.", + "$ref": "#/$defs/products_t" + }, + "known_affected": { + "title": "Known affected", + "description": "These versions are known to be affected by the vulnerability.", + "$ref": "#/$defs/products_t" + }, + "known_not_affected": { + "title": "Known not affected", + "description": "These versions are known not to be affected by the vulnerability.", + "$ref": "#/$defs/products_t" + }, + "last_affected": { + "title": "Last affected", + "description": "These are the last versions in a release train known to be affected by the vulnerability. Subsequently released versions would contain a fix for the vulnerability.", + "$ref": "#/$defs/products_t" + }, + "recommended": { + "title": "Recommended", + "description": "These versions have a fix for the vulnerability and are the vendor-recommended versions for fixing the vulnerability.", + "$ref": "#/$defs/products_t" + }, + "under_investigation": { + "title": "Under investigation", + "description": "It is not known yet whether these versions are or are not affected by the vulnerability. However, it is still under investigation - the result will be provided in a later release of the document.", + "$ref": "#/$defs/products_t" + } + } + }, + "references": { + "title": "Vulnerability references", + "description": "Holds a list of references associated with this vulnerability item.", + "$ref": "#/$defs/references_t" + }, + "release_date": { + "title": "Release date", + "description": "Holds the date and time the vulnerability was originally released into the wild.", + "type": "string", + "format": "date-time" + }, + "remediations": { + "title": "List of remediations", + "description": "Contains a list of remediations.", + "type": "array", + "minItems": 1, + "items": { + "title": "Remediation", + "description": "Specifies details on how to handle (and presumably, fix) a vulnerability.", + "type": "object", + "required": [ + "category", + "details" + ], + "properties": { + "category": { + "title": "Category of the remediation", + "description": "Specifies the category which this remediation belongs to.", + "type": "string", + "enum": [ + "mitigation", + "no_fix_planned", + "none_available", + "vendor_fix", + "workaround" + ] + }, + "date": { + "title": "Date of the remediation", + "description": "Contains the date from which the remediation is available.", + "type": "string", + "format": "date-time" + }, + "details": { + "title": "Details of the remediation", + "description": "Contains a thorough human-readable discussion of the remediation.", + "type": "string", + "minLength": 1 + }, + "entitlements": { + "title": "List of entitlements", + "description": "Contains a list of entitlements.", + "type": "array", + "minItems": 1, + "items": { + "title": "Entitlement of the remediation", + "description": "Contains any possible vendor-defined constraints for obtaining fixed software or hardware that fully resolves the vulnerability.", + "type": "string", + "minLength": 1 + } + }, + "group_ids": { + "$ref": "#/$defs/product_groups_t" + }, + "product_ids": { + "$ref": "#/$defs/products_t" + }, + "restart_required": { + "title": "Restart required by remediation", + "description": "Provides information on category of restart is required by this remediation to become effective.", + "type": "object", + "required": [ + "category" + ], + "properties": { + "category": { + "title": "Category of restart", + "description": "Specifies what category of restart is required by this remediation to become effective.", + "type": "string", + "enum": [ + "connected", + "dependencies", + "machine", + "none", + "parent", + "service", + "system", + "vulnerable_component", + "zone" + ] + }, + "details": { + "title": "Additional restart information", + "description": "Provides additional information for the restart. This can include details on procedures, scope or impact.", + "type": "string", + "minLength": 1 + } + } + }, + "url": { + "title": "URL to the remediation", + "description": "Contains the URL where to obtain the remediation.", + "type": "string", + "format": "uri" + } + } + } + }, + "scores": { + "title": "List of scores", + "description": "Contains score objects for the current vulnerability.", + "type": "array", + "minItems": 1, + "items": { + "title": "Score", + "description": "Specifies information about (at least one) score of the vulnerability and for which products the given value applies.", + "type": "object", + "minProperties": 2, + "required": [ + "products" + ], + "properties": { + "cvss_v2": { + "$ref": "https://www.first.org/cvss/cvss-v2.0.json" + }, + "cvss_v3": { + "oneOf": [ + { + "$ref": "https://www.first.org/cvss/cvss-v3.0.json" + }, + { + "$ref": "https://www.first.org/cvss/cvss-v3.1.json" + } + ] + }, + "products": { + "$ref": "#/$defs/products_t" + } + } + } + }, + "threats": { + "title": "List of threats", + "description": "Contains information about a vulnerability that can change with time.", + "type": "array", + "minItems": 1, + "items": { + "title": "Threat", + "description": "Contains the vulnerability kinetic information. This information can change as the vulnerability ages and new information becomes available.", + "type": "object", + "required": [ + "category", + "details" + ], + "properties": { + "category": { + "title": "Category of the threat", + "description": "Categorizes the threat according to the rules of the specification.", + "type": "string", + "enum": [ + "exploit_status", + "impact", + "target_set" + ] + }, + "date": { + "title": "Date of the threat", + "description": "Contains the date when the assessment was done or the threat appeared.", + "type": "string", + "format": "date-time" + }, + "details": { + "title": "Details of the threat", + "description": "Represents a thorough human-readable discussion of the threat.", + "type": "string", + "minLength": 1 + }, + "group_ids": { + "$ref": "#/$defs/product_groups_t" + }, + "product_ids": { + "$ref": "#/$defs/products_t" + } + } + } + }, + "title": { + "title": "Title", + "description": "Gives the document producer the ability to apply a canonical name or title to the vulnerability.", + "type": "string", + "minLength": 1 + } + } + } + } + } +} diff --git a/cve_bin_tool/schemas/openvex_json_schema.json b/cve_bin_tool/schemas/openvex_json_schema.json new file mode 100644 index 0000000000..2a6aecb81a --- /dev/null +++ b/cve_bin_tool/schemas/openvex_json_schema.json @@ -0,0 +1,317 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/openvex/spec/openvex_json_schema_0.2.0.json", + "title": "OpenVEX", + "description": "OpenVEX is an implementation of the Vulnerability Exploitability Exchange (VEX for short) that is designed to be minimal, compliant, interoperable, and embeddable.", + "type": "object", + "$defs": { + "vulnerability": { + "type": "object", + "properties": { + "@id": { + "type": "string", + "format": "iri", + "description": "An Internationalized Resource Identifier (IRI) identifying the struct." + }, + "name": { + "type": "string", + "description": "A string with the main identifier used to name the vulnerability." + }, + "description": { + "type": "string", + "description": "Optional free form text describing the vulnerability." + }, + "aliases": { + "type": "array", + "uniqueItems": true, + "items": { + "type": "string" + }, + "description": "A list of strings enumerating other names under which the vulnerability may be known." + } + }, + "required": [ + "name" + ], + "additionalProperties": false + }, + "identifiers": { + "type": "object", + "properties": { + "purl": { + "type": "string", + "description": "Package URL" + }, + "cpe22": { + "type": "string", + "description": "Common Platform Enumeration v2.2" + }, + "cpe23": { + "type": "string", + "description": "Common Platform Enumeration v2.3" + } + }, + "additionalProperties": false, + "anyOf": [ + { "required": ["purl"] }, + { "required": ["cpe22"] }, + { "required": ["cpe23"] } + ] + }, + "hashes": { + "type": "object", + "properties": { + "md5": { + "type": "string" + }, + "sha1": { + "type": "string" + }, + "sha-256": { + "type": "string" + }, + "sha-384": { + "type": "string" + }, + "sha-512": { + "type": "string" + }, + "sha3-224": { + "type": "string" + }, + "sha3-256": { + "type": "string" + }, + "sha3-384": { + "type": "string" + }, + "sha3-512": { + "type": "string" + }, + "blake2s-256": { + "type": "string" + }, + "blake2b-256": { + "type": "string" + }, + "blake2b-512": { + "type": "string" + } + }, + "additionalProperties": false + }, + "subcomponent": { + "type": "object", + "properties": { + "@id": { + "type": "string", + "format": "iri", + "description": "Optional IRI identifying the component to make it externally referenceable." + }, + "identifiers": { + "$ref": "#/$defs/identifiers", + "description": "Optional IRI identifying the component to make it externally referenceable." + }, + "hashes": { + "$ref": "#/$defs/hashes", + "description": "Map of cryptographic hashes of the component." + } + }, + "additionalProperties": false, + "anyOf": [ + { "required": ["@id"] }, + { "required": ["identifiers"] } + ] + }, + "component": { + "type": "object", + "properties": { + "@id": { + "type": "string", + "format": "iri", + "description": "Optional IRI identifying the component to make it externally referenceable." + }, + "identifiers": { + "$ref": "#/$defs/identifiers", + "description": "A map of software identifiers where the key is the type and the value the identifier." + }, + "hashes": { + "$ref": "#/$defs/hashes", + "description": "Map of cryptographic hashes of the component." + }, + "subcomponents": { + "type": "array", + "uniqueItems": true, + "description": "List of subcomponent structs describing the subcomponents subject of the VEX statement.", + "items": { + "$ref": "#/$defs/subcomponent" + } + } + }, + "additionalProperties": false, + "anyOf": [ + { "required": ["@id"] }, + { "required": ["identifiers"] } + ] + } + }, + "properties": { + "@context": { + "type": "string", + "format": "uri", + "description": "The URL linking to the OpenVEX context definition." + }, + "@id": { + "type": "string", + "format": "iri", + "description": "The IRI identifying the VEX document." + }, + "author": { + "type": "string", + "description": "Author is the identifier for the author of the VEX statement." + }, + "role": { + "type": "string", + "description": "Role describes the role of the document author." + }, + "timestamp": { + "type": "string", + "format": "date-time", + "description": "Timestamp defines the time at which the document was issued." + }, + "last_updated": { + "type": "string", + "format": "date-time", + "description": "Date of last modification to the document." + }, + "version": { + "type": "integer", + "minimum": 1, + "description": "Version is the document version." + }, + "tooling": { + "type": "string", + "description": "Tooling expresses how the VEX document and contained VEX statements were generated." + }, + "statements": { + "type": "array", + "uniqueItems": true, + "minItems": 1, + "description": "A statement is an assertion made by the document's author about the impact a vulnerability has on one or more software 'products'.", + "items": { + "type": "object", + "properties": { + "@id": { + "type": "string", + "format": "iri", + "description": "Optional IRI identifying the statement to make it externally referenceable." + }, + "version": { + "type": "integer", + "minimum": 1, + "description": "Optional integer representing the statement's version number." + }, + "vulnerability": { + "$ref": "#/$defs/vulnerability", + "description": "A struct identifying the vulnerability." + }, + "timestamp": { + "type": "string", + "format": "date-time", + "description": "Timestamp is the time at which the information expressed in the statement was known to be true." + }, + "last_updated": { + "type": "string", + "format": "date-time", + "description": "Timestamp when the statement was last updated." + }, + "products": { + "type": "array", + "uniqueItems": true, + "description": "List of product structs that the statement applies to.", + "items": { + "$ref": "#/$defs/component" + } + }, + "status": { + "type": "string", + "enum": [ + "not_affected", + "affected", + "fixed", + "under_investigation" + ], + "description": "A VEX statement MUST provide the status of the vulnerabilities with respect to the products and components listed in the statement." + }, + "supplier": { + "type": "string", + "description": "Supplier of the product or subcomponent." + }, + "status_notes": { + "type": "string", + "description": "A statement MAY convey information about how status was determined and MAY reference other VEX information." + }, + "justification": { + "type": "string", + "enum": [ + "component_not_present", + "vulnerable_code_not_present", + "vulnerable_code_not_in_execute_path", + "vulnerable_code_cannot_be_controlled_by_adversary", + "inline_mitigations_already_exist" + ], + "description": "For statements conveying a not_affected status, a VEX statement MUST include either a status justification or an impact_statement informing why the product is not affected by the vulnerability." + }, + "impact_statement": { + "type": "string", + "description": "For statements conveying a not_affected status, a VEX statement MUST include either a status justification or an impact_statement informing why the product is not affected by the vulnerability." + }, + "action_statement": { + "type": "string", + "description": "For a statement with affected status, a VEX statement MUST include a statement that SHOULD describe actions to remediate or mitigate the vulnerability." + }, + "action_statement_timestamp": { + "type": "string", + "format": "date-time", + "description": "The timestamp when the action statement was issued." + } + }, + "required": [ + "vulnerability", + "status" + ], + "additionalProperties": false, + "allOf": [ + { + "if": { + "properties": { "status": { "const": "not_affected" }} + }, + "then": { + "anyOf": [ + { "required": ["justification"]}, + { "required": ["impact_statement"]} + ] + } + }, + { + "if": { + "properties": { "status": { "const": "affected" }} + }, + "then": { + "required": ["action_statement"] + } + } + ] + } + } + }, + "required": [ + "@context", + "@id", + "author", + "timestamp", + "version", + "statements" + ], + "additionalProperties": false +} diff --git a/cve_bin_tool/vex_manager/validate.py b/cve_bin_tool/vex_manager/validate.py new file mode 100644 index 0000000000..2bf9a3bc8a --- /dev/null +++ b/cve_bin_tool/vex_manager/validate.py @@ -0,0 +1,573 @@ +# Copyright (C) 2025 Intel Corporation +# SPDX-License-Identifier: GPL-3.0-or-later + +""" +VEX Validation Module + +Provides functionality to validate VEX files for schema compliance using standard +JSON schemas for CycloneDX, CSAF, and OpenVEX formats. +""" + +import json +import urllib.parse +import urllib.request +from pathlib import Path +from typing import Dict, List, Optional, Tuple + +import jsonschema +from jsonschema import ValidationError as JsonSchemaValidationError + +from cve_bin_tool.log import LOGGER + +# Local schema directory +SCHEMA_DIR = Path(__file__).parent.parent / "schemas" + +# Schema file mapping for local schemas with version support +LOCAL_SCHEMA_FILES = { + "cyclonedx": { + "1.4": "bom-1.4.schema.json", + "1.5": "bom-1.4.schema.json", # Fallback to 1.4 if 1.5 not available + "1.6": "bom-1.4.schema.json", # Fallback to 1.4 if 1.6 not available + "default": "bom-1.4.schema.json", + }, + "csaf": {"2.0": "csaf_json_schema.json", "default": "csaf_json_schema.json"}, + "openvex": { + "0.2.0": "openvex_json_schema.json", + "default": "openvex_json_schema.json", + }, +} + +# Schema URLs for each VEX format (fallback) with version support +SCHEMA_URLS = { + "cyclonedx": { + "1.4": "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.4.schema.json", + "1.5": "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.5.schema.json", + "1.6": "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.6.schema.json", + "default": "https://raw.githubusercontent.com/CycloneDX/specification/master/schema/bom-1.4.schema.json", + }, + "csaf": { + "2.0": "https://raw.githubusercontent.com/oasis-tcs/csaf/master/csaf_2.0/json_schema/csaf_json_schema.json", + "default": "https://raw.githubusercontent.com/oasis-tcs/csaf/master/csaf_2.0/json_schema/csaf_json_schema.json", + }, + "openvex": { + "0.2.0": "https://raw.githubusercontent.com/openvex/spec/refs/heads/main/openvex_json_schema.json", + "default": "https://raw.githubusercontent.com/openvex/spec/refs/heads/main/openvex_json_schema.json", + }, +} + +# Local cache for schemas +SCHEMA_CACHE = {} + + +class ValidationError: + """Represents a validation error found in a VEX file.""" + + def __init__( + self, + error_type: str, + message: str, + field: Optional[str] = None, + location: Optional[str] = None, + severity: str = "error", + ): + self.error_type = error_type + self.message = message + self.field = field + self.location = location + self.severity = severity # "error", "warning", "info" + + def __str__(self) -> str: + """String representation of the validation error.""" + error_str = f"[{self.severity.upper()}:{self.error_type}] {self.message}" + if self.field: + error_str += f" (Field: {self.field})" + if self.location: + error_str += f" (Location: {self.location})" + return error_str + + +class VEXValidator: + """ + VEX file validator that checks for schema compliance using standard JSON schemas. + + Supports CycloneDX, CSAF, and OpenVEX formats with version-aware validation. + """ + + def __init__(self, logger=None, offline=False): + """Initialize the VEX validator.""" + self.logger = logger or LOGGER.getChild(self.__class__.__name__) + self.offline = offline + self.errors: List[ValidationError] = [] + self.warnings: List[ValidationError] = [] + + def validate_file( + self, vex_file_path: str + ) -> Tuple[bool, List[ValidationError], List[ValidationError]]: + """ + Validate a VEX file for schema compliance. + + Args: + vex_file_path: Path to the VEX file to validate + + Returns: + Tuple of (is_valid, errors, warnings) + """ + self.errors = [] + self.warnings = [] + + # Check if file exists + if not Path(vex_file_path).exists(): + self.errors.append( + ValidationError("FILE_ERROR", f"VEX file not found: {vex_file_path}") + ) + return False, self.errors, self.warnings + + # Check file extension + if not self._is_valid_vex_file(vex_file_path): + self.errors.append( + ValidationError( + "FILE_ERROR", + f"Invalid file extension. Expected .json for VEX files, got: {Path(vex_file_path).suffix}", + ) + ) + return False, self.errors, self.warnings + + try: + # Load JSON data with explicit UTF-8 encoding + with open(vex_file_path, encoding="utf-8") as f: + raw_data = json.load(f) + except json.JSONDecodeError as e: + self.errors.append( + ValidationError("PARSE_ERROR", f"Invalid JSON format: {str(e)}") + ) + return False, self.errors, self.warnings + except Exception as e: + self.errors.append( + ValidationError("PARSE_ERROR", f"Failed to read VEX file: {str(e)}") + ) + return False, self.errors, self.warnings + + # Detect VEX type and version + vex_type, version = self._detect_vex_type_and_version(raw_data) + if not vex_type: + self.errors.append( + ValidationError( + "SCHEMA_ERROR", + "Could not detect VEX format. File may not be a valid VEX document.", + ) + ) + return False, self.errors, self.warnings + + self.logger.info(f"Detected VEX format: {vex_type} (version: {version})") + + # Validate against appropriate schema + try: + schema = self._get_schema(vex_type, version) + if schema: # Only validate if schema was successfully loaded + jsonschema.validate(instance=raw_data, schema=schema) + self.logger.info(f"VEX file passed {vex_type} schema validation") + except JsonSchemaValidationError as e: + # Convert jsonschema validation error to our format + path = ".".join(str(p) for p in e.path) if e.path else None + + self.errors.append( + ValidationError( + "SCHEMA_ERROR", + f"Schema validation error: {e.message}", + field=path, + location=str(e.schema_path) if e.schema_path else None, + ) + ) + except Exception as e: + self.errors.append( + ValidationError( + "VALIDATION_ERROR", f"Error during schema validation: {str(e)}" + ) + ) + + # Perform format-specific validations + self._perform_format_specific_validation(raw_data, vex_type) + + # Add warnings for empty sections + self._check_for_empty_sections(raw_data, vex_type) + + # Return validation results + is_valid = len(self.errors) == 0 + return is_valid, self.errors, self.warnings + + def _is_valid_vex_file(self, file_path: str) -> bool: + """Check if the file has a valid VEX file extension.""" + return Path(file_path).suffix.lower() == ".json" + + def _detect_vex_type_and_version( + self, raw_data: Dict + ) -> Tuple[Optional[str], Optional[str]]: + """Detect VEX type and version from raw JSON data.""" + # Check for CycloneDX + if raw_data.get("bomFormat") == "CycloneDX": + version = raw_data.get("specVersion", "1.4") + return "cyclonedx", version + + # Check for OpenVEX + context = raw_data.get("@context", "") + if context and "openvex" in str(context): + # Try to extract version from context + version = "0.2.0" # Default version + if "v0.2.0" in str(context): + version = "0.2.0" + return "openvex", version + + # Check for CSAF + if raw_data.get("document") and raw_data.get("vulnerabilities"): + # Check CSAF version + doc = raw_data.get("document", {}) + version = doc.get("csaf_version", "2.0") + return "csaf", version + + return None, None + + def _get_schema(self, vex_type: str, version: Optional[str] = None) -> Dict: + """ + Get JSON schema for the specified VEX type and version. + + Attempts to load from local cache first, then local files, then downloads from official URL. + """ + cache_key = f"{vex_type}:{version}" if version else vex_type + + # Check if schema is already cached + if cache_key in SCHEMA_CACHE: + self.logger.debug(f"Using cached {vex_type} schema (version: {version})") + return SCHEMA_CACHE[cache_key] + + # Try to load from local schema files first + local_schema = self._load_local_schema(vex_type, version) + if local_schema: + SCHEMA_CACHE[cache_key] = local_schema + self.logger.debug( + f"Loaded {vex_type} schema from local file (version: {version})" + ) + return local_schema + + # If offline mode, can't download + if self.offline: + self.errors.append( + ValidationError( + "SCHEMA_ERROR", + f"Local schema not found for {vex_type} (version: {version}) and offline mode is enabled", + ) + ) + return {} + + # Fallback to downloading from official URL + return self._download_schema(vex_type, version) + + def _load_local_schema(self, vex_type: str, version: Optional[str] = None) -> Dict: + """Load schema from local file system.""" + schema_files = LOCAL_SCHEMA_FILES.get(vex_type, {}) + if not schema_files: + self.logger.debug(f"No local schema file defined for {vex_type}") + return {} + + # Get version-specific schema file or default + schema_file = schema_files.get(version) or schema_files.get("default") + if not schema_file: + self.logger.debug(f"No schema file for {vex_type} version {version}") + return {} + + schema_path = SCHEMA_DIR / schema_file + + if not schema_path.exists(): + self.logger.debug(f"Local schema file not found: {schema_path}") + return {} + + try: + with open(schema_path, encoding="utf-8") as f: + schema_data = json.load(f) + self.logger.debug( + f"Successfully loaded local {vex_type} schema from {schema_path}" + ) + return schema_data + except Exception as e: + self.logger.debug(f"Failed to load local {vex_type} schema: {str(e)}") + return {} + + def _download_schema(self, vex_type: str, version: Optional[str] = None) -> Dict: + """Download schema from official URL.""" + schema_urls = SCHEMA_URLS.get(vex_type, {}) + if not schema_urls: + self.errors.append( + ValidationError( + "SCHEMA_ERROR", f"No schema URL defined for VEX type: {vex_type}" + ) + ) + return {} + + # Get version-specific URL or default + schema_url = schema_urls.get(version) or schema_urls.get("default") + if not schema_url: + self.errors.append( + ValidationError( + "SCHEMA_ERROR", f"No schema URL for {vex_type} version {version}" + ) + ) + return {} + + # Validate URL scheme for security + if not self._is_safe_url(schema_url): + self.errors.append( + ValidationError( + "SCHEMA_ERROR", + f"Unsafe URL scheme detected. Only HTTP and HTTPS are allowed: {schema_url}", + ) + ) + return {} + + try: + # Download schema from official source + self.logger.debug(f"Downloading {vex_type} schema from {schema_url}") + # URL scheme validation performed by _is_safe_url method above + with urllib.request.urlopen( + schema_url, timeout=30 + ) as response: # nosec B310 + schema_data = json.loads(response.read().decode("utf-8")) + cache_key = f"{vex_type}:{version}" if version else vex_type + SCHEMA_CACHE[cache_key] = schema_data + self.logger.debug( + f"Successfully downloaded and cached {vex_type} schema" + ) + return schema_data + except Exception as e: + self.logger.warning(f"Failed to download {vex_type} schema: {str(e)}") + self.errors.append( + ValidationError( + "SCHEMA_ERROR", + f"Failed to download validation schema for {vex_type}: {str(e)}", + ) + ) + return {} + + def _is_safe_url(self, url: str) -> bool: + """ + Validate that URL uses safe scheme (HTTP or HTTPS only). + + Args: + url: URL to validate + + Returns: + True if URL scheme is safe, False otherwise + """ + try: + parsed = urllib.parse.urlparse(url) + return parsed.scheme.lower() in ("http", "https") + except Exception: + return False + + def _perform_format_specific_validation( + self, raw_data: Dict, vex_type: str + ) -> None: + """Perform format-specific validations beyond schema compliance.""" + if vex_type == "openvex": + statements = raw_data.get("statements", []) + for i, statement in enumerate(statements): + self._validate_openvex_statement(statement, i) + elif vex_type == "cyclonedx": + vulnerabilities = raw_data.get("vulnerabilities", []) + for i, vuln in enumerate(vulnerabilities): + self._validate_cyclonedx_vulnerability(vuln, i) + elif vex_type == "csaf": + vulnerabilities = raw_data.get("vulnerabilities", []) + for i, vuln in enumerate(vulnerabilities): + self._validate_csaf_vulnerability(vuln, i) + + def _validate_openvex_statement(self, statement: Dict, index: int) -> None: + """Validate an OpenVEX statement.""" + location = f"statements[{index}]" + + # Check for vulnerability name + vulnerability = statement.get("vulnerability", {}) + if not vulnerability.get("name"): + self.errors.append( + ValidationError( + "MISSING_FIELD", + "Missing required field 'vulnerability.name' in statement", + field="vulnerability.name", + location=location, + ) + ) + + # Check for status + status = statement.get("status") + if not status: + self.errors.append( + ValidationError( + "MISSING_FIELD", + "Missing required field 'status' in statement", + field="status", + location=location, + ) + ) + elif status not in self._get_valid_statuses("openvex"): + self.errors.append( + ValidationError( + "INVALID_VALUE", + f"Invalid status '{status}' for openvex. Valid values: {', '.join(self._get_valid_statuses('openvex'))}", + field="status", + location=location, + ) + ) + + def _validate_cyclonedx_vulnerability( + self, vulnerability: Dict, index: int + ) -> None: + """Validate a CycloneDX vulnerability.""" + location = f"vulnerabilities[{index}]" + + # Check for required ID field + if not vulnerability.get("id"): + self.errors.append( + ValidationError( + "MISSING_FIELD", + "Missing required field 'id' in vulnerability", + field="id", + location=location, + ) + ) + + # Check analysis state if present + analysis = vulnerability.get("analysis", {}) + if analysis: + state = analysis.get("state") + if state and state not in self._get_valid_statuses("cyclonedx"): + self.errors.append( + ValidationError( + "INVALID_VALUE", + f"Invalid analysis state '{state}' for CycloneDX. Valid values: {', '.join(self._get_valid_statuses('cyclonedx'))}", + field="analysis.state", + location=location, + ) + ) + + def _validate_csaf_vulnerability(self, vulnerability: Dict, index: int) -> None: + """Validate a CSAF vulnerability.""" + location = f"vulnerabilities[{index}]" + + # Check for CVE or other identifier + if not vulnerability.get("cve") and not vulnerability.get("ids"): + self.warnings.append( + ValidationError( + "MISSING_IDENTIFIER", + "Vulnerability has no CVE or identifier", + field="cve/ids", + location=location, + severity="warning", + ) + ) + + def _check_for_empty_sections(self, raw_data: Dict, vex_type: str) -> None: + """Check for empty vulnerability/statement sections and add warnings.""" + if vex_type == "cyclonedx": + vulnerabilities = raw_data.get("vulnerabilities", []) + if not vulnerabilities: + self.warnings.append( + ValidationError( + "EMPTY_SECTION", + "No vulnerabilities found in CycloneDX VEX document", + field="vulnerabilities", + severity="warning", + ) + ) + + elif vex_type == "csaf": + vulnerabilities = raw_data.get("vulnerabilities", []) + if not vulnerabilities: + self.warnings.append( + ValidationError( + "EMPTY_SECTION", + "No vulnerabilities found in CSAF VEX document", + field="vulnerabilities", + severity="warning", + ) + ) + + elif vex_type == "openvex": + statements = raw_data.get("statements", []) + if not statements: + self.warnings.append( + ValidationError( + "EMPTY_SECTION", + "No statements found in OpenVEX document", + field="statements", + severity="warning", + ) + ) + + def _get_valid_statuses(self, vex_type: str) -> List[str]: + """Get valid status values for a VEX type.""" + status_map = { + "cyclonedx": [ + "in_triage", + "exploitable", + "resolved", + "resolved_with_pedigree", + "false_positive", + "not_affected", + ], + "csaf": [ + "first_affected", + "first_fixed", + "fixed", + "known_affected", + "known_not_affected", + "last_affected", + "recommended", + "under_investigation", + ], + "openvex": ["not_affected", "affected", "fixed", "under_investigation"], + } + return status_map.get(vex_type, []) + + +def validate_vex_file(vex_file_path: str, logger=None, offline=False) -> int: + """ + Validate a VEX file and return appropriate exit code. + + Args: + vex_file_path: Path to the VEX file to validate + logger: Optional logger instance + offline: Whether to operate in offline mode + + Returns: + 0 if validation successful, 1 if validation failed + """ + if logger is None: + logger = LOGGER.getChild("vex-validate") + + # Validate file path + if not vex_file_path: + logger.error("No VEX file path provided") + return 1 + + validator = VEXValidator(logger, offline=offline) + is_valid, errors, warnings = validator.validate_file(vex_file_path) + + # Print results + logger.info(f"Validating VEX file: {vex_file_path}") + + if warnings: + logger.warning(f"Found {len(warnings)} warning(s):") + for warning in warnings: + logger.warning(f" {warning}") + + if errors: + logger.error(f"Found {len(errors)} error(s):") + for error in errors: + logger.error(f" {error}") + logger.error("VEX file validation FAILED") + return 1 + else: + logger.info("VEX file validation PASSED") + if warnings: + logger.info( + f"Note: {len(warnings)} warning(s) were found but do not prevent usage" + ) + return 0 diff --git a/test/test_vex_validate.py b/test/test_vex_validate.py new file mode 100644 index 0000000000..51cae5c81a --- /dev/null +++ b/test/test_vex_validate.py @@ -0,0 +1,610 @@ +# Copyright (C) 2025 Intel Corporation +# SPDX-License-Identifier: GPL-3.0-or-later + +import json +import shutil +import tempfile +import unittest +import urllib.error +from pathlib import Path +from unittest.mock import patch + +from cve_bin_tool.vex_manager.validate import ( + ValidationError, + VEXValidator, + validate_vex_file, +) + + +class TestVEXValidator(unittest.TestCase): + """Test cases for VEX validation functionality.""" + + def setUp(self): + """Set up test cases.""" + self.validator = VEXValidator() + self.temp_dir = Path(tempfile.mkdtemp(prefix="test_vex_validate-")) + + # Mock schema data for testing - minimal schemas that accept basic structure + self.mock_cyclonedx_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["bomFormat", "specVersion", "version"], + "properties": { + "bomFormat": {"type": "string", "enum": ["CycloneDX"]}, + "specVersion": {"type": "string"}, + "version": {"type": "integer"}, + "vulnerabilities": {"type": "array"}, + "metadata": {"type": "object"}, + }, + } + + self.mock_openvex_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["@context", "@id", "author"], + "properties": { + "@context": {"type": "string"}, + "@id": {"type": "string"}, + "author": {"type": "string"}, + "statements": {"type": "array"}, + "timestamp": {"type": "string"}, + }, + } + + self.mock_csaf_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["document", "vulnerabilities"], + "properties": { + "document": {"type": "object"}, + "vulnerabilities": {"type": "array"}, + }, + } + + # Add version-specific schemas for testing + self.mock_cyclonedx_16_schema = { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "required": ["bomFormat", "specVersion", "version"], + "properties": { + "bomFormat": {"type": "string", "enum": ["CycloneDX"]}, + "specVersion": {"type": "string", "enum": ["1.6"]}, + "version": {"type": "integer"}, + "vulnerabilities": {"type": "array"}, + "metadata": {"type": "object"}, + }, + } + + def tearDown(self): + """Clean up test files.""" + if self.temp_dir.exists(): + shutil.rmtree(self.temp_dir) + + def create_temp_vex_file(self, content: dict, filename: str = "test.json") -> str: + """Create a temporary VEX file with given content.""" + file_path = self.temp_dir / filename + with open(file_path, "w") as f: + json.dump(content, f, indent=2) + return str(file_path) + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._get_schema") + def test_valid_cyclonedx_vex(self, mock_get_schema): + """Test validation of a valid CycloneDX VEX file.""" + mock_get_schema.return_value = self.mock_cyclonedx_schema + + valid_cyclonedx = { + "bomFormat": "CycloneDX", + "specVersion": "1.6", + "version": 1, + "metadata": { + "timestamp": "2024-01-01T00:00:00Z", + "component": {"type": "application", "name": "test-app"}, + }, + "vulnerabilities": [ + {"id": "CVE-2024-0001", "analysis": {"state": "not_affected"}}, + ], + } + + file_path = self.create_temp_vex_file(valid_cyclonedx) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertTrue(is_valid, f"Validation errors: {errors}") + self.assertEqual(len(errors), 0) + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._get_schema") + def test_valid_openvex(self, mock_get_schema): + """Test validation of a valid OpenVEX file.""" + mock_get_schema.return_value = self.mock_openvex_schema + + valid_openvex = { + "@context": "https://openvex.dev/ns/v0.2.0", + "@id": "test-vex", + "author": "test-author", + "timestamp": "2024-01-01T00:00:00Z", + "statements": [ + { + "vulnerability": {"name": "CVE-2024-0001"}, + "status": "not_affected", + "products": [{"@id": "pkg:generic/test@1.0.0"}], + } + ], + } + + file_path = self.create_temp_vex_file(valid_openvex) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertTrue(is_valid, f"Validation errors: {errors}") + self.assertEqual(len(errors), 0) + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._get_schema") + def test_valid_csaf_vex(self, mock_get_schema): + """Test validation of a valid CSAF VEX file.""" + mock_get_schema.return_value = self.mock_csaf_schema + + valid_csaf = { + "document": { + "category": "csaf_vex", + "title": "Test VEX", + "publisher": {"name": "Test Publisher"}, + }, + "vulnerabilities": [ + { + "cve": "CVE-2024-0001", + "product_status": {"known_not_affected": ["product-1"]}, + } + ], + } + + file_path = self.create_temp_vex_file(valid_csaf) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertTrue(is_valid, f"Validation errors: {errors}") + self.assertEqual(len(errors), 0) + + def test_missing_file(self): + """Test validation of non-existent file.""" + non_existent_file = str(self.temp_dir / "missing.json") + is_valid, errors, warnings = self.validator.validate_file(non_existent_file) + + self.assertFalse(is_valid) + self.assertEqual(len(errors), 1) + self.assertEqual(errors[0].error_type, "FILE_ERROR") + self.assertIn("not found", errors[0].message) + + def test_invalid_file_extension(self): + """Test validation of file with invalid extension.""" + # Create a file with .txt extension + invalid_file = self.temp_dir / "test.txt" + invalid_file.write_text("{}") + + is_valid, errors, warnings = self.validator.validate_file(str(invalid_file)) + + self.assertFalse(is_valid) + self.assertEqual(len(errors), 1) + self.assertEqual(errors[0].error_type, "FILE_ERROR") + self.assertIn("Invalid file extension", errors[0].message) + + def test_invalid_json(self): + """Test validation of invalid JSON file.""" + invalid_json_file = self.temp_dir / "invalid.json" + invalid_json_file.write_text("{ invalid json") + + is_valid, errors, warnings = self.validator.validate_file( + str(invalid_json_file) + ) + + self.assertFalse(is_valid) + self.assertEqual(len(errors), 1) + self.assertEqual(errors[0].error_type, "PARSE_ERROR") + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._get_schema") + def test_schema_validation_failure(self, mock_get_schema): + """Test validation with schema validation failure.""" + mock_get_schema.return_value = self.mock_cyclonedx_schema + + # Create an invalid file missing required field + invalid_cyclonedx = { + "specVersion": "1.6", # Missing bomFormat + "version": 1, + "vulnerabilities": [], + } + + file_path = self.create_temp_vex_file(invalid_cyclonedx) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertFalse(is_valid) + self.assertGreaterEqual(len(errors), 1) + self.assertEqual(errors[0].error_type, "SCHEMA_ERROR") + + def test_unknown_format(self): + """Test validation with unknown VEX format.""" + unknown_format = {"type": "unknown", "version": "1.0", "data": {}} + + file_path = self.create_temp_vex_file(unknown_format) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertFalse(is_valid) + self.assertGreaterEqual(len(errors), 1) + self.assertIn("Could not detect VEX format", errors[0].message) + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._get_schema") + def test_empty_vulnerabilities_warning(self, mock_get_schema): + """Test that empty vulnerabilities section generates warning.""" + mock_get_schema.return_value = self.mock_cyclonedx_schema + + cyclonedx_no_vulns = { + "bomFormat": "CycloneDX", + "specVersion": "1.6", + "version": 1, + "metadata": {"timestamp": "2024-01-01T00:00:00Z"}, + "vulnerabilities": [], # Empty vulnerabilities + } + + file_path = self.create_temp_vex_file(cyclonedx_no_vulns) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertTrue(is_valid) # Should be valid but with warnings + self.assertEqual(len(errors), 0) + self.assertEqual(len(warnings), 1) + self.assertEqual(warnings[0].error_type, "EMPTY_SECTION") + + @patch("urllib.request.urlopen") + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._load_local_schema") + def test_schema_download_failure(self, mock_load_local, mock_urlopen): + """Test handling of schema download failure.""" + # Mock local schema loading to return None to force download + mock_load_local.return_value = {} + # Mock network failure + mock_urlopen.side_effect = Exception("Network error") + + cyclonedx = { + "bomFormat": "CycloneDX", + "specVersion": "1.6", + "version": 1, + } + + file_path = self.create_temp_vex_file(cyclonedx) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertFalse(is_valid) + self.assertGreaterEqual(len(errors), 1) + self.assertEqual(errors[0].error_type, "SCHEMA_ERROR") + self.assertIn("Failed to download", errors[0].message) + + @patch("urllib.request.urlopen") + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._load_local_schema") + def test_network_timeout(self, mock_load_local, mock_urlopen): + """Test handling of network timeout during schema download.""" + import socket + + # Mock local schema loading to return None to force download + mock_load_local.return_value = {} + mock_urlopen.side_effect = socket.timeout("Connection timed out") + + cyclonedx = { + "bomFormat": "CycloneDX", + "specVersion": "1.6", # Version not available locally + "version": 1, + } + + file_path = self.create_temp_vex_file(cyclonedx) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertFalse(is_valid) + self.assertGreaterEqual(len(errors), 1) + self.assertEqual(errors[0].error_type, "SCHEMA_ERROR") + self.assertIn("Failed to download", errors[0].message) + + @patch("urllib.request.urlopen") + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._load_local_schema") + def test_network_connection_error(self, mock_load_local, mock_urlopen): + """Test handling of network connection error during schema download.""" + # Mock local schema loading to return None to force download + mock_load_local.return_value = {} + mock_urlopen.side_effect = urllib.error.URLError("Connection refused") + + cyclonedx = { + "bomFormat": "CycloneDX", + "specVersion": "1.6", + "version": 1, + } + + file_path = self.create_temp_vex_file(cyclonedx) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertFalse(is_valid) + self.assertGreaterEqual(len(errors), 1) + self.assertEqual(errors[0].error_type, "SCHEMA_ERROR") + + def test_openvex_missing_required_fields(self): + """Test OpenVEX validation with missing required fields.""" + invalid_openvex = { + "@context": "https://openvex.dev/ns/v0.2.0", + "@id": "test-vex", + "author": "test-author", + "statements": [ + { + # Missing vulnerability.name + "status": "not_affected", + "products": [{"@id": "pkg:generic/test@1.0.0"}], + } + ], + } + + file_path = self.create_temp_vex_file(invalid_openvex) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertFalse(is_valid) + # Should have error about missing vulnerability.name + missing_field_errors = [e for e in errors if e.error_type == "MISSING_FIELD"] + self.assertGreater(len(missing_field_errors), 0) + + def test_cyclonedx_invalid_analysis_state(self): + """Test CycloneDX validation with invalid analysis state.""" + invalid_cyclonedx = { + "bomFormat": "CycloneDX", + "specVersion": "1.4", + "version": 1, + "vulnerabilities": [ + { + "id": "CVE-2024-0001", + "analysis": {"state": "invalid_state"}, # Invalid state + } + ], + } + + file_path = self.create_temp_vex_file(invalid_cyclonedx) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertFalse(is_valid) + # Should have error about invalid state + invalid_value_errors = [e for e in errors if e.error_type == "INVALID_VALUE"] + self.assertGreater(len(invalid_value_errors), 0) + + def test_utf8_encoding_handling(self): + """Test proper handling of UTF-8 encoded VEX files.""" + # Create VEX with non-ASCII characters + utf8_vex = { + "@context": "https://openvex.dev/ns/v0.2.0", + "@id": "test-vex-üñíçødé", # Non-ASCII characters + "author": "Test Authör", + "statements": [ + { + "vulnerability": {"name": "CVE-2024-0001"}, + "status": "not_affected", + "products": [{"@id": "pkg:generic/tëst@1.0.0"}], + } + ], + } + + file_path = self.create_temp_vex_file(utf8_vex, "utf8_test.json") + is_valid, errors, warnings = self.validator.validate_file(file_path) + + # Should handle UTF-8 encoding properly + self.assertTrue( + is_valid or len([e for e in errors if "encoding" in e.message.lower()]) == 0 + ) + + def test_version_detection_edge_cases(self): + """Test version detection for edge cases.""" + # Test CycloneDX without explicit version + no_version_cyclonedx = { + "bomFormat": "CycloneDx", # Different case + "version": 1, + } + + file_path = self.create_temp_vex_file(no_version_cyclonedx) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + # Should fail because bomFormat is case sensitive + self.assertFalse(is_valid) + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._get_schema") + def test_cyclonedx_version_16(self, mock_get_schema): + """Test validation of CycloneDX 1.6 VEX file.""" + mock_get_schema.return_value = self.mock_cyclonedx_16_schema + + cyclonedx_16 = { + "bomFormat": "CycloneDX", + "specVersion": "1.6", + "version": 1, + "metadata": { + "timestamp": "2024-01-01T00:00:00Z", + "component": {"type": "application", "name": "test-app"}, + }, + "vulnerabilities": [ + { + "id": "CVE-2024-0001", + "analysis": {"state": "not_affected"}, + "affects": [{"ref": "component-1"}], + }, + ], + } + + file_path = self.create_temp_vex_file(cyclonedx_16) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertTrue(is_valid, f"Validation errors: {errors}") + self.assertEqual(len(errors), 0) + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator._get_schema") + def test_cyclonedx_version_15(self, mock_get_schema): + """Test validation of CycloneDX 1.5 VEX file.""" + mock_get_schema.return_value = self.mock_cyclonedx_schema + + cyclonedx_15 = { + "bomFormat": "CycloneDX", + "specVersion": "1.5", + "version": 1, + "metadata": {"timestamp": "2024-01-01T00:00:00Z"}, + "vulnerabilities": [], + } + + file_path = self.create_temp_vex_file(cyclonedx_15) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + self.assertTrue(is_valid) + + def test_malformed_hybrid_format(self): + """Test validation of malformed VEX with mixed format indicators.""" + hybrid_format = { + "bomFormat": "CycloneDX", # CycloneDX indicator + "@context": "https://openvex.dev/ns/v0.2.0", # OpenVEX indicator + "document": {"title": "Test"}, # CSAF indicator + "version": 1, + } + + file_path = self.create_temp_vex_file(hybrid_format) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + # Should detect as CycloneDX (first match wins) + self.assertFalse(is_valid) # Will fail schema validation + + def test_large_file_performance(self): + """Test validation performance with large VEX file.""" + # Create a large VEX file with many vulnerabilities + large_cyclonedx = { + "bomFormat": "CycloneDX", + "specVersion": "1.4", + "version": 1, + "metadata": {"timestamp": "2024-01-01T00:00:00Z"}, + "vulnerabilities": [ + {"id": f"CVE-2024-{i:04d}", "analysis": {"state": "not_affected"}} + for i in range(1000) # 1000 vulnerabilities + ], + } + + file_path = self.create_temp_vex_file(large_cyclonedx, "large_test.json") + + # Measure validation time (should complete within reasonable time) + import time + + start_time = time.time() + is_valid, errors, warnings = self.validator.validate_file(file_path) + end_time = time.time() + + # Should complete within 10 seconds + self.assertLess(end_time - start_time, 10.0) + + +class TestVEXValidateCLI(unittest.TestCase): + """Test VEX validation CLI functionality.""" + + def setUp(self): + """Set up test cases.""" + self.temp_dir = Path(tempfile.mkdtemp(prefix="test_vex_validate_cli-")) + + def tearDown(self): + """Clean up test files.""" + if self.temp_dir.exists(): + shutil.rmtree(self.temp_dir) + + def create_temp_vex_file(self, content: dict, filename: str = "test.json") -> str: + """Create a temporary VEX file with given content.""" + file_path = self.temp_dir / filename + with open(file_path, "w") as f: + json.dump(content, f, indent=2) + return str(file_path) + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator.validate_file") + def test_validate_vex_file_valid(self, mock_validate): + """Test CLI function with valid VEX file.""" + # Mock successful validation + mock_validate.return_value = (True, [], []) + + valid_vex = { + "bomFormat": "CycloneDX", + "specVersion": "1.6", + "version": 1, + } + + file_path = self.create_temp_vex_file(valid_vex) + exit_code = validate_vex_file(file_path, offline=False) + self.assertEqual(exit_code, 0) + + @patch("cve_bin_tool.vex_manager.validate.VEXValidator.validate_file") + def test_validate_vex_file_invalid(self, mock_validate): + """Test CLI function with invalid VEX file.""" + # Mock validation failure + from cve_bin_tool.vex_manager.validate import ValidationError + + error = ValidationError("SCHEMA_ERROR", "Test error") + mock_validate.return_value = (False, [error], []) + + invalid_vex = {"invalid": "format"} + file_path = self.create_temp_vex_file(invalid_vex) + exit_code = validate_vex_file(file_path, offline=False) + self.assertEqual(exit_code, 1) + + def test_validate_vex_file_missing(self): + """Test CLI function with missing file.""" + missing_file = str(self.temp_dir / "missing.json") + exit_code = validate_vex_file(missing_file, offline=False) + self.assertEqual(exit_code, 1) + + def test_validate_vex_file_no_path(self): + """Test CLI function with no file path.""" + exit_code = validate_vex_file("", offline=False) + self.assertEqual(exit_code, 1) + + +class TestVEXValidateEnhanced(unittest.TestCase): + """Additional enhanced test cases for VEX validation.""" + + def setUp(self): + """Set up test cases.""" + self.temp_dir = Path(tempfile.mkdtemp(prefix="test_vex_validate_enhanced-")) + self.validator = VEXValidator() + + def tearDown(self): + """Clean up test files.""" + if self.temp_dir.exists(): + shutil.rmtree(self.temp_dir) + + def create_temp_vex_file(self, content: dict, filename: str = "test.json") -> str: + """Create a temporary VEX file with given content.""" + file_path = self.temp_dir / filename + with open(file_path, "w", encoding="utf-8") as f: + json.dump(content, f, indent=2, ensure_ascii=False) + return str(file_path) + + def test_error_severity_levels(self): + """Test that validation errors have appropriate severity levels.""" + # Create VEX with both errors and warnings + cyclonedx_with_issues = { + "bomFormat": "CycloneDX", + "specVersion": "1.4", + "version": 1, + "vulnerabilities": [], # Empty - should generate warning + } + + file_path = self.create_temp_vex_file(cyclonedx_with_issues) + is_valid, errors, warnings = self.validator.validate_file(file_path) + + # Check that warnings have correct severity + for warning in warnings: + self.assertEqual(warning.severity, "warning") + + # Check that errors have correct severity + for error in errors: + self.assertEqual(error.severity, "error") + + def test_validation_error_string_representation(self): + """Test ValidationError string representation.""" + error = ValidationError( + "TEST_ERROR", + "Test message", + field="test.field", + location="test[0]", + severity="error", + ) + + error_str = str(error) + self.assertIn("ERROR:TEST_ERROR", error_str) + self.assertIn("Test message", error_str) + self.assertIn("Field: test.field", error_str) + self.assertIn("Location: test[0]", error_str) + + +if __name__ == "__main__": + unittest.main()