Skip to content

Commit 47f7adc

Browse files
committed
feat: implement OSV format
1 parent 0447bc9 commit 47f7adc

12 files changed

Lines changed: 645 additions & 38 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ export interface ExtendedStrategy<
102102
) => Promise<(VulnFormat | StandardVulnerability)[]>;
103103
}
104104

105-
export type BaseStrategyFormat = "Standard";
105+
export type BaseStrategyFormat =
106+
| "Standard"
107+
| "OSV";
106108

107109
export interface BaseStrategyOptions {
108110
useFormat?: BaseStrategyFormat;
@@ -124,6 +126,7 @@ Where `dependencies` is the dependencies **Map()** object of the NodeSecure Scan
124126
125127
### Formats
126128
- [Standard](./docs/formats/standard.md)
129+
- [OSV](./docs/formats/osv.md)
127130

128131
### Databases
129132
- [OSV](./docs/database/osv.md)

docs/database/osv.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,7 @@ Lean more at [osv.dev](https://osv.dev/)
88

99
## Format
1010

11-
The OSV interface is exported as root like `StandardVulnerability`.
12-
13-
```ts
14-
export interface OSV {
15-
schema_version: string;
16-
id: string;
17-
modified: string;
18-
published: string;
19-
withdraw: string;
20-
aliases: string[];
21-
related: string[];
22-
summary: string;
23-
details: string;
24-
severity: OSVSeverity[];
25-
affected: OSVAffected[];
26-
references: {
27-
type: OSVReferenceType;
28-
url: string;
29-
}[];
30-
credits: {
31-
name: string;
32-
contact: string[];
33-
type: OSVCreditType;
34-
}[];
35-
database_specific: Record<string, any>;
36-
}
37-
```
11+
See the [OSV format](../formats/osv.md) documentation.
3812

3913
## API
4014

docs/formats/osv.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# OSV vulnerability format
2+
3+
The [Open Source Vulnerability (OSV) schema](https://ossf.github.io/osv-schema/) is an open, precise, and human-readable format for describing vulnerabilities, maintained by the OpenSSF. It is designed to be interoperable across ecosystems and tooling.
4+
5+
This format can be activated with the `useFormat` option set to `"OSV"`.
6+
7+
## TypeScript interfaces
8+
9+
```ts
10+
export interface OSV {
11+
schema_version?: string;
12+
id: string;
13+
modified: string;
14+
published: string;
15+
withdraw?: string;
16+
aliases: string[];
17+
upstream: string[];
18+
related?: string[];
19+
summary: string;
20+
details: string;
21+
severity: OSVSeverity[];
22+
affected: OSVAffected[];
23+
references: {
24+
type: OSVReferenceType;
25+
url: string;
26+
}[];
27+
credits: {
28+
name: string;
29+
contact: string[];
30+
type: OSVCreditType;
31+
}[];
32+
database_specific: Record<string, any>;
33+
}
34+
35+
export interface OSVAffected {
36+
package: {
37+
ecosystem: "npm";
38+
name: string;
39+
purl: string;
40+
};
41+
severity: OSVSeverity[];
42+
ranges: OSVRange[];
43+
versions: string[];
44+
ecosystem_specific: Record<string, any>;
45+
database_specific: Record<string, any>;
46+
}
47+
48+
export interface OSVRange {
49+
type: string;
50+
repo?: string; // Only required for GIT type
51+
events: {
52+
introduced?: string;
53+
fixed?: string;
54+
last_affected?: string;
55+
limit?: string;
56+
}[];
57+
database_specific: Record<string, any>;
58+
}
59+
60+
export interface OSVSeverity {
61+
type: string;
62+
score: string;
63+
}
64+
65+
export type OSVReferenceType =
66+
| "ADVISORY"
67+
| "ARTICLE"
68+
| "DETECTION"
69+
| "DISCUSSION"
70+
| "REPORT"
71+
| "FIX"
72+
| "GIT"
73+
| "INTRODUCED"
74+
| "PACKAGE"
75+
| "EVIDENCE"
76+
| "WEB";
77+
78+
export type OSVCreditType =
79+
| "FINDER"
80+
| "REPORTER"
81+
| "ANALYST"
82+
| "COORDINATOR"
83+
| "REMEDIATION_DEVELOPER"
84+
| "REMEDIATION_REVIEWER"
85+
| "REMEDIATION_VERIFIER"
86+
| "TOOL"
87+
| "SPONSOR"
88+
| "OTHER";
89+
```

src/formats/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import {
55
standardVulnerabilityMapper,
66
type StandardizeKind
77
} from "./standard/index.ts";
8+
import {
9+
osvVulnerabilityMapper,
10+
type OSVKind
11+
} from "./osv/index.ts";
812

913
export function formatVulnsPayload(
1014
format: BaseStrategyFormat | null = null
1115
) {
1216
return function formatVulnerabilities(
13-
strategy: StandardizeKind,
17+
strategy: StandardizeKind | OSVKind,
1418
vulnerabilities: any[]
1519
) {
1620
if (format === "Standard") {
@@ -19,6 +23,12 @@ export function formatVulnsPayload(
1923
vulnerabilities
2024
);
2125
}
26+
if (format === "OSV") {
27+
return osvVulnerabilityMapper(
28+
strategy,
29+
vulnerabilities
30+
);
31+
}
2232

2333
// identity function
2434
return vulnerabilities;

src/formats/osv/index.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
// Import Internal Dependencies
2+
import { OSV_VULN_MAPPERS } from "./mappers.ts";
13

24
/**
35
* @see https://ossf.github.io/osv-schema/
46
*/
57
export interface OSV {
6-
schema_version: string;
8+
schema_version?: string;
79
id: string;
810
modified: string;
911
published: string;
10-
withdraw: string;
12+
withdraw?: string;
1113
aliases: string[];
12-
related: string[];
14+
upstream: string[];
15+
related?: string[];
1316
summary: string;
1417
details: string;
1518
severity: OSVSeverity[];
@@ -64,7 +67,7 @@ export interface OSVAffected {
6467

6568
export interface OSVRange {
6669
type: string;
67-
repo: string;
70+
repo?: string;
6871
events: {
6972
introduced?: string;
7073
fixed?: string;
@@ -78,3 +81,16 @@ export interface OSVSeverity {
7881
type: string;
7982
score: string;
8083
}
84+
85+
export type OSVKind = keyof typeof OSV_VULN_MAPPERS;
86+
87+
export function osvVulnerabilityMapper(
88+
strategy: OSVKind,
89+
vulnerabilities: any[]
90+
): OSV[] {
91+
if (!(strategy in OSV_VULN_MAPPERS)) {
92+
return [];
93+
}
94+
95+
return vulnerabilities.map(OSV_VULN_MAPPERS[strategy]);
96+
}

0 commit comments

Comments
 (0)