walkdiff 0.9.0 → 0.10.0
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/CHANGELOG.md +5 -0
- package/README.md +6 -5
- package/package.json +1 -1
- package/walkdiff.mjs +489 -74
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
- **Dependency checks for Go and Java:** PRs that add or bump dependencies in `go.mod`, `pom.xml`, `build.gradle`, `build.gradle.kts`, Gradle version catalogs (`*.versions.toml`) or `gradle.lockfile` now get what npm, Cargo and Python ones get. Each new direct dependency is noted, checked for trust (known malicious, not on its registry, very new, or a lookalike name) and against your licence allowlist, and versions new to the build are looked up in OSV. Go and Maven packages are looked up through [deps.dev](https://deps.dev), which covers the Go module proxy, Maven Central and Google's Maven repository. `go.sum` isn't read, since it lists versions the build dropped, and a Maven module of the project's own group is recognised as part of the project.
|
|
6
|
+
- **A website:** [navasvarela.github.io/walkdiff](https://navasvarela.github.io/walkdiff/) presents what Walkdiff is for, a short manual of every feature, and a real report to try before installing anything.
|
|
7
|
+
|
|
3
8
|
## 0.9.0
|
|
4
9
|
|
|
5
10
|
- **Go, Java, C and C++:** files in these languages now get what Rust, TypeScript and Python files get. That means changed functions, methods and types as units with change facts, callers traced across the repository, function metrics, risky-API rules and syntax highlighting.
|
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
A review companion for GitHub pull requests and GitLab merge requests. `walkdiff review <url>` fetches the
|
|
6
6
|
change, analyzes it, and serves a local report.
|
|
7
7
|
|
|
8
|
-
Status: early release, [v0.
|
|
8
|
+
Status: early release, [v0.10.0](CHANGELOG.md). To run it on your team's PRs, see the [pilot guide](docs/pilot.md).
|
|
9
9
|
|
|
10
|
-
**Documentation:** [getting started](docs/getting-started.md), [configuration](docs/configuration.md), [troubleshooting](docs/troubleshooting.md), [security policy](SECURITY.md).
|
|
10
|
+
**Documentation:** [website](https://navasvarela.github.io/walkdiff/), [getting started](docs/getting-started.md), [configuration](docs/configuration.md), [troubleshooting](docs/troubleshooting.md), [security policy](SECURITY.md).
|
|
11
11
|
|
|
12
12
|
## What the report shows
|
|
13
13
|
|
|
@@ -32,8 +32,9 @@ All changes has five tabs, including **Conversation** in the app: **Changes** (f
|
|
|
32
32
|
such as `eval`, `shell=True`, raw HTML, `unsafe`, Go's `InsecureSkipVerify`, Java deserialization or C's
|
|
33
33
|
`strcpy` (only in code, not comments or strings), sensitive
|
|
34
34
|
areas such as auth, payments, migrations and CI, new dependencies, and known vulnerabilities in
|
|
35
|
-
dependency versions new to `package-lock.json`, `Cargo.lock`, `poetry.lock`, `uv.lock
|
|
36
|
-
requirements
|
|
35
|
+
dependency versions new to `package-lock.json`, `Cargo.lock`, `poetry.lock`, `uv.lock`, pinned
|
|
36
|
+
requirements, `go.mod`, `pom.xml`, Gradle build files and version catalogs, or `gradle.lockfile`
|
|
37
|
+
(via [OSV](https://osv.dev); `--offline` skips it). Review signals add large PRs, missing
|
|
37
38
|
test changes and removed or renamed units that untouched code still uses. The report says what was
|
|
38
39
|
found rather than grading the change, and lists the checks that ran and those that did not. These are
|
|
39
40
|
pattern and secret scans of added lines, not a security audit. [Security scanners](#security-scanners) add more when installed.
|
|
@@ -105,7 +106,7 @@ Tokens and code stay on your machine, apart from the host itself, package names
|
|
|
105
106
|
|
|
106
107
|
## In CI
|
|
107
108
|
|
|
108
|
-
The GitHub Action (`navasvarela/walkdiff@v0.
|
|
109
|
+
The GitHub Action (`navasvarela/walkdiff@v0.10.0`) and the GitLab template (`ci/gitlab-ci.yml`) generate the report for each PR, keep it as a job artifact, and post one summary comment that is updated on each push. The [pilot guide](docs/pilot.md) has the setup. Locally, `walkdiff review` also works without a URL inside a CI job, and `walkdiff comment --report <dir> --report-url <url>` posts the summary.
|
|
109
110
|
|
|
110
111
|
## AI review
|
|
111
112
|
|
package/package.json
CHANGED
package/walkdiff.mjs
CHANGED
|
@@ -3323,10 +3323,10 @@ async function listSourceFiles(repoDir, commit) {
|
|
|
3323
3323
|
}
|
|
3324
3324
|
/** Matches any of `names` where it is a whole identifier, not part of a longer one. */
|
|
3325
3325
|
function wordMatcher(names) {
|
|
3326
|
-
const alternatives = [...names].sort((a, b) => b.length - a.length).map(escapeRegExp);
|
|
3326
|
+
const alternatives = [...names].sort((a, b) => b.length - a.length).map(escapeRegExp$1);
|
|
3327
3327
|
return new RegExp(`(?<!${IDENTIFIER_CHAR})(?:${alternatives.join("|")})(?!${IDENTIFIER_CHAR})`, "gu");
|
|
3328
3328
|
}
|
|
3329
|
-
function escapeRegExp(text) {
|
|
3329
|
+
function escapeRegExp$1(text) {
|
|
3330
3330
|
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3331
3331
|
}
|
|
3332
3332
|
// packages/engine/src/impact/identifierUses.ts
|
|
@@ -3688,7 +3688,7 @@ async function mentionsInCode(repoDir, head, names) {
|
|
|
3688
3688
|
return new Map(specific.map(([name, files]) => [name, files.flatMap((path) => mentionsIn(path, linesByPath.get(path) ?? [], name))]));
|
|
3689
3689
|
}
|
|
3690
3690
|
function mentionsIn(path, lines, name) {
|
|
3691
|
-
const word = new RegExp(`(?<![\\p{L}\\p{N}_$])${escapeRegExp(name)}(?![\\p{L}\\p{N}_$])`, "u");
|
|
3691
|
+
const word = new RegExp(`(?<![\\p{L}\\p{N}_$])${escapeRegExp$1(name)}(?![\\p{L}\\p{N}_$])`, "u");
|
|
3692
3692
|
return lines.flatMap((text, index) => word.test(text) && !COMMENT_LINE$1.test(text) ? [{
|
|
3693
3693
|
path,
|
|
3694
3694
|
line: index + 1,
|
|
@@ -3799,7 +3799,7 @@ function keyOf$1(pattern, line) {
|
|
|
3799
3799
|
};
|
|
3800
3800
|
}
|
|
3801
3801
|
function isStillInFile(file, key) {
|
|
3802
|
-
return new RegExp(`(?<![\\w-])${escapeRegExp(key)}(?![\\w-])`).test(file.after ?? "");
|
|
3802
|
+
return new RegExp(`(?<![\\w-])${escapeRegExp$1(key)}(?![\\w-])`).test(file.after ?? "");
|
|
3803
3803
|
}
|
|
3804
3804
|
const NAME_WORD = /[_-]|(?<=[a-z])(?=[A-Z])/;
|
|
3805
3805
|
function endsInTheSameWord(a, b) {
|
|
@@ -3904,7 +3904,7 @@ function isRequiredRead(mention) {
|
|
|
3904
3904
|
return READS_ENVIRONMENT.test(mention.text) && !READ_HAS_DEFAULT.test(mention.text);
|
|
3905
3905
|
}
|
|
3906
3906
|
function looksLikeKeyRead(mention, key) {
|
|
3907
|
-
return new RegExp(`["'\`.]${escapeRegExp(key)}\\b`).test(mention.text);
|
|
3907
|
+
return new RegExp(`["'\`.]${escapeRegExp$1(key)}\\b`).test(mention.text);
|
|
3908
3908
|
}
|
|
3909
3909
|
const MONOREPO_PROJECT = /^(?:apps|packages|services|libs)\/[^/]+\//;
|
|
3910
3910
|
function isInSameProject(mention, path) {
|
|
@@ -4842,7 +4842,7 @@ function findingsForChange(api, file, versions, stillProvided) {
|
|
|
4842
4842
|
function stillProvidedIn(versions, headText, namesAtHead) {
|
|
4843
4843
|
const moduleScope = versions.after?.moduleScope.snapshot.text ?? "";
|
|
4844
4844
|
return (name) => {
|
|
4845
|
-
const escaped = escapeRegExp(name);
|
|
4845
|
+
const escaped = escapeRegExp$1(name);
|
|
4846
4846
|
return namesAtHead.has(name) || new RegExp(`(?<![\\w$])${escaped}(?![\\w$])`).test(moduleScope) || new RegExp(`["'\`]${escaped}["'\`]`).test(headText ?? "");
|
|
4847
4847
|
};
|
|
4848
4848
|
}
|
|
@@ -4894,7 +4894,7 @@ function hasOverloads(api, versions) {
|
|
|
4894
4894
|
* `request` variable matches a function named `request`, so this looks for the call on the line.
|
|
4895
4895
|
*/
|
|
4896
4896
|
function callSites(unit) {
|
|
4897
|
-
const call = new RegExp(`(?<![\\w$])${escapeRegExp(unit.name)}\\s*(?:\\(|::<|<[^()]*>\\()`);
|
|
4897
|
+
const call = new RegExp(`(?<![\\w$])${escapeRegExp$1(unit.name)}\\s*(?:\\(|::<|<[^()]*>\\()`);
|
|
4898
4898
|
return certainCallers(unit).filter((reference) => call.test(reference.snippet));
|
|
4899
4899
|
}
|
|
4900
4900
|
/** Who is affected, or as much as is known about it, as a sentence. */
|
|
@@ -5105,7 +5105,7 @@ async function findVulnerabilities(packages) {
|
|
|
5105
5105
|
}
|
|
5106
5106
|
const ids = [...new Set(affected.map((entry) => entry.id))];
|
|
5107
5107
|
const details = /* @__PURE__ */ new Map();
|
|
5108
|
-
for (const id of ids.slice(0, MAX_DETAILED_VULNERABILITIES)) details.set(id, vulnerabilitySchema.parse(await getJson$
|
|
5108
|
+
for (const id of ids.slice(0, MAX_DETAILED_VULNERABILITIES)) details.set(id, vulnerabilitySchema.parse(await getJson$2(`${OSV_API}/vulns/${encodeURIComponent(id)}`)));
|
|
5109
5109
|
return affected.map(({ package: entry, id }) => {
|
|
5110
5110
|
return {
|
|
5111
5111
|
package: entry,
|
|
@@ -5164,7 +5164,7 @@ async function postJson(url, body) {
|
|
|
5164
5164
|
body: JSON.stringify(body)
|
|
5165
5165
|
});
|
|
5166
5166
|
}
|
|
5167
|
-
async function getJson$
|
|
5167
|
+
async function getJson$2(url) {
|
|
5168
5168
|
return request(url, { method: "GET" });
|
|
5169
5169
|
}
|
|
5170
5170
|
async function request(url, init) {
|
|
@@ -5395,14 +5395,290 @@ const runScannerProcess = (binary, args, cwd) => new Promise((resolve) => {
|
|
|
5395
5395
|
function firstErrorLine(result) {
|
|
5396
5396
|
return result.stderr.split("\n").find((line) => line.trim() !== "")?.trim().slice(0, 200) ?? `exit code ${result.exitCode}`;
|
|
5397
5397
|
}
|
|
5398
|
-
// packages/engine/src/risk/dependencies/
|
|
5398
|
+
// packages/engine/src/risk/dependencies/ecosystem.ts
|
|
5399
5399
|
/** OSV's names for the package ecosystems the engine reads. */
|
|
5400
5400
|
const Ecosystem = {
|
|
5401
5401
|
Npm: "npm",
|
|
5402
5402
|
Crates: "crates.io",
|
|
5403
|
-
PyPI: "PyPI"
|
|
5403
|
+
PyPI: "PyPI",
|
|
5404
|
+
Go: "Go",
|
|
5405
|
+
Maven: "Maven"
|
|
5404
5406
|
};
|
|
5407
|
+
// packages/engine/src/risk/dependencies/goModules.ts
|
|
5408
|
+
const INDIRECT_COMMENT = /\/\/\s*indirect\b/;
|
|
5409
|
+
const LINE_COMMENT = /\/\/.*$/;
|
|
5410
|
+
const DIRECTORY_PATH = /^(?:\.{1,2}[\\/]|[\\/]|[A-Za-z]:[\\/])/;
|
|
5411
|
+
const BLOCK_END = ")";
|
|
5412
|
+
/** Direct requirements, the ones the module's own code imports; a module replaced by a directory isn't fetched. */
|
|
5413
|
+
function parseGoMod(text) {
|
|
5414
|
+
const { requirements, replacements } = readGoMod(text);
|
|
5415
|
+
const declared = /* @__PURE__ */ new Map();
|
|
5416
|
+
for (const requirement of requirements) {
|
|
5417
|
+
if (requirement.indirect) continue;
|
|
5418
|
+
const replacement = replacementFor(replacements, requirement);
|
|
5419
|
+
declared.set(requirement.module, replacement?.kind === "directory" ? `path:${replacement.path}` : requirement.version);
|
|
5420
|
+
}
|
|
5421
|
+
return declared;
|
|
5422
|
+
}
|
|
5423
|
+
/** Every module version the build uses, replacements applied. */
|
|
5424
|
+
function goModLockfile(text) {
|
|
5425
|
+
const { requirements, replacements } = readGoMod(text);
|
|
5426
|
+
return requirements.flatMap((requirement) => {
|
|
5427
|
+
const replacement = replacementFor(replacements, requirement);
|
|
5428
|
+
if (replacement?.kind === "directory") return [];
|
|
5429
|
+
const used = replacement ?? requirement;
|
|
5430
|
+
return [{
|
|
5431
|
+
ecosystem: Ecosystem.Go,
|
|
5432
|
+
name: used.module,
|
|
5433
|
+
version: used.version
|
|
5434
|
+
}];
|
|
5435
|
+
});
|
|
5436
|
+
}
|
|
5437
|
+
function replacementFor(replacements, requirement) {
|
|
5438
|
+
return replacements.get(`${requirement.module}@${requirement.version}`) ?? replacements.get(requirement.module);
|
|
5439
|
+
}
|
|
5440
|
+
function readGoMod(text) {
|
|
5441
|
+
const requirements = [];
|
|
5442
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
5443
|
+
let block;
|
|
5444
|
+
for (const rawLine of text.split("\n")) {
|
|
5445
|
+
const indirect = INDIRECT_COMMENT.test(rawLine);
|
|
5446
|
+
const line = rawLine.replace(LINE_COMMENT, "").trim();
|
|
5447
|
+
if (line === "") continue;
|
|
5448
|
+
if (block !== void 0 && line === BLOCK_END) {
|
|
5449
|
+
block = void 0;
|
|
5450
|
+
continue;
|
|
5451
|
+
}
|
|
5452
|
+
const words = line.split(/\s+/);
|
|
5453
|
+
const [directive, rest] = block === void 0 ? [words.at(0), words.slice(1)] : [block, words];
|
|
5454
|
+
if (block === void 0 && rest.length === 1 && rest.at(0) === "(") {
|
|
5455
|
+
block = directive;
|
|
5456
|
+
continue;
|
|
5457
|
+
}
|
|
5458
|
+
if (directive === "require") addRequirement(requirements, rest, indirect);
|
|
5459
|
+
if (directive === "replace") addReplacement(replacements, rest);
|
|
5460
|
+
}
|
|
5461
|
+
return {
|
|
5462
|
+
requirements,
|
|
5463
|
+
replacements
|
|
5464
|
+
};
|
|
5465
|
+
}
|
|
5466
|
+
function addRequirement(requirements, words, indirect) {
|
|
5467
|
+
const [module, version] = words;
|
|
5468
|
+
if (module !== void 0 && version !== void 0) requirements.push({
|
|
5469
|
+
module: unquote(module),
|
|
5470
|
+
version,
|
|
5471
|
+
indirect
|
|
5472
|
+
});
|
|
5473
|
+
}
|
|
5474
|
+
function addReplacement(replacements, words) {
|
|
5475
|
+
const arrow = words.indexOf("=>");
|
|
5476
|
+
const [module, version] = words.slice(0, arrow);
|
|
5477
|
+
const [target, targetVersion] = words.slice(arrow + 1);
|
|
5478
|
+
if (arrow === -1 || module === void 0 || target === void 0) return;
|
|
5479
|
+
const key = version === void 0 ? unquote(module) : `${unquote(module)}@${version}`;
|
|
5480
|
+
const path = unquote(target);
|
|
5481
|
+
if (DIRECTORY_PATH.test(path)) replacements.set(key, {
|
|
5482
|
+
kind: "directory",
|
|
5483
|
+
path
|
|
5484
|
+
});
|
|
5485
|
+
else if (targetVersion !== void 0) replacements.set(key, {
|
|
5486
|
+
kind: "module",
|
|
5487
|
+
module: path,
|
|
5488
|
+
version: targetVersion
|
|
5489
|
+
});
|
|
5490
|
+
}
|
|
5491
|
+
function unquote(word) {
|
|
5492
|
+
return word.replace(/^["`]|["`]$/g, "");
|
|
5493
|
+
}
|
|
5494
|
+
// packages/engine/src/risk/dependencies/fields.ts
|
|
5495
|
+
function isRecord(value) {
|
|
5496
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5497
|
+
}
|
|
5498
|
+
function field(value, key) {
|
|
5499
|
+
return isRecord(value) ? value[key] : void 0;
|
|
5500
|
+
}
|
|
5501
|
+
function stringField(value, key) {
|
|
5502
|
+
const found = field(value, key);
|
|
5503
|
+
return typeof found === "string" ? found : void 0;
|
|
5504
|
+
}
|
|
5505
|
+
function recordOrEmpty(value) {
|
|
5506
|
+
return isRecord(value) ? value : {};
|
|
5507
|
+
}
|
|
5508
|
+
// packages/engine/src/risk/dependencies/maven.ts
|
|
5509
|
+
const COMMENT_OPEN = "<!--";
|
|
5510
|
+
const COMMENT_CLOSE = "-->";
|
|
5511
|
+
const NOT_PROJECT_DEPENDENCIES = [
|
|
5512
|
+
/<dependencyManagement>[\s\S]*?<\/dependencyManagement>/g,
|
|
5513
|
+
/<build>[\s\S]*?<\/build>/g,
|
|
5514
|
+
/<reporting>[\s\S]*?<\/reporting>/g,
|
|
5515
|
+
/<exclusions>[\s\S]*?<\/exclusions>/g
|
|
5516
|
+
];
|
|
5517
|
+
const DEPENDENCY = /<dependency>([\s\S]*?)<\/dependency>/g;
|
|
5518
|
+
const PROPERTIES = /<properties>([\s\S]*?)<\/properties>/g;
|
|
5519
|
+
const PROPERTY = /<([\w.-]+)>\s*([^<]*?)\s*<\/\1>/g;
|
|
5520
|
+
const PROPERTY_REFERENCE = /\$\{([^}]+)\}/g;
|
|
5521
|
+
const UNRESOLVED = "${";
|
|
5522
|
+
const NOT_EXACT_VERSION = /^[[(]|[,\s]|^(?:LATEST|RELEASE)$|^latest\.|\$|\+$/;
|
|
5523
|
+
const ANY_VERSION = "*";
|
|
5524
|
+
const INTERNAL_REQUIREMENT = "workspace:";
|
|
5525
|
+
const PROJECT_SECTIONS = [
|
|
5526
|
+
/<parent>[\s\S]*?<\/parent>/g,
|
|
5527
|
+
/<dependencies>[\s\S]*?<\/dependencies>/g,
|
|
5528
|
+
/<profiles>[\s\S]*?<\/profiles>/g
|
|
5529
|
+
];
|
|
5530
|
+
function parsePom(text) {
|
|
5531
|
+
const { coordinates, ownGroup } = readPom(text);
|
|
5532
|
+
return new Map(coordinates.map((coordinate) => [coordinate.name, isInternal(coordinate, ownGroup) ? INTERNAL_REQUIREMENT : coordinate.version ?? ANY_VERSION]));
|
|
5533
|
+
}
|
|
5534
|
+
function pomLockfile(text) {
|
|
5535
|
+
const { coordinates, ownGroup } = readPom(text);
|
|
5536
|
+
return toLocked(coordinates.filter((coordinate) => !isInternal(coordinate, ownGroup)));
|
|
5537
|
+
}
|
|
5538
|
+
function isInternal(coordinate, ownGroup) {
|
|
5539
|
+
return ownGroup !== void 0 && coordinate.version === void 0 && coordinate.name.startsWith(`${ownGroup}:`);
|
|
5540
|
+
}
|
|
5541
|
+
function toDeclared(coordinates) {
|
|
5542
|
+
return new Map(coordinates.map((coordinate) => [coordinate.name, coordinate.version ?? ANY_VERSION]));
|
|
5543
|
+
}
|
|
5544
|
+
/** The coordinates that name one exact version, which is what OSV can check. */
|
|
5545
|
+
function toLocked(coordinates) {
|
|
5546
|
+
return coordinates.flatMap(({ name, version }) => version === void 0 || NOT_EXACT_VERSION.test(version) ? [] : [{
|
|
5547
|
+
ecosystem: Ecosystem.Maven,
|
|
5548
|
+
name,
|
|
5549
|
+
version
|
|
5550
|
+
}]);
|
|
5551
|
+
}
|
|
5552
|
+
function readPom(text) {
|
|
5553
|
+
const withoutComments = withoutXmlComments(text);
|
|
5554
|
+
const properties = readProperties(withoutComments);
|
|
5555
|
+
const projectOnly = withoutSections(withoutComments, NOT_PROJECT_DEPENDENCIES);
|
|
5556
|
+
return {
|
|
5557
|
+
coordinates: [...projectOnly.matchAll(DEPENDENCY)].flatMap((match) => {
|
|
5558
|
+
const body = match[1] ?? "";
|
|
5559
|
+
const written = elementText(body, "groupId");
|
|
5560
|
+
const group = written === void 0 ? void 0 : resolveProperties(written, properties);
|
|
5561
|
+
const artifact = elementText(body, "artifactId");
|
|
5562
|
+
if (group === void 0 || artifact === void 0) return [];
|
|
5563
|
+
const version = elementText(body, "version");
|
|
5564
|
+
return [{
|
|
5565
|
+
name: `${group}:${artifact}`,
|
|
5566
|
+
version: version === void 0 ? void 0 : resolveProperties(version, properties)
|
|
5567
|
+
}];
|
|
5568
|
+
}),
|
|
5569
|
+
ownGroup: elementText(withoutSections(projectOnly, PROJECT_SECTIONS), "groupId") ?? elementText(/<parent>([\s\S]*?)<\/parent>/.exec(withoutComments)?.[1] ?? "", "groupId")
|
|
5570
|
+
};
|
|
5571
|
+
}
|
|
5572
|
+
function withoutXmlComments(xml) {
|
|
5573
|
+
let text = xml;
|
|
5574
|
+
while (text.includes(COMMENT_OPEN)) text = withoutCommentsOnce(text);
|
|
5575
|
+
return text;
|
|
5576
|
+
}
|
|
5577
|
+
function withoutCommentsOnce(xml) {
|
|
5578
|
+
let kept = "";
|
|
5579
|
+
let position = 0;
|
|
5580
|
+
for (let open = xml.indexOf(COMMENT_OPEN); open !== -1; open = xml.indexOf(COMMENT_OPEN, position)) {
|
|
5581
|
+
kept += xml.slice(position, open);
|
|
5582
|
+
const close = xml.indexOf(COMMENT_CLOSE, open + 4);
|
|
5583
|
+
if (close === -1) return kept;
|
|
5584
|
+
position = close + 3;
|
|
5585
|
+
}
|
|
5586
|
+
return kept + xml.slice(position);
|
|
5587
|
+
}
|
|
5588
|
+
function withoutSections(xml, sections) {
|
|
5589
|
+
return sections.reduce((current, section) => current.replace(section, ""), xml);
|
|
5590
|
+
}
|
|
5591
|
+
function readProperties(pom) {
|
|
5592
|
+
const properties = /* @__PURE__ */ new Map();
|
|
5593
|
+
for (const section of pom.matchAll(PROPERTIES)) for (const [, key, value] of (section[1] ?? "").matchAll(PROPERTY)) if (key !== void 0 && value !== void 0) properties.set(key, value);
|
|
5594
|
+
return properties;
|
|
5595
|
+
}
|
|
5596
|
+
function resolveProperties(value, properties) {
|
|
5597
|
+
const resolved = value.replace(PROPERTY_REFERENCE, (reference, key) => properties.get(key) ?? reference);
|
|
5598
|
+
return resolved.includes(UNRESOLVED) ? void 0 : resolved;
|
|
5599
|
+
}
|
|
5600
|
+
function elementText(xml, element) {
|
|
5601
|
+
return new RegExp(`<${element}>\\s*([^<]*?)\\s*</${element}>`).exec(xml)?.[1];
|
|
5602
|
+
}
|
|
5603
|
+
// packages/engine/src/risk/dependencies/gradle.ts
|
|
5604
|
+
const CONFIGURATION = String.raw`\b(?:\w*(?:[Ii]mplementation|[Aa]pi|[Cc]ompileOnly|[Rr]untimeOnly|[Aa]nnotationProcessor|[Cc]ompile|[Rr]untime)|kapt\w*|ksp\w*|classpath|coreLibraryDesugaring|detektPlugins|lintChecks)`;
|
|
5605
|
+
const PLATFORM = String.raw`(?:(?:platform|enforcedPlatform)\s*\(\s*)?`;
|
|
5606
|
+
const COORDINATE = String.raw`["']([\w.-]+):([\w.-]+)(?::([^"':@\s]+))?(?::[\w.-]+)?(?:@\w+)?["']`;
|
|
5607
|
+
const COORDINATE_STRING = new RegExp(String.raw`${CONFIGURATION}\s*(?:\(\s*)?${PLATFORM}${COORDINATE}`, "g");
|
|
5608
|
+
const MAP_NOTATION = /\bgroup\s*[:=]\s*["']([\w.-]+)["']\s*,\s*name\s*[:=]\s*["']([\w.-]+)["'](?:\s*,\s*version\s*[:=]\s*["']([^"']+)["'])?/g;
|
|
5609
|
+
const LOCKED_LINE = /^([\w.-]+):([\w.-]+):([^=\s]+)=/;
|
|
5610
|
+
const RICH_VERSION_KEYS = [
|
|
5611
|
+
"strictly",
|
|
5612
|
+
"require",
|
|
5613
|
+
"prefer"
|
|
5614
|
+
];
|
|
5615
|
+
function parseGradleBuild(text) {
|
|
5616
|
+
return toDeclared(buildCoordinates(text));
|
|
5617
|
+
}
|
|
5618
|
+
function gradleBuildLockfile(text) {
|
|
5619
|
+
return toLocked(buildCoordinates(text));
|
|
5620
|
+
}
|
|
5621
|
+
function parseGradleCatalog(text) {
|
|
5622
|
+
return toDeclared(catalogCoordinates(text));
|
|
5623
|
+
}
|
|
5624
|
+
function gradleCatalogLockfile(text) {
|
|
5625
|
+
return toLocked(catalogCoordinates(text));
|
|
5626
|
+
}
|
|
5627
|
+
function gradleLockfile(text) {
|
|
5628
|
+
return text.split("\n").flatMap((line) => {
|
|
5629
|
+
const [, group, artifact, version] = LOCKED_LINE.exec(line.trim()) ?? [];
|
|
5630
|
+
return group === void 0 || artifact === void 0 || version === void 0 ? [] : [{
|
|
5631
|
+
ecosystem: Ecosystem.Maven,
|
|
5632
|
+
name: `${group}:${artifact}`,
|
|
5633
|
+
version
|
|
5634
|
+
}];
|
|
5635
|
+
});
|
|
5636
|
+
}
|
|
5637
|
+
function buildCoordinates(text) {
|
|
5638
|
+
const fromStrings = [...text.matchAll(COORDINATE_STRING)].map(([, group, artifact, version]) => ({
|
|
5639
|
+
name: `${group}:${artifact}`,
|
|
5640
|
+
version
|
|
5641
|
+
}));
|
|
5642
|
+
const fromMaps = [...text.matchAll(MAP_NOTATION)].map(([, group, artifact, version]) => ({
|
|
5643
|
+
name: `${group}:${artifact}`,
|
|
5644
|
+
version
|
|
5645
|
+
}));
|
|
5646
|
+
return [...fromStrings, ...fromMaps];
|
|
5647
|
+
}
|
|
5648
|
+
function catalogCoordinates(text) {
|
|
5649
|
+
const catalog = parse(text);
|
|
5650
|
+
const versions = recordOrEmpty(field(catalog, "versions"));
|
|
5651
|
+
return Object.values(recordOrEmpty(field(catalog, "libraries"))).flatMap((library) => {
|
|
5652
|
+
if (typeof library === "string") {
|
|
5653
|
+
const [group, artifact, version] = library.split(":");
|
|
5654
|
+
return group === void 0 || artifact === void 0 ? [] : [{
|
|
5655
|
+
name: `${group}:${artifact}`,
|
|
5656
|
+
version
|
|
5657
|
+
}];
|
|
5658
|
+
}
|
|
5659
|
+
const group = stringField(library, "group");
|
|
5660
|
+
const artifact = stringField(library, "name");
|
|
5661
|
+
const name = stringField(library, "module") ?? (group === void 0 || artifact === void 0 ? void 0 : `${group}:${artifact}`);
|
|
5662
|
+
return name === void 0 ? [] : [{
|
|
5663
|
+
name,
|
|
5664
|
+
version: catalogVersion(field(library, "version"), versions)
|
|
5665
|
+
}];
|
|
5666
|
+
});
|
|
5667
|
+
}
|
|
5668
|
+
function catalogVersion(version, versions) {
|
|
5669
|
+
if (typeof version === "string") return version;
|
|
5670
|
+
const reference = stringField(version, "ref");
|
|
5671
|
+
if (reference !== void 0) return catalogVersion(versions[reference], {});
|
|
5672
|
+
if (!isRecord(version)) return void 0;
|
|
5673
|
+
return RICH_VERSION_KEYS.map((key) => stringField(version, key)).find((value) => value !== void 0);
|
|
5674
|
+
}
|
|
5675
|
+
// packages/engine/src/risk/dependencies/packages.ts
|
|
5405
5676
|
const REQUIREMENTS_FILE = /^requirements.*\.txt$/;
|
|
5677
|
+
const GO_MOD = "go.mod";
|
|
5678
|
+
const POM = "pom.xml";
|
|
5679
|
+
const GRADLE_BUILD = /* @__PURE__ */ new Set(["build.gradle", "build.gradle.kts"]);
|
|
5680
|
+
const GRADLE_CATALOG = /\.versions\.toml$/;
|
|
5681
|
+
const GRADLE_LOCKFILE = "gradle.lockfile";
|
|
5406
5682
|
const PEP508_REQUIREMENT = /^\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*(?:\[[^\]]*\])?\s*([^;#]*)/;
|
|
5407
5683
|
const PINNED_VERSION = /^==\s*([^\s,;]+)$/;
|
|
5408
5684
|
const MANIFESTS = [
|
|
@@ -5425,6 +5701,26 @@ const MANIFESTS = [
|
|
|
5425
5701
|
ecosystem: Ecosystem.PyPI,
|
|
5426
5702
|
matches: (name) => REQUIREMENTS_FILE.test(name),
|
|
5427
5703
|
parse: parseRequirements
|
|
5704
|
+
},
|
|
5705
|
+
{
|
|
5706
|
+
ecosystem: Ecosystem.Go,
|
|
5707
|
+
matches: (name) => name === GO_MOD,
|
|
5708
|
+
parse: parseGoMod
|
|
5709
|
+
},
|
|
5710
|
+
{
|
|
5711
|
+
ecosystem: Ecosystem.Maven,
|
|
5712
|
+
matches: (name) => name === POM,
|
|
5713
|
+
parse: parsePom
|
|
5714
|
+
},
|
|
5715
|
+
{
|
|
5716
|
+
ecosystem: Ecosystem.Maven,
|
|
5717
|
+
matches: (name) => GRADLE_BUILD.has(name),
|
|
5718
|
+
parse: parseGradleBuild
|
|
5719
|
+
},
|
|
5720
|
+
{
|
|
5721
|
+
ecosystem: Ecosystem.Maven,
|
|
5722
|
+
matches: (name) => GRADLE_CATALOG.test(name),
|
|
5723
|
+
parse: parseGradleCatalog
|
|
5428
5724
|
}
|
|
5429
5725
|
];
|
|
5430
5726
|
const LOCKFILES = [
|
|
@@ -5447,6 +5743,31 @@ const LOCKFILES = [
|
|
|
5447
5743
|
ecosystem: Ecosystem.PyPI,
|
|
5448
5744
|
matches: (name) => REQUIREMENTS_FILE.test(name),
|
|
5449
5745
|
parse: pinnedRequirements
|
|
5746
|
+
},
|
|
5747
|
+
{
|
|
5748
|
+
ecosystem: Ecosystem.Go,
|
|
5749
|
+
matches: (name) => name === GO_MOD,
|
|
5750
|
+
parse: goModLockfile
|
|
5751
|
+
},
|
|
5752
|
+
{
|
|
5753
|
+
ecosystem: Ecosystem.Maven,
|
|
5754
|
+
matches: (name) => name === POM,
|
|
5755
|
+
parse: pomLockfile
|
|
5756
|
+
},
|
|
5757
|
+
{
|
|
5758
|
+
ecosystem: Ecosystem.Maven,
|
|
5759
|
+
matches: (name) => GRADLE_BUILD.has(name),
|
|
5760
|
+
parse: gradleBuildLockfile
|
|
5761
|
+
},
|
|
5762
|
+
{
|
|
5763
|
+
ecosystem: Ecosystem.Maven,
|
|
5764
|
+
matches: (name) => GRADLE_CATALOG.test(name),
|
|
5765
|
+
parse: gradleCatalogLockfile
|
|
5766
|
+
},
|
|
5767
|
+
{
|
|
5768
|
+
ecosystem: Ecosystem.Maven,
|
|
5769
|
+
matches: (name) => name === GRADLE_LOCKFILE,
|
|
5770
|
+
parse: gradleLockfile
|
|
5450
5771
|
}
|
|
5451
5772
|
];
|
|
5452
5773
|
const UNREAD_LOCKFILES = /* @__PURE__ */ new Set([
|
|
@@ -5567,19 +5888,6 @@ function pinnedRequirements(text) {
|
|
|
5567
5888
|
function normalizePythonName(name) {
|
|
5568
5889
|
return name.toLowerCase().replace(/[-_.]+/g, "-");
|
|
5569
5890
|
}
|
|
5570
|
-
function isRecord(value) {
|
|
5571
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5572
|
-
}
|
|
5573
|
-
function field(value, key) {
|
|
5574
|
-
return isRecord(value) ? value[key] : void 0;
|
|
5575
|
-
}
|
|
5576
|
-
function stringField(value, key) {
|
|
5577
|
-
const found = field(value, key);
|
|
5578
|
-
return typeof found === "string" ? found : void 0;
|
|
5579
|
-
}
|
|
5580
|
-
function recordOrEmpty(value) {
|
|
5581
|
-
return isRecord(value) ? value : {};
|
|
5582
|
-
}
|
|
5583
5891
|
function stringEntries(value) {
|
|
5584
5892
|
return Object.entries(recordOrEmpty(value)).flatMap(([key, entry]) => typeof entry === "string" ? [[key, entry]] : []);
|
|
5585
5893
|
}
|
|
@@ -5937,6 +6245,62 @@ const POPULAR_PACKAGES = {
|
|
|
5937
6245
|
"base64",
|
|
5938
6246
|
"sha2",
|
|
5939
6247
|
"rustls"
|
|
6248
|
+
]),
|
|
6249
|
+
[Ecosystem.Go]: /* @__PURE__ */ new Set([
|
|
6250
|
+
"github.com/gin-gonic/gin",
|
|
6251
|
+
"github.com/stretchr/testify",
|
|
6252
|
+
"github.com/spf13/cobra",
|
|
6253
|
+
"github.com/spf13/viper",
|
|
6254
|
+
"github.com/sirupsen/logrus",
|
|
6255
|
+
"go.uber.org/zap",
|
|
6256
|
+
"github.com/gorilla/mux",
|
|
6257
|
+
"github.com/gorilla/websocket",
|
|
6258
|
+
"google.golang.org/grpc",
|
|
6259
|
+
"google.golang.org/protobuf",
|
|
6260
|
+
"github.com/golang-jwt/jwt/v5",
|
|
6261
|
+
"gorm.io/gorm",
|
|
6262
|
+
"github.com/redis/go-redis/v9",
|
|
6263
|
+
"github.com/jackc/pgx/v5",
|
|
6264
|
+
"github.com/go-sql-driver/mysql",
|
|
6265
|
+
"github.com/lib/pq",
|
|
6266
|
+
"github.com/google/uuid",
|
|
6267
|
+
"github.com/labstack/echo/v4",
|
|
6268
|
+
"github.com/gofiber/fiber/v2",
|
|
6269
|
+
"github.com/go-chi/chi/v5",
|
|
6270
|
+
"github.com/prometheus/client_golang",
|
|
6271
|
+
"golang.org/x/crypto",
|
|
6272
|
+
"golang.org/x/net",
|
|
6273
|
+
"golang.org/x/sync",
|
|
6274
|
+
"gopkg.in/yaml.v3",
|
|
6275
|
+
"github.com/aws/aws-sdk-go-v2",
|
|
6276
|
+
"github.com/boltdb/bolt",
|
|
6277
|
+
"go.etcd.io/bbolt"
|
|
6278
|
+
]),
|
|
6279
|
+
[Ecosystem.Maven]: /* @__PURE__ */ new Set([
|
|
6280
|
+
"com.fasterxml.jackson.core:jackson-databind",
|
|
6281
|
+
"com.fasterxml.jackson.core:jackson-core",
|
|
6282
|
+
"org.springframework:spring-core",
|
|
6283
|
+
"org.springframework:spring-web",
|
|
6284
|
+
"org.springframework.boot:spring-boot-starter-web",
|
|
6285
|
+
"com.google.guava:guava",
|
|
6286
|
+
"org.apache.commons:commons-lang3",
|
|
6287
|
+
"commons-io:commons-io",
|
|
6288
|
+
"junit:junit",
|
|
6289
|
+
"org.junit.jupiter:junit-jupiter",
|
|
6290
|
+
"org.mockito:mockito-core",
|
|
6291
|
+
"org.slf4j:slf4j-api",
|
|
6292
|
+
"ch.qos.logback:logback-classic",
|
|
6293
|
+
"org.apache.logging.log4j:log4j-core",
|
|
6294
|
+
"com.google.code.gson:gson",
|
|
6295
|
+
"org.projectlombok:lombok",
|
|
6296
|
+
"org.apache.httpcomponents:httpclient",
|
|
6297
|
+
"com.squareup.okhttp3:okhttp",
|
|
6298
|
+
"org.postgresql:postgresql",
|
|
6299
|
+
"mysql:mysql-connector-java",
|
|
6300
|
+
"org.hibernate:hibernate-core",
|
|
6301
|
+
"io.netty:netty-all",
|
|
6302
|
+
"org.jetbrains.kotlin:kotlin-stdlib",
|
|
6303
|
+
"org.yaml:snakeyaml"
|
|
5940
6304
|
])
|
|
5941
6305
|
};
|
|
5942
6306
|
// packages/engine/src/risk/dependencies/packageTrust.ts
|
|
@@ -5954,7 +6318,9 @@ const USER_AGENT$1 = "walkdiff (https://github.com/navasvarela/walkdiff)";
|
|
|
5954
6318
|
const REGISTRY_NAMES = {
|
|
5955
6319
|
[Ecosystem.Npm]: "npm",
|
|
5956
6320
|
[Ecosystem.PyPI]: "PyPI",
|
|
5957
|
-
[Ecosystem.Crates]: "crates.io"
|
|
6321
|
+
[Ecosystem.Crates]: "crates.io",
|
|
6322
|
+
[Ecosystem.Go]: "the Go module proxy",
|
|
6323
|
+
[Ecosystem.Maven]: "Maven Central"
|
|
5958
6324
|
};
|
|
5959
6325
|
/**
|
|
5960
6326
|
* Requirements that don't come from a public registry, so a registry can't say anything about them:
|
|
@@ -6098,6 +6464,15 @@ const cratesSchema = z.object({
|
|
|
6098
6464
|
crate: z.object({ created_at: z.string() }).loose(),
|
|
6099
6465
|
versions: z.array(z.object({ license: z.string().nullish() }).loose()).default([])
|
|
6100
6466
|
}).loose();
|
|
6467
|
+
function singleRequest(service, url, read) {
|
|
6468
|
+
return {
|
|
6469
|
+
service,
|
|
6470
|
+
facts: async (name, getJson) => {
|
|
6471
|
+
const body = await getJson(url(name));
|
|
6472
|
+
return body === void 0 ? void 0 : read(body);
|
|
6473
|
+
}
|
|
6474
|
+
};
|
|
6475
|
+
}
|
|
6101
6476
|
function npmLicenseText(license) {
|
|
6102
6477
|
return typeof license === "string" ? license : license?.type;
|
|
6103
6478
|
}
|
|
@@ -6105,45 +6480,83 @@ function npmPathFor(name) {
|
|
|
6105
6480
|
return name.startsWith("@") ? `@${encodeURIComponent(name.slice(1))}` : encodeURIComponent(name);
|
|
6106
6481
|
}
|
|
6107
6482
|
const REGISTRIES = {
|
|
6108
|
-
[Ecosystem.Npm]: {
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
}
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6483
|
+
[Ecosystem.Npm]: singleRequest("npm", (name) => `https://registry.npmjs.org/${npmPathFor(name)}`, (body) => {
|
|
6484
|
+
const parsed = npmSchema.parse(body);
|
|
6485
|
+
const latest = parsed["dist-tags"]?.latest;
|
|
6486
|
+
const latestLicense = latest === void 0 ? void 0 : parsed.versions?.[latest]?.license;
|
|
6487
|
+
return {
|
|
6488
|
+
firstPublished: new Date(parsed.time.created),
|
|
6489
|
+
license: npmLicenseText(latestLicense) ?? npmLicenseText(parsed.license)
|
|
6490
|
+
};
|
|
6491
|
+
}),
|
|
6492
|
+
[Ecosystem.PyPI]: singleRequest("PyPI", (name) => `https://pypi.org/pypi/${encodeURIComponent(name)}/json`, (body) => {
|
|
6493
|
+
const { info, releases } = pypiSchema.parse(body);
|
|
6494
|
+
const times = Object.values(releases).flat().map((file) => new Date(file.upload_time_iso_8601).getTime());
|
|
6495
|
+
return {
|
|
6496
|
+
firstPublished: times.length === 0 ? void 0 : new Date(Math.min(...times)),
|
|
6497
|
+
license: pypiLicense(info.license_expression, info.license, info.classifiers)
|
|
6498
|
+
};
|
|
6499
|
+
}),
|
|
6500
|
+
[Ecosystem.Crates]: singleRequest("crates.io", (name) => `https://crates.io/api/v1/crates/${encodeURIComponent(name)}`, (body) => {
|
|
6501
|
+
const parsed = cratesSchema.parse(body);
|
|
6502
|
+
return {
|
|
6503
|
+
firstPublished: new Date(parsed.crate.created_at),
|
|
6504
|
+
license: parsed.versions.at(0)?.license ?? void 0
|
|
6505
|
+
};
|
|
6506
|
+
}),
|
|
6507
|
+
[Ecosystem.Go]: depsDevClient("go"),
|
|
6508
|
+
[Ecosystem.Maven]: depsDevClient("maven")
|
|
6509
|
+
};
|
|
6510
|
+
const DEPS_DEV_SYSTEMS = "https://api.deps.dev/v3/systems";
|
|
6511
|
+
const depsDevPackageSchema = z.object({ versions: z.array(z.object({
|
|
6512
|
+
versionKey: z.object({ version: z.string() }).loose(),
|
|
6513
|
+
publishedAt: z.string().optional(),
|
|
6514
|
+
isDefault: z.boolean().optional()
|
|
6515
|
+
}).loose()).default([]) }).loose();
|
|
6516
|
+
const depsDevVersionSchema = z.object({ licenses: z.array(z.string()).default([]) }).loose();
|
|
6517
|
+
function depsDevClient(system) {
|
|
6518
|
+
return {
|
|
6519
|
+
service: "deps.dev",
|
|
6520
|
+
facts: async (name, getJson) => {
|
|
6521
|
+
const packageUrl = `${DEPS_DEV_SYSTEMS}/${system}/packages/${encodeURIComponent(name)}`;
|
|
6522
|
+
const body = await getJson(packageUrl);
|
|
6523
|
+
if (body === void 0) return void 0;
|
|
6524
|
+
const { versions } = depsDevPackageSchema.parse(body);
|
|
6525
|
+
const times = versions.flatMap((version) => version.publishedAt === void 0 ? [] : [new Date(version.publishedAt).getTime()]);
|
|
6526
|
+
const current = versions.find((version) => version.isDefault === true) ?? versions.at(-1);
|
|
6527
|
+
const license = current === void 0 ? void 0 : depsDevLicense(await getJson(`${packageUrl}/versions/${encodeURIComponent(current.versionKey.version)}`));
|
|
6125
6528
|
return {
|
|
6126
6529
|
firstPublished: times.length === 0 ? void 0 : new Date(Math.min(...times)),
|
|
6127
|
-
license
|
|
6530
|
+
license
|
|
6128
6531
|
};
|
|
6129
6532
|
}
|
|
6130
|
-
}
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
};
|
|
6139
|
-
}
|
|
6140
|
-
}
|
|
6141
|
-
};
|
|
6533
|
+
};
|
|
6534
|
+
}
|
|
6535
|
+
function depsDevLicense(body) {
|
|
6536
|
+
if (body === void 0) return void 0;
|
|
6537
|
+
const { licenses } = depsDevVersionSchema.parse(body);
|
|
6538
|
+
if (licenses.length <= 1) return licenses.at(0);
|
|
6539
|
+
return licenses.map((license) => `(${license})`).join(" AND ");
|
|
6540
|
+
}
|
|
6142
6541
|
async function lookUpOnRegistry(ecosystem, name) {
|
|
6143
6542
|
const client = REGISTRIES[ecosystem];
|
|
6543
|
+
let facts;
|
|
6544
|
+
try {
|
|
6545
|
+
facts = await client.facts(name, (url) => getJson$1(url, client.service));
|
|
6546
|
+
} catch (error) {
|
|
6547
|
+
if (error instanceof RegistryUnavailableError) throw error;
|
|
6548
|
+
throw new RegistryUnavailableError(`${client.service} sent an unexpected answer: ${error instanceof Error ? error.message : String(error)}`);
|
|
6549
|
+
}
|
|
6550
|
+
return facts?.firstPublished === void 0 ? { status: RegistryStatus.Missing } : {
|
|
6551
|
+
status: RegistryStatus.Published,
|
|
6552
|
+
firstPublished: facts.firstPublished,
|
|
6553
|
+
license: facts.license
|
|
6554
|
+
};
|
|
6555
|
+
}
|
|
6556
|
+
async function getJson$1(url, service) {
|
|
6144
6557
|
let response;
|
|
6145
6558
|
try {
|
|
6146
|
-
response = await fetch(
|
|
6559
|
+
response = await fetch(url, {
|
|
6147
6560
|
headers: {
|
|
6148
6561
|
"User-Agent": USER_AGENT$1,
|
|
6149
6562
|
Accept: "application/json"
|
|
@@ -6151,20 +6564,11 @@ async function lookUpOnRegistry(ecosystem, name) {
|
|
|
6151
6564
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
6152
6565
|
});
|
|
6153
6566
|
} catch (error) {
|
|
6154
|
-
throw new RegistryUnavailableError(`could not reach ${
|
|
6155
|
-
}
|
|
6156
|
-
if (response.status === 404) return { status: RegistryStatus.Missing };
|
|
6157
|
-
if (!response.ok) throw new RegistryUnavailableError(`${REGISTRY_NAMES[ecosystem]} responded ${response.status}`);
|
|
6158
|
-
try {
|
|
6159
|
-
const { firstPublished, license } = client.read(await response.json());
|
|
6160
|
-
return firstPublished === void 0 ? { status: RegistryStatus.Missing } : {
|
|
6161
|
-
status: RegistryStatus.Published,
|
|
6162
|
-
firstPublished,
|
|
6163
|
-
license
|
|
6164
|
-
};
|
|
6165
|
-
} catch (error) {
|
|
6166
|
-
throw new RegistryUnavailableError(`${REGISTRY_NAMES[ecosystem]} sent an unexpected answer: ${error instanceof Error ? error.message : String(error)}`);
|
|
6567
|
+
throw new RegistryUnavailableError(`could not reach ${service}: ${error instanceof Error ? error.message : String(error)}`);
|
|
6167
6568
|
}
|
|
6569
|
+
if (response.status === 404) return void 0;
|
|
6570
|
+
if (!response.ok) throw new RegistryUnavailableError(`${service} responded ${response.status}`);
|
|
6571
|
+
return response.json();
|
|
6168
6572
|
}
|
|
6169
6573
|
const LIVE_TRUST_SOURCES = (now) => ({
|
|
6170
6574
|
lookUp: lookUpOnRegistry,
|
|
@@ -6172,6 +6576,7 @@ const LIVE_TRUST_SOURCES = (now) => ({
|
|
|
6172
6576
|
now
|
|
6173
6577
|
});
|
|
6174
6578
|
// packages/engine/src/risk/dependencies/scanDependencies.ts
|
|
6579
|
+
const MAVEN_SEPARATOR = ":";
|
|
6175
6580
|
const OSV_DATABASE_CHECK = {
|
|
6176
6581
|
name: "OSV database",
|
|
6177
6582
|
detail: "package versions new to lockfiles"
|
|
@@ -6384,16 +6789,26 @@ function vulnerabilityFinding(found, lockfile, text) {
|
|
|
6384
6789
|
}, lockfile, lineMentioning$1(text, entry.name), `${entry.name} ${entry.version}`);
|
|
6385
6790
|
}
|
|
6386
6791
|
/**
|
|
6387
|
-
* First line naming the package, so a finding links to where it is declared or locked
|
|
6388
|
-
*
|
|
6389
|
-
*
|
|
6792
|
+
* First line naming the package, so a finding links to where it is declared or locked, never
|
|
6793
|
+
* as part of a longer name:
|
|
6794
|
+
* - a quoted name, in JSON and TOML values, or a quoted Maven coordinate in a Gradle script,
|
|
6795
|
+
* `"group:artifact:1.0"`;
|
|
6796
|
+
* - the name at the start of a line, in TOML keys, requirements files, go.mod's `require`
|
|
6797
|
+
* lines and gradle.lockfile;
|
|
6798
|
+
* - for a Maven `group:artifact`, a pom's `<artifactId>` element.
|
|
6390
6799
|
*/
|
|
6391
6800
|
function lineMentioning$1(text, name) {
|
|
6392
|
-
const escaped = name
|
|
6393
|
-
const
|
|
6801
|
+
const escaped = escapeRegExp(name);
|
|
6802
|
+
const alternatives = [`["']${escaped}["':]`, `^\\s*(?:require\\s+)?${escaped}(?![\\w./-])`];
|
|
6803
|
+
const artifact = name.includes(MAVEN_SEPARATOR) ? name.split(MAVEN_SEPARATOR).at(-1) : void 0;
|
|
6804
|
+
if (artifact !== void 0) alternatives.push(`<artifactId>\\s*${escapeRegExp(artifact)}\\s*</artifactId>`);
|
|
6805
|
+
const pattern = new RegExp(alternatives.join("|"));
|
|
6394
6806
|
const index = text.split("\n").findIndex((line) => pattern.test(line));
|
|
6395
6807
|
return index === -1 ? null : index + 1;
|
|
6396
6808
|
}
|
|
6809
|
+
function escapeRegExp(text) {
|
|
6810
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6811
|
+
}
|
|
6397
6812
|
function previousPathOf$1(diff) {
|
|
6398
6813
|
return diff.status === FileChangeStatus.Renamed || diff.status === FileChangeStatus.Copied ? diff.previousPath : diff.path;
|
|
6399
6814
|
}
|