diff --git a/schema/2.0/modules/cyclonedx-blueprint-2.0.schema.json b/schema/2.0/modules/cyclonedx-blueprint-2.0.schema.json index e014b9fdf..ec01b1d59 100644 --- a/schema/2.0/modules/cyclonedx-blueprint-2.0.schema.json +++ b/schema/2.0/modules/cyclonedx-blueprint-2.0.schema.json @@ -338,11 +338,9 @@ "description": "When the blueprint expires." }, "reviewFrequency": { - "type": "string", + "$ref": "cyclonedx-common-2.0.schema.json#/$defs/duration", "title": "Review Frequency", - "pattern": "^P(?!$)(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?$", - "description": "ISO 8601 duration for review frequency (e.g., `\"P3M\"` for quarterly).", - "examples": ["P1Y", "P3M", "P5W", "P23D"] + "description": "How often the blueprint is reviewed, as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration, for example `\"P3M\"` for quarterly." } } }, diff --git a/schema/2.0/modules/cyclonedx-common-2.0.schema.json b/schema/2.0/modules/cyclonedx-common-2.0.schema.json index 99052fc2d..7c4ae381f 100644 --- a/schema/2.0/modules/cyclonedx-common-2.0.schema.json +++ b/schema/2.0/modules/cyclonedx-common-2.0.schema.json @@ -679,6 +679,21 @@ "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$", "description": "An RFC 3339-compliant UTC timestamp using Zulu time (i.e., ending with `\"Z\"`). The format shall be `YYYY-MM-DDTHH:MM:SSZ` or include optional fractional seconds, e.g., `YYYY-MM-DDTHH:MM:SS.sssZ`. Offsets such as `\"+00:00\"` are not allowed." }, + "duration": { + "type": "string", + "title": "Duration", + "$comment": "The pattern only checks the leading designator on purpose. ISO 8601 already defines the full duration syntax, and repeating it as a complex regex here would duplicate the standard. Producers and consumers are expected to follow ISO 8601 in full.", + "pattern": "^P", + "minLength": 3, + "description": "[ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration.", + "examples": [ + "P1Y", + "P3M", + "P2W", + "P1DT12H", + "PT30M" + ] + }, "ordinalVersion": { "title": "Ordinal Version", "description": "An ordinal version is a dot-delimited, purely numeric identifier where each segment represents an ordered level in the hierarchy. The segments have no prescribed meaning beyond numeric ordering, allowing straightforward comparison and sorting.", diff --git a/schema/2.0/modules/cyclonedx-risk-2.0.schema.json b/schema/2.0/modules/cyclonedx-risk-2.0.schema.json index 251d5ec99..099c9a34b 100644 --- a/schema/2.0/modules/cyclonedx-risk-2.0.schema.json +++ b/schema/2.0/modules/cyclonedx-risk-2.0.schema.json @@ -512,10 +512,9 @@ "description": "The expected number of events within the timeframe, for frequency-based methods such as the [FAIR](https://www.fairinstitute.org/) loss event frequency. Unlike a probability, a frequency may exceed `1`." }, "timeframe": { - "type": "string", + "$ref": "cyclonedx-common-2.0.schema.json#/$defs/duration", "title": "Timeframe", - "description": "The period over which the probability or frequency is assessed, expressed as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration, for example `\"P1Y\"` for one year.", - "examples": ["P1Y", "P1M", "P23DT23H", "PT1M"] + "description": "The period over which the probability or frequency is assessed, expressed as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration, for example `\"P1Y\"` for one year." }, "range": { "$ref": "#/$defs/estimateRange", @@ -893,8 +892,7 @@ "description": "The number of affected users." }, "downtime": { - "type": "string", - "pattern": "^P(?!$)(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?(T(\\d+H)?(\\d+M)?(\\d+(\\.\\d+)?S)?)?$", + "$ref": "cyclonedx-common-2.0.schema.json#/$defs/duration", "description": "The expected downtime, as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration." }, "dataRecords": { @@ -902,8 +900,7 @@ "description": "The number of data records affected." }, "recovery": { - "type": "string", - "pattern": "^P(?!$)(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?(T(\\d+H)?(\\d+M)?(\\d+(\\.\\d+)?S)?)?$", + "$ref": "cyclonedx-common-2.0.schema.json#/$defs/duration", "description": "The recovery time, as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration." }, "financialLossRange": { @@ -1602,9 +1599,8 @@ "description": "The party accountable for setting and approving this appetite, such as a board or risk committee. May be an inline party object or a reference to a previously declared party." }, "horizon": { - "type": "string", - "description": "The time horizon over which this appetite applies, expressed as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration, for example `\"P1Y\"` for one year.", - "examples": ["P1Y", "P1M", "P23DT23H", "PT1M"] + "$ref": "cyclonedx-common-2.0.schema.json#/$defs/duration", + "description": "The time horizon over which this appetite applies, expressed as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration, for example `\"P1Y\"` for one year." }, "nextReview": { "type": "string", diff --git a/tools/src/test/resources/2.0/invalid-blueprint-review-frequency-2.0.json b/tools/src/test/resources/2.0/invalid-blueprint-review-frequency-2.0.json new file mode 100644 index 000000000..817c55863 --- /dev/null +++ b/tools/src/test/resources/2.0/invalid-blueprint-review-frequency-2.0.json @@ -0,0 +1,21 @@ +{ + "specFormat": "CycloneDX", + "specVersion": "2.0", + "serialNumber": "urn:uuid:4c2a7d3f-9e5b-4f8c-8b21-7d6e5f4a3b2c", + "version": 1, + "blueprints": [ + { + "refId": "bp-review-frequency-bare", + "name": "A bare designator is not a duration", + "modelTypes": [ + "data-flow" + ], + "metadata": { + "validityPeriod": { + "start": "2026-01-01T00:00:00Z", + "reviewFrequency": "P" + } + } + } + ] +} diff --git a/tools/src/test/resources/2.0/invalid-risk-likelihood-timeframe-2.0.json b/tools/src/test/resources/2.0/invalid-risk-likelihood-timeframe-2.0.json new file mode 100644 index 000000000..2ffa244a3 --- /dev/null +++ b/tools/src/test/resources/2.0/invalid-risk-likelihood-timeframe-2.0.json @@ -0,0 +1,18 @@ +{ + "specFormat": "CycloneDX", + "specVersion": "2.0", + "serialNumber": "urn:uuid:5d3b8e4a-1f6c-4a9d-9c32-8e7f6a5b4c3d", + "version": 1, + "risks": { + "risks": [ + { + "refId": "risk-timeframe", + "name": "Timeframe that is not a duration", + "statement": "The likelihood timeframe is free text instead of an ISO 8601 duration.", + "inherentRisk": { + "likelihood": { "level": "high", "timeframe": "one year" } + } + } + ] + } +} diff --git a/tools/src/test/resources/2.0/valid-blueprint-review-frequency-2.0.json b/tools/src/test/resources/2.0/valid-blueprint-review-frequency-2.0.json new file mode 100644 index 000000000..955787e87 --- /dev/null +++ b/tools/src/test/resources/2.0/valid-blueprint-review-frequency-2.0.json @@ -0,0 +1,21 @@ +{ + "specFormat": "CycloneDX", + "specVersion": "2.0", + "serialNumber": "urn:uuid:3b1f6c2e-8d4a-4e7b-9a10-6c5d4e3f2a1b", + "version": 1, + "blueprints": [ + { + "refId": "bp-review-frequency", + "name": "Blueprint with a review frequency that has a time part", + "modelTypes": [ + "data-flow" + ], + "metadata": { + "validityPeriod": { + "start": "2026-01-01T00:00:00Z", + "reviewFrequency": "P1DT12H" + } + } + } + ] +}