@lateos/npm-scan 0.18.1 → 0.18.2

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.
Files changed (93) hide show
  1. package/.dockerignore +20 -20
  2. package/.husky/pre-commit +1 -1
  3. package/CHANGELOG.md +233 -199
  4. package/LICENSING.md +19 -19
  5. package/README.de.md +708 -708
  6. package/README.fr.md +707 -707
  7. package/README.ja.md +704 -704
  8. package/README.md +826 -826
  9. package/README.zh.md +708 -708
  10. package/SECURITY.md +72 -72
  11. package/backend/cra.js +68 -68
  12. package/backend/db/schema.sql +32 -32
  13. package/backend/db.js +88 -88
  14. package/backend/detectors/atk-001-lifecycle.js +17 -17
  15. package/backend/detectors/atk-002-obfusc.js +261 -261
  16. package/backend/detectors/atk-003-creds.js +13 -13
  17. package/backend/detectors/atk-004-persist.js +13 -13
  18. package/backend/detectors/atk-005-exfil.js +13 -13
  19. package/backend/detectors/atk-006-depconf.js +14 -14
  20. package/backend/detectors/atk-007-typosquat.js +34 -34
  21. package/backend/detectors/atk-008-tarball-tamper.js +91 -91
  22. package/backend/detectors/atk-009-dormant-trigger.js +62 -62
  23. package/backend/detectors/atk-010-sandbox-evasion.js +50 -50
  24. package/backend/detectors/atk-011-transitive-prop.js +76 -76
  25. package/backend/detectors/cve-2026-48710-badhost/codePattern.js +99 -99
  26. package/backend/detectors/cve-2026-48710-badhost/findings.js +105 -105
  27. package/backend/detectors/cve-2026-48710-badhost/index.js +15 -15
  28. package/backend/detectors/cve-2026-48710-badhost/manifest.js +305 -305
  29. package/backend/detectors/cve-2026-48710-badhost/transitive.js +189 -189
  30. package/backend/detectors/hf-impersonation/index.js +396 -396
  31. package/backend/detectors/hf-impersonation/jaro-winkler.js +44 -44
  32. package/backend/detectors/hf-impersonation/known-orgs.js +5 -5
  33. package/backend/detectors/hf-impersonation/simhash.js +46 -46
  34. package/backend/detectors/index.js +81 -75
  35. package/backend/detectors/megalodon/d1-workflow-scan.js +147 -147
  36. package/backend/detectors/megalodon/d2-credential-harvest.js +61 -61
  37. package/backend/detectors/megalodon/d3-publish-velocity.js +67 -67
  38. package/backend/detectors/megalodon/d4-publisher-drift.js +124 -124
  39. package/backend/detectors/megalodon/d5-bot-commit-identity.js +3 -3
  40. package/backend/detectors/megalodon/d6-date-anachronism.js +3 -3
  41. package/backend/detectors/megalodon/index.js +80 -80
  42. package/backend/detectors/megalodon/types.js +9 -9
  43. package/backend/detectors/mini-shai-hulud/d1-burst-publish.js +42 -42
  44. package/backend/detectors/mini-shai-hulud/d2-sibling-compromise.js +116 -116
  45. package/backend/detectors/mini-shai-hulud/d3-slsa-mismatch.js +72 -72
  46. package/backend/detectors/mini-shai-hulud/d4-maintainer-anomaly.js +45 -45
  47. package/backend/detectors/mini-shai-hulud/d5-ioc-check.js +95 -95
  48. package/backend/detectors/mini-shai-hulud/d6-token-exfil.js +38 -38
  49. package/backend/detectors/mini-shai-hulud/index.js +118 -118
  50. package/backend/detectors/mini-shai-hulud/iocs.json +79 -79
  51. package/backend/detectors/tier1-cloud-imds.js +124 -0
  52. package/backend/detectors/tier1-infostealer.js +36 -0
  53. package/backend/detectors/tier1-multistage-postinstall.js +81 -0
  54. package/backend/detectors/tier1-version-confusion.js +107 -0
  55. package/backend/fetch.js +175 -175
  56. package/backend/index.js +4 -4
  57. package/backend/license.js +89 -89
  58. package/backend/lockfile.js +379 -379
  59. package/backend/pdf.js +245 -245
  60. package/backend/policy.js +193 -193
  61. package/backend/report.js +254 -254
  62. package/backend/sbom.js +66 -66
  63. package/backend/siem/cef.js +32 -32
  64. package/backend/siem/ecs.js +40 -40
  65. package/backend/siem/index.js +18 -18
  66. package/backend/siem/qradar.js +56 -56
  67. package/backend/siem/sentinel.js +27 -27
  68. package/backend/vsix-scan/detectors/activation-event-risk.js +116 -116
  69. package/backend/vsix-scan/detectors/burst-publish.js +52 -52
  70. package/backend/vsix-scan/detectors/exfil-pattern.js +88 -88
  71. package/backend/vsix-scan/detectors/known-ioc.js +105 -105
  72. package/backend/vsix-scan/detectors/orphan-commit-fetch.js +69 -69
  73. package/backend/vsix-scan/detectors/publisher-anomaly.js +70 -70
  74. package/backend/vsix-scan/index.js +183 -183
  75. package/backend/vsix-scan/marketplace-client.js +145 -145
  76. package/backend/vsix-scan/vsix-iocs.json +31 -31
  77. package/cli/cli.js +458 -458
  78. package/deploy/helm/npm-scan/Chart.yaml +21 -21
  79. package/deploy/helm/npm-scan/templates/_helpers.tpl +8 -8
  80. package/deploy/helm/npm-scan/templates/api.yaml +93 -93
  81. package/deploy/helm/npm-scan/templates/ingress.yaml +27 -27
  82. package/deploy/helm/npm-scan/templates/postgresql.yaml +66 -66
  83. package/deploy/helm/npm-scan/templates/secrets.yaml +18 -18
  84. package/deploy/helm/npm-scan/templates/worker.yaml +31 -31
  85. package/deploy/helm/npm-scan/values.byoc.yaml +74 -74
  86. package/deploy/helm/npm-scan/values.yaml +102 -102
  87. package/package.json +57 -57
  88. package/scripts/download-corpus.js +30 -30
  89. package/scripts/gen-mal-corpus.js +34 -34
  90. package/test/fixtures/lockfiles/npm-lock.json +68 -68
  91. package/test/fixtures/lockfiles/pnpm-lock.yaml +117 -117
  92. package/test/fixtures/lockfiles/yarn.lock +103 -103
  93. package/test/fixtures/mock-data.js +69 -69
