@lateos/npm-scan 0.15.4 → 0.15.6

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.
@@ -0,0 +1,145 @@
1
+ const MARKETPLACE_API = 'https://marketplace.visualstudio.com/_apis/public/gallery';
2
+ const OPENVSX_API = 'https://open-vsx.org/api';
3
+
4
+ const _cache = new Map();
5
+ const CACHE_TTL = 5 * 60 * 1000;
6
+ const RATE_LIMIT_MS = 6000;
7
+ let _lastFetchTime = 0;
8
+
9
+ function sleep(ms) {
10
+ return new Promise(r => setTimeout(r, ms));
11
+ }
12
+
13
+ async function rateLimitedFetch(url) {
14
+ const now = Date.now();
15
+ const elapsed = now - _lastFetchTime;
16
+ if (elapsed < RATE_LIMIT_MS) {
17
+ await sleep(RATE_LIMIT_MS - elapsed);
18
+ }
19
+ _lastFetchTime = Date.now();
20
+
21
+ const cached = _cache.get(url);
22
+ if (cached && Date.now() - cached.fetchedAt < CACHE_TTL) {
23
+ return cached.data;
24
+ }
25
+
26
+ let res;
27
+ try {
28
+ res = await fetch(url);
29
+ if (res.status === 429) {
30
+ const retryAfter = parseInt(res.headers.get('Retry-After') || '10', 10);
31
+ await sleep(retryAfter * 1000);
32
+ res = await fetch(url);
33
+ }
34
+ if (!res.ok) {
35
+ console.debug(`Marketplace API warning: ${url} returned ${res.status}`);
36
+ return null;
37
+ }
38
+ const data = await res.json();
39
+ _cache.set(url, { data, fetchedAt: Date.now() });
40
+ return data;
41
+ } catch (err) {
42
+ console.debug(`Marketplace API error: ${err.message}`);
43
+ return null;
44
+ }
45
+ }
46
+
47
+ function parseExtensionId(id) {
48
+ const parts = id.split('.');
49
+ if (parts.length < 2) throw new Error(`Invalid extension ID: ${id}`);
50
+ return { publisherId: parts[0], extensionName: parts.slice(1).join('.') };
51
+ }
52
+
53
+ export async function getExtensionMetadata(publisherId, extensionName) {
54
+ const url = `${MARKETPLACE_API}/extensionquery`;
55
+ const body = {
56
+ filters: [{
57
+ criteria: [
58
+ { filterType: 8, value: `${publisherId}.${extensionName}` },
59
+ ],
60
+ }],
61
+ flags: 914,
62
+ };
63
+
64
+ const cached = _cache.get(url + JSON.stringify(body));
65
+ if (cached && Date.now() - cached.fetchedAt < CACHE_TTL) {
66
+ return cached.data;
67
+ }
68
+
69
+ const now = Date.now();
70
+ const elapsed = now - _lastFetchTime;
71
+ if (elapsed < RATE_LIMIT_MS) {
72
+ await sleep(RATE_LIMIT_MS - elapsed);
73
+ }
74
+ _lastFetchTime = Date.now();
75
+
76
+ let res;
77
+ try {
78
+ res = await fetch(url, {
79
+ method: 'POST',
80
+ headers: { 'Content-Type': 'application/json', 'Accept': 'application/json;api-version=3.0-preview.1' },
81
+ body: JSON.stringify(body),
82
+ });
83
+ if (res.status === 429) {
84
+ const retryAfter = parseInt(res.headers.get('Retry-After') || '10', 10);
85
+ await sleep(retryAfter * 1000);
86
+ res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json;api-version=3.0-preview.1' }, body: JSON.stringify(body) });
87
+ }
88
+ if (!res.ok) {
89
+ console.debug(`Marketplace API warning: ${url} returned ${res.status}`);
90
+ return null;
91
+ }
92
+ const data = await res.json();
93
+ _cache.set(url + JSON.stringify(body), { data, fetchedAt: Date.now() });
94
+ return data;
95
+ } catch (err) {
96
+ console.debug(`Marketplace API error: ${err.message}`);
97
+ return null;
98
+ }
99
+ }
100
+
101
+ export async function getVersionHistory(publisherId, extensionName) {
102
+ const data = await getExtensionMetadata(publisherId, extensionName);
103
+ if (!data?.results?.[0]?.extensions?.[0]) return [];
104
+
105
+ const extension = data.results[0].extensions[0];
106
+ const versions = extension.versions || [];
107
+
108
+ return versions.map(v => ({
109
+ version: v.version,
110
+ publishedAt: v.lastUpdated || v.publishedDate,
111
+ publishedBy: extension.publisher?.publisherName || publisherId,
112
+ assetSha256: v.assetUri ? null : null,
113
+ flags: v.flags ? [String(v.flags)] : [],
114
+ }));
115
+ }
116
+
117
+ export async function getPublisherProfile(publisherId) {
118
+ const url = `${MARKETPLACE_API}/publishers/${publisherId}`;
119
+ return rateLimitedFetch(url);
120
+ }
121
+
122
+ export async function getOpenVsxMetadata(namespace, name) {
123
+ const url = `${OPENVSX_API}/${namespace}/${name}`;
124
+ return rateLimitedFetch(url);
125
+ }
126
+
127
+ export async function getOpenVsxVersionHistory(namespace, name) {
128
+ const data = await getOpenVsxMetadata(namespace, name);
129
+ if (!data) return [];
130
+ const versions = data.allVersions || {};
131
+ const files = data.files || {};
132
+
133
+ return Object.entries(versions).map(([version, publishedAt]) => ({
134
+ version,
135
+ publishedAt: typeof publishedAt === 'string' ? publishedAt : data.timestamp,
136
+ publishedBy: data.namespace || namespace,
137
+ assetSha256: files?.[version]?.sha256 || null,
138
+ flags: [],
139
+ }));
140
+ }
141
+
142
+ export function clearMarketplaceCache() {
143
+ _cache.clear();
144
+ _lastFetchTime = 0;
145
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "lastUpdated": "2026-05-25",
3
+ "schema": "vsix-ioc-v1",
4
+ "iocs": [
5
+ {
6
+ "type": "extensionId",
7
+ "value": "nrwl.angular-console",
8
+ "maliciousVersions": ["18.95.0"],
9
+ "wave": "nx-console-wave3",
10
+ "cve": "CVE-2026-48027",
11
+ "exposureWindowStart": "2026-05-18T12:30:00Z",
12
+ "exposureWindowEnd": "2026-05-18T13:09:00Z",
13
+ "registries": ["marketplace", "open-vsx"],
14
+ "safeVersion": ">=18.100.0",
15
+ "source": "https://nx.dev/blog/nx-console-v18-95-0-postmortem"
16
+ },
17
+ {
18
+ "type": "publisherAccount",
19
+ "value": "nrwl",
20
+ "compromiseWindowStart": "2026-05-11T00:00:00Z",
21
+ "compromiseWindowEnd": "2026-05-18T13:09:00Z",
22
+ "note": "Contributor token stolen via TanStack wave1 on May 11; 7-day dwell before publish"
23
+ },
24
+ {
25
+ "type": "orphanCommitHash",
26
+ "value": "PLACEHOLDER_UPDATE_FROM_THREAT_INTEL",
27
+ "repo": "nrwl/nx",
28
+ "note": "Dangling commit hosting 498KB Bun payload — update hash from StepSecurity IOC report"
29
+ }
30
+ ]
31
+ }
package/cli/cli.js CHANGED
@@ -38,6 +38,7 @@ program
38
38
  .option('--cache-dir <path>', 'Cache directory for offline/air-gapped scans')
