Skip to content

Commit 249ef31

Browse files
feat: bom.vulnerabilities data models and enums (#419)
* Added * New vulnerability-related enums were added in a new namespace `Enums.Vulnerability` ([#164] via [#419]) _Release stage is “beta”._ These namespace and enums have been released to third-party developers experimentally for the purpose of collecting feedback. These enums should not be used in production, because their contracts may change without notice. * `AffectStatus` * `AnalysisJustification` * `AnalysisResponse` * `AnalysisState` * `RatingMethod` * `Severity` * New vulnerability-related models were added in a new namespace `Models.Vulnerability` ([#164] via [#419]) _Release stage is “beta”._ These namespace and models have been released to third-party developers experimentally for the purpose of collecting feedback. These models should not be used in production, because their contracts may change without notice. _Attention_: The models are not yet supported by shipped serializers nor shipped normalizers. * `Advisory`, `AdvisoryRepository` * `Affect`, `AffectRepository`, `AffectedSingleVersion`, `AffectedVersionRange`, `AffectedVersionRepository` * `Analysis` * `Credits` * `Rating`, `RatingRepository` * `Reference`, `ReferenceRepository` * `Source` * `Vulnerability`, `VulnerabilityRepository` * New class `Models.OrganizationalEntityRepository` to represent a collection of `Models.OrganizationalEntity` (via [#419]) Additionally, `Models.OrganizationalEntity.compare()` was implemented. * New types and related functionality Common Weaknesses Enumerations (CWE) were added (via [#419]) _Release stage is “beta”._ These types, functions and classes have been released to third-party developers experimentally for the purpose of collecting feedback. These types, functions and classes should not be used in production, because their contracts may change without notice. * type `Types.CWE` * runtime validation `Types.isCWE()` * class `Types.CweRepository` --------- Signed-off-by: Peter Wagner <[email protected]> Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: Peter Wagner <[email protected]>
1 parent 5286fe5 commit 249ef31

37 files changed

+1240
-12
lines changed

HISTORY.md

+29
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,41 @@ All notable changes to this project will be documented in this file.
44

55
## unreleased
66

7+
* Added
8+
* New vulnerability-related enums were added in a new namespace `Enums.Vulnerability` ([#164] via [#419])
9+
_Release stage is “beta”._ These namespace and enums have been released to third-party developers experimentally for the purpose of collecting feedback. These enums should not be used in production, because their contracts may change without notice.
10+
* `AffectStatus`
11+
* `AnalysisJustification`
12+
* `AnalysisResponse`
13+
* `AnalysisState`
14+
* `RatingMethod`
15+
* `Severity`
16+
* New vulnerability-related models were added in a new namespace `Models.Vulnerability` ([#164] via [#419])
17+
_Release stage is “beta”._ These namespace and models have been released to third-party developers experimentally for the purpose of collecting feedback. These models should not be used in production, because their contracts may change without notice.
18+
_Attention_: The models are not yet supported by shipped serializers nor shipped normalizers.
19+
* `Advisory`, `AdvisoryRepository`
20+
* `Affect`, `AffectRepository`, `AffectedSingleVersion`, `AffectedVersionRange`, `AffectedVersionRepository`
21+
* `Analysis`
22+
* `Credits`
23+
* `Rating`, `RatingRepository`
24+
* `Reference`, `ReferenceRepository`
25+
* `Source`
26+
* `Vulnerability`, `VulnerabilityRepository`
27+
* New class `Models.OrganizationalEntityRepository` to represent a collection of `Models.OrganizationalEntity` (via [#419])
28+
Additionally, `Models.OrganizationalEntity.compare()` was implemented.
29+
* New types and related functionality Common Weaknesses Enumerations (CWE) were added (via [#419])
30+
_Release stage is “beta”._ These types, functions and classes have been released to third-party developers experimentally for the purpose of collecting feedback. These types, functions and classes should not be used in production, because their contracts may change without notice.
31+
* type `Types.CWE`
32+
* runtime validation `Types.isCWE()`
33+
* class `Types.CweRepository`
734
* Docs
835
* Use [TSDoc](https://tsdoc.org/) syntax in TypeScript files, instead of [JSDoc](https://jsdoc.app/) (via [#318], [#453])
936
* Misc
1037
* Added tests for internal helpers (via [#454])
1138

39+
[#164]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/164
1240
[#318]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/318
41+
[#419]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/419
1342
[#453]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/453
1443
[#454]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/454
1544

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ written in _TypeScript_ and compiled for the target.
3838
* `ComponentType`
3939
* `ExternalReferenceType`
4040
* `HashAlgorithm`
41+
* Vulnerability related:
42+
_Release stage is “beta”._ These namespace and enums have been released to third-party developers experimentally for the purpose of collecting feedback. These enums should not be used in production, because their contracts may change without notice.
43+
* `AffectStatus`
44+
* `AnalysisJustification`
45+
* `AnalysisResponse`
46+
* `AnalysisState`
47+
* `RatingMethod`
48+
* `Severity`
4149
* Data models for the following use cases:
4250
* `Attachment`
4351
* `Bom`
@@ -48,10 +56,21 @@ written in _TypeScript_ and compiled for the target.
4856
* `LicenseExpression`, `NamedLicense`, `SpdxLicense`, `LicenseRepository`
4957
* `Metadata`
5058
* `OrganizationalContact`, `OrganizationalContactRepository`
51-
* `OrganizationalEntity`
59+
* `OrganizationalEntity`, `OrganizationalEntityRepository`
5260
* `Property`, `PropertyRepository`
5361
* `SWID`
5462
* `Tool`, `ToolRepository`
63+
* Vulnerability related:
64+
_Release stage is “beta”._ These namespace and models have been released to third-party developers experimentally for the purpose of collecting feedback. These models should not be used in production, because their contracts may change without notice.
65+
_Attention_: These models are not yet supported by serializers nor normalizers.
66+
* `Advisory`, `AdvisoryRepository`
67+
* `Affect`, `AffectRepository`, `AffectedSingleVersion`, `AffectedVersionRange`, `AffectedVersionRepository`
68+
* `Analysis`
69+
* `Credits`
70+
* `Rating`, `RatingRepository`
71+
* `Reference`, `ReferenceRepository`
72+
* `Source`
73+
* `Vulnerability`, `VulnerabilityRepository`
5574
* Factories for the following use cases:
5675
* Create data models from any license descriptor string
5776
* Create `PackageURL` from `Component` data models

src/_helpers/sortable.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ abstract class SortableSet<TItem> extends Set<TItem> implements SortableIterable
7373
}
7474
}
7575

76-
export abstract class SortableComparables<TItem extends Comparable<TItem>> extends SortableSet<TItem> {
76+
export class SortableComparables<TItem extends Comparable<TItem>> extends SortableSet<TItem> {
7777
protected [compareObjectsSymbol] (a: TItem, b: TItem): number {
7878
return a.compare(b)
7979
}
8080
}
8181

82-
export abstract class SortableStringables<TItem extends Stringable = Stringable> extends SortableSet<TItem> {
82+
export class SortableStringables<TItem extends Stringable = Stringable> extends SortableSet<TItem> {
8383
protected [compareObjectsSymbol] (a: TItem, b: TItem): number {
8484
return a.toString().localeCompare(b.toString())
8585
}
8686
}
8787

88-
export abstract class SortableNumbers<TItem extends number = number> extends SortableSet<TItem> {
88+
export class SortableNumbers<TItem extends number = number> extends SortableSet<TItem> {
8989
protected [compareObjectsSymbol] (a: TItem, b: TItem): number {
9090
return a - b
9191
}

src/enums/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ export * from './componentScope'
2222
export * from './componentType'
2323
export * from './externalReferenceType'
2424
export * from './hashAlogorithm'
25+
26+
/** @beta */
27+
export * as Vulnerability from './vulnerability'
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
/** @beta */
21+
export enum AffectStatus {
22+
Affected = 'affected',
23+
Unaffected = 'unaffected',
24+
Unknown = 'unknown',
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
/** @beta */
21+
export enum AnalysisJustification {
22+
CodeNotPresent = 'code_not_present',
23+
CodeNotReachable = 'code_not_reachable',
24+
RequiresConfiguration = 'requires_configuration',
25+
RequiresDependency = 'requires_dependency',
26+
RequiresEnvironment = 'requires_environment',
27+
ProtectedByCompiler = 'protected_by_compiler',
28+
ProtectedAtRuntime = 'protected_at_runtime',
29+
ProtectedAtPerimeter = 'protected_at_perimeter',
30+
ProtectedByMitigatingControl = 'protected_by_mitigating_control',
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
import { SortableStringables } from '../../_helpers/sortable'
21+
22+
/** @beta */
23+
export enum AnalysisResponse {
24+
CanNotFix = 'can_not_fix',
25+
WillNotFix = 'will_not_fix',
26+
Update = 'update',
27+
Rollback = 'rollback',
28+
WorkaroundAvailable = 'workaround_available',
29+
}
30+
31+
/** @beta */
32+
export class AnalysisResponseRepository extends SortableStringables<AnalysisResponse> {
33+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
/** @beta */
21+
export enum AnalysisState {
22+
Resolved = 'resolved',
23+
ResolvedWithPedigree = 'resolved_with_pedigree',
24+
Exploitable = 'exploitable',
25+
InTriage = 'in_triage',
26+
FalsePositive = 'false_positive',
27+
NotAffected = 'not_affected',
28+
}

src/enums/vulnerability/index.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
export * from './affectStatus'
21+
export * from './analysisJustification'
22+
export * from './analysisResponse'
23+
export * from './analysisState'
24+
export * from './ratingMethod'
25+
export * from './severity'
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
/**
21+
* Specifies the severity or risk scoring methodology or standard used.
22+
*
23+
* @beta
24+
*/
25+
export enum RatingMethod {
26+
/** [CVSS v2 standard](https://www.first.org/cvss/v2/) */
27+
CVSSv2 = 'CVSSv2',
28+
/** [CVSS v3.0 standard](https://www.first.org/cvss/v3-0/) */
29+
CVSSv3 = 'CVSSv3',
30+
/** [CVSS v3.1 standard](https://www.first.org/cvss/v3-1/) */
31+
CVSSv31 = 'CVSSv31',
32+
/** [OWASP Risk Rating](https://owasp.org/www-community/OWASP_Risk_Rating_Methodology) */
33+
OWASP = 'OWASP',
34+
Other = 'other',
35+
}

src/enums/vulnerability/severity.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
/**
21+
* Textual representation of the severity of the vulnerability adopted by the analysis method.
22+
* If the analysis method uses values other than what is provided, the user is expected to translate appropriately.
23+
*
24+
* @beta
25+
*/
26+
export enum Severity {
27+
Critical = 'critical',
28+
High = 'high',
29+
Medium = 'medium',
30+
Low = 'low',
31+
Info = 'info',
32+
None = 'none',
33+
Unknown = 'unknown',
34+
}

src/models/bom.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ import type { PositiveInteger, UrnUuid } from '../types'
2121
import { isPositiveInteger, isUrnUuid } from '../types'
2222
import { ComponentRepository } from './component'
2323
import { Metadata } from './metadata'
24+
import { VulnerabilityRepository } from './vulnerability'
2425

2526
export interface OptionalBomProperties {
2627
metadata?: Bom['metadata']
2728
components?: Bom['components']
2829
version?: Bom['version']
30+
vulnerabilities?: Bom['vulnerabilities']
2931
serialNumber?: Bom['serialNumber']
3032
}
3133

3234
export class Bom {
3335
metadata: Metadata
3436
components: ComponentRepository
37+
vulnerabilities: VulnerabilityRepository
3538

3639
/** @see {@link version} */
3740
#version: PositiveInteger = 1
@@ -53,6 +56,7 @@ export class Bom {
5356
this.metadata = op.metadata ?? new Metadata()
5457
this.components = op.components ?? new ComponentRepository()
5558
this.version = op.version ?? this.version
59+
this.vulnerabilities = op.vulnerabilities ?? new VulnerabilityRepository()
5660
this.serialNumber = op.serialNumber
5761
}
5862

src/models/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ export * from './organizationalEntity'
3030
export * from './property'
3131
export * from './swid'
3232
export * from './tool'
33+
34+
/** @beta */
35+
export * as Vulnerability from './vulnerability'

src/models/organizationalContact.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ export class OrganizationalContact implements Comparable<OrganizationalContact>
4646
}
4747
}
4848

49-
export class OrganizationalContactRepository extends SortableComparables<OrganizationalContact> {
50-
}
49+
export class OrganizationalContactRepository extends SortableComparables<OrganizationalContact> {}

0 commit comments

Comments
 (0)