@repometry/cli 0.2.0 → 0.4.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/README.md +5 -2
- package/package.json +2 -2
- package/target/main/resources/language-catalog.json +54 -0
- package/target/main/resources/licenses/spdx.json +746 -0
- package/target/main/resources/report/json/config-v2.schema.json +2 -1
- package/target/main/resources/report/json/file-metrics-v1.schema.json +2 -0
- package/target/main/resources/report/json/report-v2.schema.json +6 -3
- package/target/main/resources/report/json/repository-summary-v1.schema.json +14 -0
- package/target/main/resources/viewer/index.html +4 -0
- package/target/main/resources/viewer/styles.css +7 -2
- package/target/main/ts/api/git/git.d.ts +2 -1
- package/target/main/ts/api/git/git.js +4 -4
- package/target/main/ts/api/git/inspection-source.js +2 -2
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +5 -4
- package/target/main/ts/api/import/finding-import.js +2 -9
- package/target/main/ts/api/import/license-import.d.ts +2 -0
- package/target/main/ts/api/import/license-import.js +36 -0
- package/target/main/ts/api/import/repository-path.d.ts +1 -0
- package/target/main/ts/api/import/repository-path.js +10 -0
- package/target/main/ts/cli/imports.d.ts +2 -0
- package/target/main/ts/cli/imports.js +6 -2
- package/target/main/ts/cli/run.js +10 -4
- package/target/main/ts/compose/analysis-report.js +5 -2
- package/target/main/ts/compose/analysis-results.d.ts +3 -2
- package/target/main/ts/compose/analysis-results.js +15 -6
- package/target/main/ts/compose/analysis-steps.js +3 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
- package/target/main/ts/compose/analyze-snapshot.js +7 -4
- package/target/main/ts/compose/built-ins.d.ts +2 -2
- package/target/main/ts/compose/built-ins.js +2 -2
- package/target/main/ts/compose/inspect.d.ts +2 -0
- package/target/main/ts/compose/inspect.js +7 -4
- package/target/main/ts/compose/language-discovery.js +3 -1
- package/target/main/ts/compose/load-plugins.js +4 -2
- package/target/main/ts/compose/phases.d.ts +7 -3
- package/target/main/ts/compose/phases.js +26 -10
- package/target/main/ts/plugins/built-in.d.ts +2 -0
- package/target/main/ts/plugins/built-in.js +4 -1
- package/target/main/ts/plugins/duplication/duplication.d.ts +1 -2
- package/target/main/ts/plugins/duplication/duplication.js +18 -17
- package/target/main/ts/plugins/json-spans.d.ts +11 -0
- package/target/main/ts/plugins/json-spans.js +86 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +34 -2
- package/target/main/ts/plugins/language-js/babel-provider.js +39 -35
- package/target/main/ts/plugins/language-js/js-security.d.ts +17 -2
- package/target/main/ts/plugins/language-js/js-security.js +24 -23
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +2 -1
- package/target/main/ts/plugins/language-js/structural-observations.js +2 -2
- package/target/main/ts/plugins/legal/composer-lock.d.ts +2 -0
- package/target/main/ts/plugins/legal/composer-lock.js +24 -0
- package/target/main/ts/plugins/legal/dependencies.d.ts +73 -0
- package/target/main/ts/plugins/legal/dependencies.js +27 -0
- package/target/main/ts/plugins/legal/licenses.d.ts +19 -0
- package/target/main/ts/plugins/legal/licenses.js +112 -0
- package/target/main/ts/plugins/legal/npm-lock.d.ts +3 -0
- package/target/main/ts/plugins/legal/npm-lock.js +30 -0
- package/target/main/ts/plugins/legal/policy.d.ts +72 -0
- package/target/main/ts/plugins/legal/policy.js +149 -0
- package/target/main/ts/plugins/legal/sbom.d.ts +3 -0
- package/target/main/ts/plugins/legal/sbom.js +131 -0
- package/target/main/ts/plugins/legal/unverified-lock.d.ts +1 -0
- package/target/main/ts/plugins/legal/unverified-lock.js +21 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -2
- package/target/main/ts/plugins/maintainability/maintainability.js +34 -33
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +1 -2
- package/target/main/ts/plugins/maintainability/structural-smells.js +5 -5
- package/target/main/ts/plugins/security/actions-security.d.ts +17 -2
- package/target/main/ts/plugins/security/actions-security.js +21 -16
- package/target/main/ts/plugins/security/dockerfile.d.ts +17 -2
- package/target/main/ts/plugins/security/dockerfile.js +23 -18
- package/target/main/ts/plugins/security/npm-supply-chain.d.ts +17 -2
- package/target/main/ts/plugins/security/npm-supply-chain.js +32 -110
- package/target/main/ts/plugins/security/secrets.d.ts +18 -6
- package/target/main/ts/plugins/security/secrets.js +27 -23
- package/target/main/ts/plugins/source/forges.js +25 -32
- package/target/main/ts/report/html/app/viewer-issue-group.js +1 -1
- package/target/main/ts/report/html/app/viewer-metric-registry.js +1 -1
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -1
- package/target/main/ts/report/html/app/viewer-metrics.js +7 -2
- package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-overview-cards.js +20 -1
- package/target/main/ts/report/html/app/viewer-overview-lead.js +4 -1
- package/target/main/ts/report/html/app/viewer-shell.js +3 -1
- package/target/main/ts/report/html/app/viewer-tokenizer.js +37 -9
- package/target/main/ts/report/html/app/viewer-trend-data.js +1 -0
- package/target/main/ts/report/html/app/viewer.js +5 -2
- package/target/main/ts/report/json/validation/report.js +2 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isRecord } from '@repometry/core/internal/engine/plugin.js';
|
|
2
|
+
const packageMarkers = {
|
|
3
|
+
'poetry.lock': /^\[\[package\]\]\s*$/m,
|
|
4
|
+
'go.sum': /^\S+\s+v\S+\s+h1:\S+/m,
|
|
5
|
+
'Gemfile.lock': /^DEPENDENCIES\r?\n {2}\S/m,
|
|
6
|
+
'pnpm-lock.yaml': /^(?:packages|snapshots):[ \t]*\r?\n(?:\s*\r?\n)* {2}\S/m,
|
|
7
|
+
'yarn.lock': /^(?![#\s]|[^\r\n]*@workspace:)[^\r\n]*@[^\r\n]*:[ \t]*\r?$/m,
|
|
8
|
+
};
|
|
9
|
+
export function listsDependencies(name, text) {
|
|
10
|
+
if (name === 'Cargo.lock')
|
|
11
|
+
return /^source\s*=\s*"|^dependencies\s*=\s*\[\s*"/m.test(text);
|
|
12
|
+
if (name === 'uv.lock')
|
|
13
|
+
return /^source\s*=\s*\{\s*(registry|git|url|path)\s*=|^dependencies\s*=\s*\[\s*\{/m.test(text);
|
|
14
|
+
if (name !== 'Pipfile.lock')
|
|
15
|
+
return packageMarkers[name]?.test(text) ?? false;
|
|
16
|
+
const lock = JSON.parse(text);
|
|
17
|
+
if (!isRecord(lock))
|
|
18
|
+
throw new Error('The Pipfile lock must contain a JSON object');
|
|
19
|
+
return [lock.default, lock.develop].some(group => isRecord(group) && Object.keys(group).length > 0);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=unverified-lock.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const maintainability: Plugin;
|
|
1
|
+
export declare const maintainability: import("@repometry/core/internal/engine/plugin.js").Plugin;
|
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { codeStructure, findingResult } from '@repometry/core/internal/engine/author-contracts.js';
|
|
2
|
+
import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
|
|
3
|
+
import { structureCodeLines } from '@repometry/core/internal/model/code-structure.js';
|
|
4
4
|
import { definitions } from '@repometry/core/internal/model/measurement.js';
|
|
5
5
|
import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
|
|
6
6
|
import { structuralRules } from '@repometry/core/internal/profile/maintainability.js';
|
|
7
7
|
import { structuralSmells } from './structural-smells.js';
|
|
8
|
-
export const maintainability = {
|
|
9
|
-
id: 'maintainability', version: '1.0.0',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
8
|
+
export const maintainability = bundledPlugin({
|
|
9
|
+
schema: pluginManifestSchema, id: 'maintainability', version: '1.0.0', category: 'maintainability',
|
|
10
|
+
checks: Object.entries(structuralRules).map(([id, { limit, minutesPerExcess }]) => ({ id, defaults: { limit, cost: minutesPerExcess } })),
|
|
11
|
+
create: () => ({
|
|
12
|
+
produces: [{ contract: findingResult.id, persistence: 'report', metrics: [
|
|
13
|
+
{ id: definitions.cognitiveComplexity, label: 'Cognitive complexity', unit: 'count', scope: 'file', aggregate: 'sum',
|
|
14
|
+
better: 'lower', group: 'Maintainability' },
|
|
15
|
+
{ id: definitions.classes, label: 'Classes', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
|
|
16
|
+
{ id: definitions.codeLines, label: 'Lines of code', short: 'Code lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none',
|
|
17
|
+
group: 'Size' },
|
|
18
|
+
{ id: definitions.comments, label: 'Comment lines', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Size' },
|
|
19
|
+
] }],
|
|
20
|
+
operations: [{
|
|
21
|
+
id: 'file', role: 'inspection', inputs: { syntax: codeStructure, source: sourceFile }, output: findingResult,
|
|
22
|
+
execute(inputs) {
|
|
23
|
+
const facts = inputs.read('syntax', codeStructure);
|
|
24
|
+
const { path, observations = [], cognitiveFunctions = [], cognitiveComplexity, classes, commentLines } = facts;
|
|
25
|
+
const codeLines = structureCodeLines(facts);
|
|
26
|
+
const counts = [[definitions.cognitiveComplexity, cognitiveComplexity], [definitions.classes, classes],
|
|
27
|
+
[definitions.codeLines, codeLines?.length], [definitions.comments, commentLines]];
|
|
28
|
+
return {
|
|
29
|
+
findings: structuralSmells(path, observations),
|
|
30
|
+
measurements: [
|
|
31
|
+
...cognitiveFunctions.map(({ line, column, name, value }) => ({ definition: definitions.cognitiveComplexity, target: 'function', path, line, column, name, value })),
|
|
32
|
+
...counts.flatMap(([definition, value]) => value === undefined ? [] : [{ definition, target: 'file', path, value }]),
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
}],
|
|
37
|
+
}),
|
|
38
|
+
}, { tool: 'repometry', category: 'structure' });
|
|
38
39
|
//# sourceMappingURL=maintainability.js.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { StructuralObservation } from '@repometry/core/internal/
|
|
2
|
-
import type { Finding } from '@repometry/core/internal/model/finding.js';
|
|
1
|
+
import type { Finding, StructuralObservation } from '@repometry/core/internal/engine/author-contracts.js';
|
|
3
2
|
export declare function structuralSmells(path: string, observations: readonly StructuralObservation[]): Finding[];
|
|
@@ -2,13 +2,13 @@ import { structuralRules } from '@repometry/core/internal/profile/maintainabilit
|
|
|
2
2
|
export function structuralSmells(path, observations) {
|
|
3
3
|
const findings = [];
|
|
4
4
|
const functionLimit = structuralRules['function-complexity'].limit;
|
|
5
|
-
const functionExcess = observations.reduce((total, {
|
|
6
|
-
for (const {
|
|
7
|
-
const { limit, minutesPerExcess } = structuralRules[
|
|
5
|
+
const functionExcess = observations.reduce((total, { check, value }) => total + (check === 'function-complexity' ? Math.max(0, value - functionLimit) : 0), 0);
|
|
6
|
+
for (const { check, value, label, line, endLine, anchor } of observations) {
|
|
7
|
+
const { limit, minutesPerExcess } = structuralRules[check];
|
|
8
8
|
if (value <= limit)
|
|
9
9
|
continue;
|
|
10
|
-
const chargedExcess =
|
|
11
|
-
findings.push({
|
|
10
|
+
const chargedExcess = check === 'file-complexity' ? Math.max(0, value - limit - functionExcess) : value - limit;
|
|
11
|
+
findings.push({ check, level: 'medium', path,
|
|
12
12
|
message: `${label} ${value} (limit ${limit})`, line, endLine, effortMinutes: chargedExcess * minutesPerExcess,
|
|
13
13
|
value, limit, anchor: anchor ?? '(file)' });
|
|
14
14
|
}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare const actionsSecurity: {
|
|
2
|
+
id: string;
|
|
3
|
+
version: string;
|
|
4
|
+
api: string;
|
|
5
|
+
tools?: Readonly<Record<string, string>>;
|
|
6
|
+
operations: readonly import("@repometry/core").Operation[];
|
|
7
|
+
rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
|
|
8
|
+
config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
|
|
9
|
+
settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
|
|
10
|
+
kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
|
|
11
|
+
providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
|
|
12
|
+
languageProvenanceRequiresSource?: true;
|
|
13
|
+
produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
|
|
14
|
+
claims: {
|
|
15
|
+
globs: string[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
|
|
2
|
+
import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
|
|
3
3
|
import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
|
|
4
4
|
const tool = 'actions-security';
|
|
5
5
|
const ruleCatalog = {
|
|
@@ -20,19 +20,24 @@ const ruleCatalog = {
|
|
|
20
20
|
'secrets-inherit': { level: 'low',
|
|
21
21
|
description: 'A reusable workflow call passes every repository secret with secrets: inherit.' },
|
|
22
22
|
};
|
|
23
|
+
const paths = ['.github/workflows/*.yml', '.github/workflows/*.yaml', 'action.yml', 'action.yaml'];
|
|
23
24
|
export const actionsSecurity = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
...bundledPlugin({
|
|
26
|
+
schema: pluginManifestSchema, id: tool, version: '1.0.0', category: 'security',
|
|
27
|
+
include: paths,
|
|
28
|
+
checks: Object.entries(ruleCatalog).map(([id, { description }]) => ({ id, description })),
|
|
29
|
+
create: () => ({
|
|
30
|
+
produces: [{ contract: findingResult.id, persistence: 'report' }],
|
|
31
|
+
operations: [{
|
|
32
|
+
id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
|
|
33
|
+
execute(inputs) {
|
|
34
|
+
const { path, bytes } = inputs.read('source', sourceFile);
|
|
35
|
+
return { measurements: [], findings: audit(path, new TextDecoder().decode(bytes)) };
|
|
36
|
+
},
|
|
37
|
+
}],
|
|
38
|
+
}),
|
|
39
|
+
}, { tool: tool, category: 'infrastructure' }),
|
|
40
|
+
claims: { globs: paths },
|
|
36
41
|
};
|
|
37
42
|
function audit(path, text) {
|
|
38
43
|
const root = new YamlReader(text).read();
|
|
@@ -41,7 +46,7 @@ function audit(path, text) {
|
|
|
41
46
|
// Aliased nodes are visited once per alias; report each location once.
|
|
42
47
|
const key = `${rule}\0${line}\0${message}`;
|
|
43
48
|
if (!findings.has(key)) {
|
|
44
|
-
findings.set(key, {
|
|
49
|
+
findings.set(key, { check: rule, level: ruleCatalog[rule].level, message, path, line });
|
|
45
50
|
}
|
|
46
51
|
};
|
|
47
52
|
const jobs = entryOf(root, 'jobs');
|
|
@@ -50,7 +55,7 @@ function audit(path, text) {
|
|
|
50
55
|
else
|
|
51
56
|
for (const step of itemsOf(valueOf(valueOf(root, 'runs'), 'steps')))
|
|
52
57
|
auditStep(step, undefined, report);
|
|
53
|
-
return [...findings.values()].sort((left, right) => left.line - right.line || (left.
|
|
58
|
+
return [...findings.values()].sort((left, right) => left.line - right.line || (left.check < right.check ? -1 : left.check > right.check ? 1 : 0));
|
|
54
59
|
}
|
|
55
60
|
function auditWorkflow(root, jobs, report) {
|
|
56
61
|
const events = triggers(valueOf(root, 'on'));
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare const dockerfile: {
|
|
2
|
+
id: string;
|
|
3
|
+
version: string;
|
|
4
|
+
api: string;
|
|
5
|
+
tools?: Readonly<Record<string, string>>;
|
|
6
|
+
operations: readonly import("@repometry/core").Operation[];
|
|
7
|
+
rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
|
|
8
|
+
config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
|
|
9
|
+
settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
|
|
10
|
+
kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
|
|
11
|
+
providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
|
|
12
|
+
languageProvenanceRequiresSource?: true;
|
|
13
|
+
produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
|
|
14
|
+
claims: {
|
|
15
|
+
globs: string[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
|
|
2
|
+
import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
|
|
3
3
|
import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
|
|
4
4
|
const rules = {
|
|
5
5
|
'unpinned-base-image': { level: 'medium',
|
|
@@ -30,27 +30,32 @@ const secretName = /_(?:[A-Z0-9]*PASS(?:WORD|WD)S?|[A-Z0-9]*SECRETS?|[A-Z0-9]*TO
|
|
|
30
30
|
const qualifiers = new Set(['DIR', 'ENABLED', 'ENDPOINT', 'EXPIRES', 'EXPIRY', 'FILE', 'FORMAT', 'HEADER', 'HOST', 'LEN', 'LENGTH',
|
|
31
31
|
'LIFETIME', 'MODE', 'NAME', 'PATH', 'POLICY', 'PORT', 'REQUIRED', 'SIZE', 'TIMEOUT', 'TTL', 'TYPE', 'URI', 'URL', 'USER',
|
|
32
32
|
'USERNAME', 'VERSION']);
|
|
33
|
+
const paths = ['**/Dockerfile', '**/Dockerfile.*', '**/*.dockerfile', '**/Containerfile'];
|
|
33
34
|
export const dockerfile = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
...bundledPlugin({
|
|
36
|
+
schema: pluginManifestSchema, id: 'dockerfile', version: '1.0.0', category: 'security',
|
|
37
|
+
include: paths,
|
|
38
|
+
checks: Object.entries(rules).map(([id, { description }]) => ({ id, description })),
|
|
39
|
+
create: () => ({
|
|
40
|
+
produces: [{ contract: findingResult.id, persistence: 'report' }],
|
|
41
|
+
operations: [{
|
|
42
|
+
id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
|
|
43
|
+
execute(inputs) {
|
|
44
|
+
const { path, bytes } = inputs.read('source', sourceFile);
|
|
45
|
+
if (bytes.includes(0))
|
|
46
|
+
return { measurements: [], findings: [] };
|
|
47
|
+
return { measurements: [], findings: scan(path, new TextDecoder().decode(bytes)) };
|
|
48
|
+
},
|
|
49
|
+
}],
|
|
50
|
+
}),
|
|
51
|
+
}, { tool: 'dockerfile', category: 'infrastructure', categoryBeforeRule: true }),
|
|
52
|
+
claims: { globs: paths },
|
|
48
53
|
};
|
|
49
54
|
function scan(path, text) {
|
|
50
55
|
const { escape, instructions } = parseDockerfile(text);
|
|
51
56
|
const findings = [];
|
|
52
57
|
const report = (rule, at, message) => {
|
|
53
|
-
findings.push({
|
|
58
|
+
findings.push({ check: rule, level: rules[rule].level, message, path,
|
|
54
59
|
line: at.line, endLine: at.endLine });
|
|
55
60
|
};
|
|
56
61
|
const globals = new Map();
|
|
@@ -86,7 +91,7 @@ function scan(path, text) {
|
|
|
86
91
|
}
|
|
87
92
|
checkFinalStage();
|
|
88
93
|
return findings.sort((left, right) => left.line - right.line || left.endLine - right.endLine
|
|
89
|
-
|| left.
|
|
94
|
+
|| left.check.localeCompare(right.check));
|
|
90
95
|
function startStage(instruction) {
|
|
91
96
|
const [reference = '', as, name] = words(instruction.args, escape).filter(item => !item.startsWith('--'));
|
|
92
97
|
const image = expand(reference, globals);
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import type { Plugin } from '@repometry/core/internal/engine/plugin.js';
|
|
2
1
|
/** Above this many hits of one rule in one file, the rest collapse into a single summary finding. */
|
|
3
2
|
export declare const findingsPerRule = 20;
|
|
4
|
-
export declare const npmSupplyChain:
|
|
3
|
+
export declare const npmSupplyChain: {
|
|
4
|
+
id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
api: string;
|
|
7
|
+
tools?: Readonly<Record<string, string>>;
|
|
8
|
+
operations: readonly import("@repometry/core/internal/engine/plugin.js").Operation[];
|
|
9
|
+
rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
|
|
10
|
+
config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
|
|
11
|
+
settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
|
|
12
|
+
kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
|
|
13
|
+
providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
|
|
14
|
+
languageProvenanceRequiresSource?: true;
|
|
15
|
+
produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
|
|
16
|
+
claims: {
|
|
17
|
+
globs: string[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { isRecord
|
|
2
|
-
import { findingResult } from '@repometry/core/internal/
|
|
1
|
+
import { isRecord } from '@repometry/core/internal/engine/plugin.js';
|
|
2
|
+
import { findingResult } from '@repometry/core/internal/engine/author-contracts.js';
|
|
3
|
+
import { bundledPlugin, pluginManifestSchema } from '@repometry/core/internal/engine/plugin-manifest.js';
|
|
3
4
|
import { sourceFile } from '@repometry/core/internal/model/snapshot.js';
|
|
5
|
+
import { locateJsonSpans, pointer } from '../json-spans.js';
|
|
4
6
|
const tool = 'npm-supply-chain';
|
|
5
7
|
const ruleDescriptions = {
|
|
6
8
|
'dependency-from-url': 'A package.json dependency is installed from a URL, git repository or tarball instead of a registry version.',
|
|
@@ -19,27 +21,32 @@ const installScripts = ['preinstall', 'install', 'postinstall'];
|
|
|
19
21
|
const levelOrder = ['low', 'medium', 'high'];
|
|
20
22
|
/** A repository page URL such as https://github.com/owner/repo, which npm clones with git. */
|
|
21
23
|
const hostedRepository = /^https:\/\/(?:www\.)?(?:github\.com|gitlab\.com|bitbucket\.org)\/[^/?#]+\/[^/?#]+\/?(?:#.*)?$/i;
|
|
24
|
+
const paths = ['**/package.json', '**/package-lock.json', '**/npm-shrinkwrap.json', '**/yarn.lock', '**/pnpm-lock.yaml'];
|
|
22
25
|
export const npmSupplyChain = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
...bundledPlugin({
|
|
27
|
+
schema: pluginManifestSchema, id: tool, version: '1.0.0', category: 'security',
|
|
28
|
+
include: paths,
|
|
29
|
+
checks: Object.entries(ruleDescriptions).map(([id, description]) => ({ id, description })),
|
|
30
|
+
create: () => ({
|
|
31
|
+
produces: [{ contract: findingResult.id, persistence: 'report' }],
|
|
32
|
+
operations: [{
|
|
33
|
+
id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
|
|
34
|
+
execute(inputs) {
|
|
35
|
+
const { path, bytes } = inputs.read('source', sourceFile);
|
|
36
|
+
if (path.split('/').includes('node_modules'))
|
|
37
|
+
return { measurements: [], findings: [] };
|
|
38
|
+
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
39
|
+
const text = new TextDecoder().decode(bytes);
|
|
40
|
+
const hits = name === 'package.json' ? jsonHits(name, text, manifestHits)
|
|
41
|
+
: name === 'package-lock.json' || name === 'npm-shrinkwrap.json' ? jsonHits(name, text, packageLockHits)
|
|
42
|
+
: name === 'yarn.lock' ? yarnLockHits(text)
|
|
43
|
+
: name === 'pnpm-lock.yaml' ? pnpmLockHits(text) : [];
|
|
44
|
+
return { measurements: [], findings: capped(path, name, hits) };
|
|
45
|
+
},
|
|
46
|
+
}],
|
|
47
|
+
}),
|
|
48
|
+
}, { tool: tool, category: 'dependency' }),
|
|
49
|
+
claims: { globs: paths },
|
|
43
50
|
};
|
|
44
51
|
function capped(path, name, hits) {
|
|
45
52
|
const byLine = [...hits].sort((left, right) => (left.line ?? 0) - (right.line ?? 0));
|
|
@@ -52,11 +59,11 @@ function capped(path, name, hits) {
|
|
|
52
59
|
if (rest.length === 0)
|
|
53
60
|
continue;
|
|
54
61
|
const level = rest.reduce((worst, hit) => levelOrder.indexOf(hit.level) > levelOrder.indexOf(worst) ? hit.level : worst, 'low');
|
|
55
|
-
summaries.push({
|
|
62
|
+
summaries.push({ check: rule, level, path,
|
|
56
63
|
message: `${name} has ${matching.length} ${rule} findings; only the first ${findingsPerRule} are listed.` });
|
|
57
64
|
}
|
|
58
65
|
kept.sort((left, right) => (left.line ?? 0) - (right.line ?? 0));
|
|
59
|
-
return [...kept.map(({ rule, level, message, line, endLine }) => ({
|
|
66
|
+
return [...kept.map(({ rule, level, message, line, endLine }) => ({ check: rule, level, message, path,
|
|
60
67
|
...(line === undefined ? {} : { line, endLine: endLine ?? line }) })), ...summaries];
|
|
61
68
|
}
|
|
62
69
|
function jsonHits(name, text, analyse) {
|
|
@@ -70,7 +77,7 @@ function jsonHits(name, text, analyse) {
|
|
|
70
77
|
const found = analyse(value);
|
|
71
78
|
if (found.length === 0)
|
|
72
79
|
return [];
|
|
73
|
-
const spans =
|
|
80
|
+
const spans = locateJsonSpans(text, new Set(found.map(hit => pointer(hit.at))), Math.max(...found.map(hit => hit.at.length)));
|
|
74
81
|
return found.map(({ at, ...hit }) => ({ ...hit, ...spans.get(pointer(at)) }));
|
|
75
82
|
}
|
|
76
83
|
function manifestHits(manifest) {
|
|
@@ -280,89 +287,4 @@ function display(url) {
|
|
|
280
287
|
function abbreviate(text, limit) {
|
|
281
288
|
return text.length > limit ? `${text.slice(0, limit - 1)}…` : text;
|
|
282
289
|
}
|
|
283
|
-
function pointer(path) {
|
|
284
|
-
return path.map(segment => JSON.stringify(segment)).join('');
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Find the lines of the wanted values in JSON text that JSON.parse has already accepted. A member starts on the line
|
|
288
|
-
* of its key and ends on the line where its value ends. Only paths up to `depth` keys deep are tracked.
|
|
289
|
-
*/
|
|
290
|
-
function locate(text, wanted, depth) {
|
|
291
|
-
const spans = new Map();
|
|
292
|
-
const stack = [];
|
|
293
|
-
let line = 1;
|
|
294
|
-
const child = () => {
|
|
295
|
-
const parent = stack.at(-1);
|
|
296
|
-
if (!parent)
|
|
297
|
-
return { path: '', line };
|
|
298
|
-
const path = parent.path === undefined || stack.length > depth ? undefined
|
|
299
|
-
: parent.path + (parent.array ? `#${parent.index}` : JSON.stringify(parent.key));
|
|
300
|
-
return { path, line: parent.array ? line : parent.keyLine };
|
|
301
|
-
};
|
|
302
|
-
const scalar = () => {
|
|
303
|
-
const { path, line: start } = child();
|
|
304
|
-
if (path !== undefined && wanted.has(path))
|
|
305
|
-
spans.set(path, { line: start, endLine: line });
|
|
306
|
-
};
|
|
307
|
-
for (let index = 0; index < text.length;) {
|
|
308
|
-
const char = text[index];
|
|
309
|
-
if (char === '\n')
|
|
310
|
-
line++;
|
|
311
|
-
if (char === '\n' || char === ' ' || char === '\t' || char === '\r' || char === ':') {
|
|
312
|
-
index++;
|
|
313
|
-
}
|
|
314
|
-
else if (char === ',') {
|
|
315
|
-
const parent = stack.at(-1);
|
|
316
|
-
if (parent?.array)
|
|
317
|
-
parent.index++;
|
|
318
|
-
else if (parent)
|
|
319
|
-
parent.expectKey = true;
|
|
320
|
-
index++;
|
|
321
|
-
}
|
|
322
|
-
else if (char === '"') {
|
|
323
|
-
const end = stringEnd(text, index);
|
|
324
|
-
const parent = stack.at(-1);
|
|
325
|
-
if (parent && !parent.array && parent.expectKey) {
|
|
326
|
-
const raw = text.slice(index + 1, end);
|
|
327
|
-
parent.key = raw.includes('\\') ? JSON.parse(text.slice(index, end + 1)) : raw;
|
|
328
|
-
parent.keyLine = line;
|
|
329
|
-
parent.expectKey = false;
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
scalar();
|
|
333
|
-
}
|
|
334
|
-
index = end + 1;
|
|
335
|
-
}
|
|
336
|
-
else if (char === '{' || char === '[') {
|
|
337
|
-
const { path, line: start } = child();
|
|
338
|
-
stack.push({ path, line: start, array: char === '[', index: 0, key: '', keyLine: line, expectKey: char === '{' });
|
|
339
|
-
index++;
|
|
340
|
-
}
|
|
341
|
-
else if (char === '}' || char === ']') {
|
|
342
|
-
const frame = stack.pop();
|
|
343
|
-
if (frame?.path !== undefined && wanted.has(frame.path))
|
|
344
|
-
spans.set(frame.path, { line: frame.line, endLine: line });
|
|
345
|
-
index++;
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
scalar();
|
|
349
|
-
while (index < text.length && !/[\s,\]}]/.test(text[index]))
|
|
350
|
-
index++;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return spans;
|
|
354
|
-
}
|
|
355
|
-
function stringEnd(text, start) {
|
|
356
|
-
for (let from = start + 1;;) {
|
|
357
|
-
const quote = text.indexOf('"', from);
|
|
358
|
-
if (quote < 0)
|
|
359
|
-
return text.length;
|
|
360
|
-
let slashes = 0;
|
|
361
|
-
while (text[quote - 1 - slashes] === '\\')
|
|
362
|
-
slashes++;
|
|
363
|
-
if (slashes % 2 === 0)
|
|
364
|
-
return quote;
|
|
365
|
-
from = quote + 1;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
290
|
//# sourceMappingURL=npm-supply-chain.js.map
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import type { Plugin, RuleDescriptor } from '@repometry/core/internal/engine/plugin.js';
|
|
2
|
-
import type { Finding } from '@repometry/core/internal/model/finding.js';
|
|
3
1
|
/** A line that contains this marker is never reported. */
|
|
4
2
|
export declare const ignoreMarker = "repometry-ignore-secret";
|
|
5
3
|
/** Files larger than this are not scanned. */
|
|
6
4
|
export declare const maxScannedBytes: number;
|
|
7
5
|
export declare function isPlaceholder(value: string): boolean;
|
|
8
6
|
export declare function shannonEntropy(value: string): number;
|
|
9
|
-
export declare const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export declare const secrets: {
|
|
8
|
+
id: string;
|
|
9
|
+
version: string;
|
|
10
|
+
api: string;
|
|
11
|
+
tools?: Readonly<Record<string, string>>;
|
|
12
|
+
operations: readonly import("@repometry/core/internal/engine/plugin.js").Operation[];
|
|
13
|
+
rules?: readonly import("@repometry/core/internal/engine/plugin.js").RuleDescriptor[];
|
|
14
|
+
config?: import("@repometry/core/internal/engine/plugin.js").PluginConfigSchema;
|
|
15
|
+
settings?: import("@repometry/core/internal/model/plugin-data.js").JsonValue;
|
|
16
|
+
kinds: readonly import("@repometry/core/internal/engine/plugin.js").PluginKind[];
|
|
17
|
+
providesLanguages?: readonly import("@repometry/core/internal/model/language.js").ProvidedLanguage[];
|
|
18
|
+
languageProvenanceRequiresSource?: true;
|
|
19
|
+
produces: readonly import("@repometry/core/internal/engine/plugin.js").ProductDeclaration[];
|
|
20
|
+
claims: {
|
|
21
|
+
globs: string[];
|
|
22
|
+
scanOnly: boolean;
|
|
23
|
+
};
|
|
24
|
+
};
|