39
39
  .option('--cache-ttl <seconds>', 'Cache TTL in seconds (default: 604800 = 7 days)', '604800')
40
40
  .option('--cache-size <bytes>', 'Max cache size in bytes (default: 1GB)', '1000000000')
41
+ .option('--vsix <extensionId>', 'Scan a VS Code extension (e.g. nrwl.angular-console)')
41
42
  .action(async (target, options) => {
42
43
  try {
43
44
  if (options.fips) {
@@ -50,11 +51,21 @@ program
50
51
  cacheMaxSize: parseInt(options.cacheSize || '1000000000')
51
52
  };
52
53
 
53
- if (!target && !options.file) {
54
- console.error('Error: specify a package name or --file <path>');
54
+ if (!target && !options.file && !options.vsix) {
55
+ console.error('Error: specify a package name, --file <path>, or --vsix <extensionId>');
55
56
  process.exit(1);
56
57
  }
57
58
 
59
+ if (options.vsix && !target && !options.file) {
60
+ const { vsixScan } = await import('../backend/vsix-scan/index.js');
61
+ const vsixFindings = await vsixScan(options.vsix);
62
+ const { saveScan } = await import('../backend/db.js');
63
+ const scanId = await saveScan(options.vsix, 'latest', vsixFindings);
64
+ const vsixOutput = JSON.stringify({ scanId, findings: vsixFindings, blocked: false, riskScore: 0, vsix: true }, null, 2);
65
+ console.log(vsixOutput);
66
+ return;
67
+ }
68
+
58
69
  const policy = options.policy
59
70
  ? await import('../backend/policy.js').then(m => m.loadPolicy(options.policy))
60
71
  : null;
@@ -72,10 +83,16 @@ program
72
83
  : await import('../backend/fetch.js').then(m => m.fetchPackage(target, fetchOptions));
73
84
  const pkgName = target || pkgJson.name || 'unknown';
74
85
  const findings = await import('../backend/detectors/index.js').then(m => m.runAll(pkgJson, jsFiles, meta, allFiles));
86
+ let vsixFindings = [];
87
+ if (options.vsix) {
88
+ const { vsixScan } = await import('../backend/vsix-scan/index.js');
89
+ vsixFindings = await vsixScan(options.vsix);
90
+ }
91
+ const allFindings = [...findings, ...vsixFindings];
75
92
  const { saveScan } = await import('../backend/db.js');
76
- const scanId = await saveScan(pkgName, 'latest', findings);
93
+ const scanId = await saveScan(pkgName, 'latest', allFindings);
77
94
 
78
- let outputFindings = findings;
95
+ let outputFindings = allFindings;
79
96
  let blocked = false;
80
97
 
81
98
  if (policy) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lateos/npm-scan",
3
- "version": "0.15.4",
3
+ "version": "0.15.6",
4
4
  "description": "Modern npm supply chain security scanner — detects obfuscated payloads, credential stealers, conditional triggers, sandbox evasion, and worm-like propagation. 11 attack types, SBOM, NIST/EU CRA compliance reporting.",
5
5
  "main": "backend/index.js",
6
6
  "bin": {