package/backend/policy.js CHANGED
@@ -1,193 +1,193 @@
1
- import { readFileSync } from 'fs';
2
- import { load as yamlLoad } from 'js-yaml';
3
-
4
- const SEVERITY_ORDER = ['none', 'low', 'medium', 'high', 'critical'];
5
- const VALID_SEVERITIES = new Set(SEVERITY_ORDER);
6
-
7
- const KNOWN_REPUTABLE_PACKAGES = new Set([
8
- 'react', 'react-dom', 'vue', 'angular', 'next', 'nuxt',
9
- 'express', 'fastify', 'hono', 'koa', 'connect',
10
- 'webpack', 'vite', 'rollup', 'esbuild', 'typescript', 'babel-core',
11
- 'lodash', 'ramda', 'underscore',
12
- 'axios', 'node-fetch', 'got', 'superagent',
13
- 'sequelize', 'prisma', 'typeorm', 'mongoose',
14
- 'jest', 'mocha', 'vitest', 'ava',
15
- 'prettier', 'eslint', 'stylelint',
16
- 'socket.io', 'ws',
17
- 'rimraf', 'glob', 'minimatch', 'fs-extra',
18
- 'electron', 'puppeteer', 'playwright', 'sharp', 'node-canvas',
19
- 'ffmpeg-static', 'turbo',
20
- 'react-scripts', '@angular/cli',
21
- 'gatsby', 'parcel',
22
- 'tslib', 'core-js', 'regenerator-runtime', 'buffer',
23
- 'node-gyp', 'node-pre-gyp',
24
- 'winston', 'uuid', 'moment', 'dotenv', 'pg', 'semver', 'redux', 'redis',
25
- 'dayjs', 'luxon', 'chalk', 'debug', 'cors', 'helmet', 'multer',
26
- 'body-parser', 'cheerio', 'bluebird', 'bcrypt', 'commander', 'yargs',
27
- 'passport', 'jsonwebtoken', 'nodemailer', 'class-validator',
28
- ]);
29
-
30
- function severityIndex(s) {
31
- return SEVERITY_ORDER.indexOf(s);
32
- }
33
-
34
- function matchesFilePath(filePath, pattern) {
35
- if (!pattern) return false;
36
- if (pattern === '*') return true;
37
- const regexPattern = pattern
38
- .replace(/\./g, '\\.')
39
- .replace(/\*\*/g, '___DOUBLE_STAR___')
40
- .replace(/\*/g, '[^/]*')
41
- .replace(/___DOUBLE_STAR___/g, '.*');
42
- return new RegExp(`^${regexPattern}$`).test(filePath);
43
- }
44
-
45
- function matchesContext(finding, rule) {
46
- const ctx = finding.context;
47
- if (!ctx) return false;
48
-
49
- if (rule.context?.is_dist_build === true && !ctx.is_dist_build) return false;
50
- if (rule.context?.is_dist_build === false && ctx.is_dist_build) return false;
51
- if (rule.context?.is_test_fixture === true && !ctx.is_test_fixture) return false;
52
- if (rule.context?.is_test_fixture === false && ctx.is_test_fixture) return false;
53
- if (rule.context?.is_lifecycle_hook === true && !ctx.is_lifecycle_hook) return false;
54
- if (rule.context?.is_lifecycle_hook === false && ctx.is_lifecycle_hook) return false;
55
- if (rule.context?.is_known_safe_domain === true && !ctx.is_known_safe_domain) return false;
56
- if (rule.context?.is_known_safe_domain === false && ctx.is_known_safe_domain) return false;
57
-
58
- if (rule.context?.file_path && !matchesFilePath(ctx.file_path, rule.context.file_path)) return false;
59
- if (rule.context?.url_domain) {
60
- if (!ctx.url_domain) return false;
61
- const domainPattern = rule.context.url_domain.replace(/\*/g, '.*');
62
- if (!new RegExp(`^${domainPattern}$`).test(ctx.url_domain)) return false;
63
- }
64
-
65
- return true;
66
- }
67
-
68
- function matchesKnownReputable(packageName) {
69
- if (KNOWN_REPUTABLE_PACKAGES.has(packageName)) return true;
70
- const [scope, name] = packageName.split('/');
71
- if (scope && name && KNOWN_REPUTABLE_PACKAGES.has(`${scope}/*`)) return true;
72
- return false;
73
- }
74
-
75
- function getPackageReputationTier(pkgName) {
76
- const name = pkgName?.replace(/^@/, '').replace(/\/.*/, '') || '';
77
- if (matchesKnownReputable(name)) return 'trusted';
78
- return 'unknown';
79
- }
80
-
81
- function matchesSuppressRule(finding, pkgName, rule) {
82
- if (rule.atk_id !== (finding.atk_id || finding.id)) return false;
83
- if (rule.package && rule.package !== '*' && rule.package !== pkgName) return false;
84
-
85
- if (rule.context && !matchesContext(finding, rule)) return false;
86
-
87
- if (rule.reputation_tier) {
88
- const tier = getPackageReputationTier(pkgName);
89
- if (rule.reputation_tier !== tier && !(rule.reputation_tier === '*' || rule.reputation_tier === 'any')) return false;
90
- }
91
-
92
- return true;
93
- }
94
-
95
- function loadPolicy(path) {
96
- const raw = readFileSync(path, 'utf8').trim();
97
- let policy;
98
-
99
- if (path.endsWith('.json')) {
100
- policy = JSON.parse(raw);
101
- } else {
102
- policy = yamlLoad(raw);
103
- }
104
-
105
- if (!policy || typeof policy !== 'object') {
106
- throw new Error('Policy file must contain a valid YAML/JSON object');
107
- }
108
-
109
- if (policy.severity_overrides) {
110
- for (const [atkId, severity] of Object.entries(policy.severity_overrides)) {
111
- if (!VALID_SEVERITIES.has(severity)) {
112
- throw new Error(`Invalid severity "${severity}" for ${atkId} — must be one of: low, medium, high, critical`);
113
- }
114
- }
115
- }
116
-
117
- if (policy.fail_on && !VALID_SEVERITIES.has(policy.fail_on)) {
118
- throw new Error(`Invalid fail_on "${policy.fail_on}" — must be one of: none, low, medium, high, critical`);
119
- }
120
-
121
- if (policy.suppress) {
122
- if (!Array.isArray(policy.suppress)) {
123
- throw new Error('suppress must be an array');
124
- }
125
- for (const rule of policy.suppress) {
126
- if (!rule.atk_id) {
127
- throw new Error('Each suppress rule must have an atk_id');
128
- }
129
- }
130
- }
131
-
132
- if (policy.allow) {
133
- if (policy.allow.packages && !Array.isArray(policy.allow.packages)) {
134
- throw new Error('allow.packages must be an array');
135
- }
136
- }
137
-
138
- return sanitizePolicy(policy);
139
- }
140
-
141
- function sanitizePolicy(policy) {
142
- return {
143
- allow: { packages: policy.allow?.packages ?? [] },
144
- severity_overrides: policy.severity_overrides ?? {},
145
- fail_on: policy.fail_on ?? 'none',
146
- suppress: (policy.suppress ?? []).map(r => ({
147
- atk_id: r.atk_id,
148
- package: r.package || '*',
149
- reason: r.reason || '',
150
- context: r.context || null,
151
- reputation_tier: r.reputation_tier || null,
152
- })),
153
- };
154
- }
155
-
156
- function isAllowed(packageName, policy) {
157
- if (!policy.allow.packages.length) return false;
158
- const nameOnly = packageName.split('@')[0];
159
- return policy.allow.packages.some(p => p === packageName || p === nameOnly);
160
- }
161
-
162
- function applyPolicy(findings, packageName, policy) {
163
- let filtered = [...findings];
164
-
165
- if (policy.suppress.length) {
166
- filtered = filtered.filter(f => {
167
- if (f.context?.is_lifecycle_hook) return true;
168
- if (f.context?.is_multi_layer) return true;
169
- return !policy.suppress.some(r => matchesSuppressRule(f, packageName, r));
170
- });
171
- }
172
-
173
- filtered = filtered.map(f => {
174
- const override = policy.severity_overrides[f.atk_id || f.id];
175
- if (override) {
176
- return { ...f, severity: override, _severityOverridden: true };
177
- }
178
- return f;
179
- });
180
-
181
- const blocked = checkFailOn(filtered, policy);
182
-
183
- return { findings: filtered, blocked };
184
- }
185
-
186
- function checkFailOn(findings, policy) {
187
- if (policy.fail_on === 'none') return false;
188
-
189
- const threshold = severityIndex(policy.fail_on);
190
- return findings.some(f => severityIndex(f.severity) >= threshold);
191
- }
192
-
193
- export { loadPolicy, applyPolicy, isAllowed, getPackageReputationTier, matchesContext, KNOWN_REPUTABLE_PACKAGES };
1
+ import { readFileSync } from 'fs';
2
+ import { load as yamlLoad } from 'js-yaml';
3
+
4
+ const SEVERITY_ORDER = ['none', 'low', 'medium', 'high', 'critical'];
5
+ const VALID_SEVERITIES = new Set(SEVERITY_ORDER);
6
+
7
+ const KNOWN_REPUTABLE_PACKAGES = new Set([
8
+ 'react', 'react-dom', 'vue', 'angular', 'next', 'nuxt',
9
+ 'express', 'fastify', 'hono', 'koa', 'connect',
10
+ 'webpack', 'vite', 'rollup', 'esbuild', 'typescript', 'babel-core',
11
+ 'lodash', 'ramda', 'underscore',
12
+ 'axios', 'node-fetch', 'got', 'superagent',
13
+ 'sequelize', 'prisma', 'typeorm', 'mongoose',
14
+ 'jest', 'mocha', 'vitest', 'ava',
15
+ 'prettier', 'eslint', 'stylelint',
16
+ 'socket.io', 'ws',
17
+ 'rimraf', 'glob', 'minimatch', 'fs-extra',
18
+ 'electron', 'puppeteer', 'playwright', 'sharp', 'node-canvas',
19
+ 'ffmpeg-static', 'turbo',
20
+ 'react-scripts', '@angular/cli',
21
+ 'gatsby', 'parcel',
22
+ 'tslib', 'core-js', 'regenerator-runtime', 'buffer',
23
+ 'node-gyp', 'node-pre-gyp',
24
+ 'winston', 'uuid', 'moment', 'dotenv', 'pg', 'semver', 'redux', 'redis',
25
+ 'dayjs', 'luxon', 'chalk', 'debug', 'cors', 'helmet', 'multer',
26
+ 'body-parser', 'cheerio', 'bluebird', 'bcrypt', 'commander', 'yargs',
27
+ 'passport', 'jsonwebtoken', 'nodemailer', 'class-validator',
28
+ ]);
29
+
30
+ function severityIndex(s) {
31
+ return SEVERITY_ORDER.indexOf(s);
32
+ }
33
+
34
+ function matchesFilePath(filePath, pattern) {
35
+ if (!pattern) return false;
36
+ if (pattern === '*') return true;
37
+ const regexPattern = pattern
38
+ .replace(/\./g, '\\.')
39
+ .replace(/\*\*/g, '___DOUBLE_STAR___')
40
+ .replace(/\*/g, '[^/]*')
41
+ .replace(/___DOUBLE_STAR___/g, '.*');
42
+ return new RegExp(`^${regexPattern}$`).test(filePath);
43
+ }
44
+
45
+ function matchesContext(finding, rule) {
46
+ const ctx = finding.context;
47
+ if (!ctx) return false;
48
+
49
+ if (rule.context?.is_dist_build === true && !ctx.is_dist_build) return false;
50
+ if (rule.context?.is_dist_build === false && ctx.is_dist_build) return false;
51
+ if (rule.context?.is_test_fixture === true && !ctx.is_test_fixture) return false;
52
+ if (rule.context?.is_test_fixture === false && ctx.is_test_fixture) return false;
53
+ if (rule.context?.is_lifecycle_hook === true && !ctx.is_lifecycle_hook) return false;
54
+ if (rule.context?.is_lifecycle_hook === false && ctx.is_lifecycle_hook) return false;
55
+ if (rule.context?.is_known_safe_domain === true && !ctx.is_known_safe_domain) return false;
56
+ if (rule.context?.is_known_safe_domain === false && ctx.is_known_safe_domain) return false;
57
+
58
+ if (rule.context?.file_path && !matchesFilePath(ctx.file_path, rule.context.file_path)) return false;
59
+ if (rule.context?.url_domain) {
60
+ if (!ctx.url_domain) return false;
61
+ const domainPattern = rule.context.url_domain.replace(/\*/g, '.*');
62
+ if (!new RegExp(`^${domainPattern}$`).test(ctx.url_domain)) return false;
63
+ }
64
+
65
+ return true;
66
+ }
67
+
68
+ function matchesKnownReputable(packageName) {
69
+ if (KNOWN_REPUTABLE_PACKAGES.has(packageName)) return true;
70
+ const [scope, name] = packageName.split('/');
71
+ if (scope && name && KNOWN_REPUTABLE_PACKAGES.has(`${scope}/*`)) return true;
72
+ return false;
73
+ }
74
+
75
+ function getPackageReputationTier(pkgName) {
76
+ const name = pkgName?.replace(/^@/, '').replace(/\/.*/, '') || '';
77
+ if (matchesKnownReputable(name)) return 'trusted';
78
+ return 'unknown';
79
+ }
80
+
81
+ function matchesSuppressRule(finding, pkgName, rule) {
82
+ if (rule.atk_id !== (finding.atk_id || finding.id)) return false;
83
+ if (rule.package && rule.package !== '*' && rule.package !== pkgName) return false;
84
+
85
+ if (rule.context && !matchesContext(finding, rule)) return false;
86
+
87
+ if (rule.reputation_tier) {
88
+ const tier = getPackageReputationTier(pkgName);
89
+ if (rule.reputation_tier !== tier && !(rule.reputation_tier === '*' || rule.reputation_tier === 'any')) return false;
90
+ }
91
+
92
+ return true;
93
+ }
94
+
95
+ function loadPolicy(path) {
96
+ const raw = readFileSync(path, 'utf8').trim();
97
+ let policy;
98
+
99
+ if (path.endsWith('.json')) {
100
+ policy = JSON.parse(raw);
101
+ } else {
102
+ policy = yamlLoad(raw);
103
+ }
104
+
105
+ if (!policy || typeof policy !== 'object') {
106
+ throw new Error('Policy file must contain a valid YAML/JSON object');
107
+ }
108
+
109
+ if (policy.severity_overrides) {
110
+ for (const [atkId, severity] of Object.entries(policy.severity_overrides)) {
111
+ if (!VALID_SEVERITIES.has(severity)) {
112
+ throw new Error(`Invalid severity "${severity}" for ${atkId} — must be one of: low, medium, high, critical`);
113
+ }
114
+ }
115
+ }
116
+
117
+ if (policy.fail_on && !VALID_SEVERITIES.has(policy.fail_on)) {
118
+ throw new Error(`Invalid fail_on "${policy.fail_on}" — must be one of: none, low, medium, high, critical`);
119
+ }
120
+
121
+ if (policy.suppress) {
122
+ if (!Array.isArray(policy.suppress)) {
123
+ throw new Error('suppress must be an array');
124
+ }
125
+ for (const rule of policy.suppress) {
126
+ if (!rule.atk_id) {
127
+ throw new Error('Each suppress rule must have an atk_id');
128
+ }
129
+ }
130
+ }
131
+
132
+ if (policy.allow) {
133
+ if (policy.allow.packages && !Array.isArray(policy.allow.packages)) {
134
+ throw new Error('allow.packages must be an array');
135
+ }
136
+ }
137
+
138
+ return sanitizePolicy(policy);
139
+ }
140
+
141
+ function sanitizePolicy(policy) {
142
+ return {
143
+ allow: { packages: policy.allow?.packages ?? [] },
144
+ severity_overrides: policy.severity_overrides ?? {},
145
+ fail_on: policy.fail_on ?? 'none',
146
+ suppress: (policy.suppress ?? []).map(r => ({
147
+ atk_id: r.atk_id,
148
+ package: r.package || '*',
149
+ reason: r.reason || '',
150
+ context: r.context || null,
151
+ reputation_tier: r.reputation_tier || null,
152
+ })),
153
+ };
154
+ }
155
+
156
+ function isAllowed(packageName, policy) {
157
+ if (!policy.allow.packages.length) return false;
158
+ const nameOnly = packageName.split('@')[0];
159
+ return policy.allow.packages.some(p => p === packageName || p === nameOnly);
160
+ }
161
+
162
+ function applyPolicy(findings, packageName, policy) {
163
+ let filtered = [...findings];
164
+
165
+ if (policy.suppress.length) {
166
+ filtered = filtered.filter(f => {
167
+ if (f.context?.is_lifecycle_hook) return true;
168
+ if (f.context?.is_multi_layer) return true;
169
+ return !policy.suppress.some(r => matchesSuppressRule(f, packageName, r));
170
+ });
171
+ }
172
+
173
+ filtered = filtered.map(f => {
174
+ const override = policy.severity_overrides[f.atk_id || f.id];
175
+ if (override) {
176
+ return { ...f, severity: override, _severityOverridden: true };
177
+ }
178
+ return f;
179
+ });
180
+
181
+ const blocked = checkFailOn(filtered, policy);
182
+
183
+ return { findings: filtered, blocked };
184
+ }
185
+
186
+ function checkFailOn(findings, policy) {
187
+ if (policy.fail_on === 'none') return false;
188
+
189
+ const threshold = severityIndex(policy.fail_on);
190
+ return findings.some(f => severityIndex(f.severity) >= threshold);
191
+ }
192
+
193
+ export { loadPolicy, applyPolicy, isAllowed, getPackageReputationTier, matchesContext, KNOWN_REPUTABLE_PACKAGES };