@renovatebot/osv-offline-db 1.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Jamie Magee <jamie.magee@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # osv-offline-db
2
+
3
+ [![Package version](https://img.shields.io/npm/v/@renovatebot/osv-offline-db?style=for-the-badge)](https://www.npmjs.com/package/@renovatebot/osv-offline-db)
4
+ [![Build status](https://img.shields.io/github/actions/workflow/status/renovatebot/osv-offline/build.yml?branch=main&style=for-the-badge)](https://github.com/renovatebot/osv-offline/actions/workflows/build.yml)
5
+ [![MIT license](https://img.shields.io/badge/license-MIT-blue?style=for-the-badge)](./LICENSE)
6
+
7
+ ## License
8
+
9
+ This package is licensed under [the MIT license](https://opensource.org/licenses/MIT).
10
+
11
+ Vulnerabilities are provided from the following upstream data sources and licenses:
12
+
13
+ - [GitHub Advisory Database](https://github.com/github/advisory-database) ([CC-BY 4.0](https://github.com/github/advisory-database/blob/main/LICENSE.md))
14
+ - [PyPI Advisory Database](https://github.com/pypa/advisory-database) ([CC-BY 4.0](https://github.com/pypa/advisory-database/blob/main/LICENSE))
15
+ - [Go Vulnerability Database](https://github.com/golang/vulndb) ([CC-BY 4.0](https://github.com/golang/vulndb#license))
16
+ - [Rust Advisory Database](https://github.com/RustSec/advisory-db) ([CC0 1.0](https://github.com/rustsec/advisory-db/blob/main/LICENSE.txt))
17
+ - [Global Security Database](https://github.com/cloudsecurityalliance/gsd-database) ([CC0 1.0](https://github.com/cloudsecurityalliance/gsd-database/blob/main/LICENSE))
18
+ - [OSS-Fuzz](https://github.com/google/oss-fuzz-vulns) ([CC-BY 4.0](https://github.com/google/oss-fuzz-vulns/blob/main/LICENSE))
@@ -0,0 +1,3 @@
1
+ export { OsvOfflineDb } from './lib/db';
2
+ export { Ecosystem, ecosystems } from './lib/ecosystem';
3
+ export * as Osv from './lib/osv';
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Osv = exports.ecosystems = exports.OsvOfflineDb = void 0;
37
+ var db_1 = require("./lib/db");
38
+ Object.defineProperty(exports, "OsvOfflineDb", { enumerable: true, get: function () { return db_1.OsvOfflineDb; } });
39
+ var ecosystem_1 = require("./lib/ecosystem");
40
+ Object.defineProperty(exports, "ecosystems", { enumerable: true, get: function () { return ecosystem_1.ecosystems; } });
41
+ exports.Osv = __importStar(require("./lib/osv"));
@@ -0,0 +1,10 @@
1
+ import { Ecosystem } from './ecosystem';
2
+ import type { Osv } from '..';
3
+ export declare class OsvOfflineDb {
4
+ static readonly rootDirectory: string;
5
+ private db;
6
+ private constructor();
7
+ private initialize;
8
+ static create(): Promise<OsvOfflineDb>;
9
+ query(ecosystem: Ecosystem, packageName: string): Promise<Osv.Vulnerability[]>;
10
+ }
package/dist/lib/db.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OsvOfflineDb = void 0;
7
+ const os_1 = require("os");
8
+ const path_1 = __importDefault(require("path"));
9
+ const nedb_1 = __importDefault(require("@seald-io/nedb"));
10
+ const ecosystem_1 = require("./ecosystem");
11
+ const purl_helper_1 = require("./purl-helper");
12
+ class OsvOfflineDb {
13
+ static rootDirectory = process.env.OSV_OFFLINE_ROOT_DIR ?? path_1.default.join((0, os_1.tmpdir)(), 'osv-offline');
14
+ db = {};
15
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
16
+ constructor() { }
17
+ async initialize() {
18
+ for (const ecosystem of ecosystem_1.ecosystems) {
19
+ this.db[ecosystem] = new nedb_1.default({
20
+ filename: path_1.default.join(OsvOfflineDb.rootDirectory, `${ecosystem.toLowerCase()}.nedb`),
21
+ });
22
+ await this.db[ecosystem].loadDatabaseAsync();
23
+ }
24
+ }
25
+ static async create() {
26
+ const osvOfflineDb = new OsvOfflineDb();
27
+ await osvOfflineDb.initialize();
28
+ return osvOfflineDb;
29
+ }
30
+ async query(ecosystem, packageName) {
31
+ return await this.db[ecosystem].findAsync({
32
+ affected: {
33
+ $elemMatch: {
34
+ package: {
35
+ name: packageName,
36
+ ecosystem,
37
+ purl: (0, purl_helper_1.packageToPurl)(ecosystem, packageName),
38
+ },
39
+ },
40
+ },
41
+ });
42
+ }
43
+ }
44
+ exports.OsvOfflineDb = OsvOfflineDb;
@@ -0,0 +1,2 @@
1
+ export declare const ecosystems: readonly ["crates.io", "Go", "Hackage", "Hex", "Maven", "npm", "NuGet", "Packagist", "Pub", "PyPI", "RubyGems"];
2
+ export type Ecosystem = (typeof ecosystems)[number];
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ecosystems = void 0;
4
+ // https://github.com/google/osv.dev/blob/b8ec0096f93f062993dee57f8b902f257993be88/osv/ecosystems/_ecosystems.py#L38-L68
5
+ exports.ecosystems = [
6
+ 'crates.io',
7
+ 'Go',
8
+ 'Hackage',
9
+ 'Hex',
10
+ 'Maven',
11
+ 'npm',
12
+ 'NuGet',
13
+ 'Packagist',
14
+ 'Pub',
15
+ 'PyPI',
16
+ 'RubyGems',
17
+ ];
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A schema for describing a vulnerability in an open source package.
3
+ *
4
+ * https://github.com/ossf/osv-schema/blob/main/validation/schema.json
5
+ */
6
+ export interface Vulnerability {
7
+ schema_version?: string;
8
+ id: string;
9
+ modified: string;
10
+ published?: string;
11
+ withdrawn?: string;
12
+ aliases?: string[];
13
+ related?: string[];
14
+ summary?: string;
15
+ details?: string;
16
+ severity?: Severity[];
17
+ affected?: Affected[];
18
+ references?: Reference[];
19
+ credits?: Credit[];
20
+ database_specific?: Record<string, unknown>;
21
+ }
22
+ export interface Affected {
23
+ package?: Package;
24
+ severity?: Severity[];
25
+ ranges?: Range[];
26
+ versions?: string[];
27
+ ecosystem_specific?: Record<string, unknown>;
28
+ database_specific?: Record<string, unknown>;
29
+ }
30
+ export interface Severity {
31
+ type: SeverityType;
32
+ score: string;
33
+ }
34
+ export type SeverityType = 'CVSS_V4' | 'CVSS_V3' | 'CVSS_V2';
35
+ export interface Package {
36
+ ecosystem: string;
37
+ name: string;
38
+ purl?: string;
39
+ }
40
+ export interface Range {
41
+ type: RangeType;
42
+ repo?: string;
43
+ events: Event[];
44
+ database_specific?: Record<string, unknown>;
45
+ }
46
+ export type RangeType = 'ECOSYSTEM' | 'GIT' | 'SEMVER';
47
+ export interface Event {
48
+ introduced?: string;
49
+ fixed?: string;
50
+ last_affected?: string;
51
+ limit?: string;
52
+ }
53
+ export interface Reference {
54
+ type: ReferenceType;
55
+ url: string;
56
+ }
57
+ export interface Credit {
58
+ name: string;
59
+ contact?: string[];
60
+ type: CreditType;
61
+ }
62
+ export type ReferenceType = 'ADVISORY' | 'ARTICLE' | 'DETECTION' | 'DISCUSSION' | 'REPORT' | 'FIX' | 'GIT' | 'INTRODUCED' | 'PACKAGE' | 'EVIDENCE' | 'WEB';
63
+ export type CreditType = 'FINDER' | 'REPORTER' | 'ANALYST' | 'COORDINATOR' | 'REMEDIATION_DEVELOPER' | 'REMEDIATION_REVIEWER' | 'REMEDIATION_VERIFIER' | 'TOOL' | 'SPONSOR' | 'OTHER';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import type { Ecosystem } from './ecosystem';
2
+ export declare function packageToPurl(ecosystem: Ecosystem, packageName: string): string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageToPurl = packageToPurl;
4
+ // https://github.com/google/osv.dev/blob/edacbd3c32b1d632bad8c5b506a14d0850b2e537/osv/purl_helpers.py#L18-L30
5
+ const PURL_ECOSYSTEMS = {
6
+ 'crates.io': 'cargo',
7
+ Go: 'golang',
8
+ Hackage: 'hackage',
9
+ Hex: 'hex',
10
+ Maven: 'maven',
11
+ NuGet: 'nuget',
12
+ npm: 'npm',
13
+ Packagist: 'composer',
14
+ PyPI: 'pypi',
15
+ Pub: 'pub',
16
+ RubyGems: 'gem',
17
+ };
18
+ function urlEncode(packageName) {
19
+ const parts = packageName.split('/');
20
+ return parts.map(encodeURIComponent).join('/');
21
+ }
22
+ function packageToPurl(ecosystem, packageName) {
23
+ let packageNamePurl = packageName;
24
+ const purlType = PURL_ECOSYSTEMS[ecosystem];
25
+ if (purlType === 'maven') {
26
+ packageNamePurl = packageName.replace(':', '/');
27
+ }
28
+ return `pkg:${purlType}/${urlEncode(packageNamePurl)}`;
29
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@renovatebot/osv-offline-db",
3
+ "version": "1.0.0-next.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "license": "MIT",
7
+ "type": "commonjs",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/renovatebot/osv-offline.git"
14
+ },
15
+ "dependencies": {
16
+ "@seald-io/nedb": "^4.1.2"
17
+ },
18
+ "devDependencies": {
19
+ "@tsconfig/node18": "18.2.4",
20
+ "@tsconfig/strictest": "2.0.6",
21
+ "@types/fs-extra": "11.0.4",
22
+ "@types/node": "18.19.129",
23
+ "fs-extra": "11.3.2"
24
+ },
25
+ "engines": {
26
+ "node": ">=18.12.0"
27
+ }
28
+ }