0sec-cli 0.15.0 → 0.18.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.
Files changed (209) hide show
  1. package/0sec.js +327 -0
  2. package/README.md +68 -48
  3. package/attacks/data-exfiltration/pii-leakage.yaml +27 -0
  4. package/attacks/encoding-bypass/base64-encoding.yaml +24 -0
  5. package/attacks/jailbreak/dan-roleplay.yaml +27 -0
  6. package/attacks/jailbreak/hypothetical-scenario.yaml +25 -0
  7. package/attacks/jailbreak/multilingual-bypass.yaml +22 -0
  8. package/attacks/output-manipulation/harmful-content.yaml +25 -0
  9. package/attacks/prompt-injection/context-manipulation.yaml +32 -0
  10. package/attacks/prompt-injection/direct-injection.yaml +28 -0
  11. package/attacks/prompt-injection/indirect-injection.yaml +33 -0
  12. package/attacks/system-prompt-extraction/direct-ask.yaml +30 -0
  13. package/attacks/system-prompt-extraction/markdown-exfil.yaml +26 -0
  14. package/attacks/tool-misuse/ssrf-via-tools.yaml +27 -0
  15. package/chunks/adapt-loop-SMH6V4PD.js +18 -0
  16. package/chunks/adgraph-JLGA6RYI.js +54 -0
  17. package/chunks/agent/skills/frameworks/entra-id.yaml +63 -0
  18. package/chunks/agent/skills/frameworks/graphql-introspection.yaml +116 -0
  19. package/chunks/agent/skills/frameworks/nextjs.yaml +82 -0
  20. package/chunks/agent/skills/frameworks/python-web.yaml +85 -0
  21. package/chunks/agent/skills/frameworks/supabase.yaml +83 -0
  22. package/chunks/agent/skills/frameworks/wordpress-deep.yaml +122 -0
  23. package/chunks/agent/skills/techniques/ad-attack-paths.yaml +57 -0
  24. package/chunks/agent/skills/techniques/advisory-disclosure.yaml +59 -0
  25. package/chunks/agent/skills/techniques/assumption-mining.yaml +53 -0
  26. package/chunks/agent/skills/techniques/blind-exploitation.yaml +143 -0
  27. package/chunks/agent/skills/techniques/crypto-misuse.yaml +88 -0
  28. package/chunks/agent/skills/techniques/cve-poc-adaptation.yaml +82 -0
  29. package/chunks/agent/skills/techniques/entra-attack-paths.yaml +55 -0
  30. package/chunks/agent/skills/techniques/http-conformance-diff.yaml +48 -0
  31. package/chunks/agent/skills/techniques/jwt-attacks.yaml +137 -0
  32. package/chunks/agent/skills/techniques/kernel-weaponization.yaml +53 -0
  33. package/chunks/agent/skills/techniques/llm-excessive-agency.yaml +55 -0
  34. package/chunks/agent/skills/techniques/llm-insecure-output-handling.yaml +56 -0
  35. package/chunks/agent/skills/techniques/llm-prompt-injection.yaml +54 -0
  36. package/chunks/agent/skills/techniques/llm-prompt-layer-write.yaml +68 -0
  37. package/chunks/agent/skills/techniques/llm-rag-poisoning.yaml +57 -0
  38. package/chunks/agent/skills/techniques/llm-safety-eval.yaml +51 -0
  39. package/chunks/agent/skills/techniques/npm-ecosystem.yaml +51 -0
  40. package/chunks/agent/skills/techniques/poc-verification.yaml +55 -0
  41. package/chunks/agent/skills/techniques/race-condition.yaml +122 -0
  42. package/chunks/agent/skills/techniques/scoped-fix.yaml +49 -0
  43. package/chunks/agent/skills/techniques/seedless-depth-review.yaml +59 -0
  44. package/chunks/agent/skills/techniques/spec-differential.yaml +48 -0
  45. package/chunks/agent/skills/techniques/variant-hunting.yaml +55 -0
  46. package/chunks/agent/skills/vulnerabilities/cardano-eutxo-validators.yaml +72 -0
  47. package/chunks/agent/skills/vulnerabilities/command-injection.yaml +99 -0
  48. package/chunks/agent/skills/vulnerabilities/deserialization-chains.yaml +106 -0
  49. package/chunks/agent/skills/vulnerabilities/native-memory-safety.yaml +93 -0
  50. package/chunks/agent/skills/vulnerabilities/path-traversal.yaml +78 -0
  51. package/chunks/agent/skills/vulnerabilities/prototype-pollution.yaml +132 -0
  52. package/chunks/agent/skills/vulnerabilities/request-smuggling.yaml +129 -0
  53. package/chunks/agent/skills/vulnerabilities/sqli-advanced.yaml +102 -0
  54. package/chunks/agent/skills/vulnerabilities/ssrf-bypass.yaml +84 -0
  55. package/chunks/agent/skills/vulnerabilities/ssti-exploitation.yaml +112 -0
  56. package/chunks/agent/skills/vulnerabilities/structural-sqli.yaml +91 -0
  57. package/chunks/appsec-catalog-CBWHGTEL.js +24 -0
  58. package/chunks/artifact-scraper-HQ7HLP6V.js +34 -0
  59. package/chunks/assumption-mining-5SNIVVDN.js +79 -0
  60. package/chunks/chunk-242TMK6G.js +110 -0
  61. package/chunks/chunk-2JCCA2JL.js +381 -0
  62. package/chunks/chunk-2RMLOJVB.js +47 -0
  63. package/chunks/chunk-3KPWWJCI.js +1422 -0
  64. package/chunks/chunk-3MOLBTLS.js +953 -0
  65. package/chunks/chunk-53G27VPS.js +136 -0
  66. package/chunks/chunk-57ZENEX2.js +169 -0
  67. package/chunks/chunk-5G3ZXFBW.js +182 -0
  68. package/chunks/chunk-5JI7L7KV.js +74240 -0
  69. package/chunks/chunk-6L26OBWI.js +1094 -0
  70. package/chunks/chunk-6LKRLK2R.js +542 -0
  71. package/chunks/chunk-72CISA2D.js +2597 -0
  72. package/chunks/chunk-7DQEV5QI.js +287 -0
  73. package/chunks/chunk-AD7WXDH6.js +3250 -0
  74. package/chunks/chunk-ADOLI6DT.js +102 -0
  75. package/chunks/chunk-AHTBZC3E.js +596 -0
  76. package/chunks/chunk-ASUR522M.js +518 -0
  77. package/chunks/chunk-ATATQACO.js +471 -0
  78. package/chunks/chunk-BATRQBOR.js +1732 -0
  79. package/chunks/chunk-BFR2CDV5.js +5735 -0
  80. package/chunks/chunk-BFRB6HB2.js +235 -0
  81. package/chunks/chunk-BKZFDZ23.js +361 -0
  82. package/chunks/chunk-BVAZO4WA.js +193 -0
  83. package/chunks/chunk-BZNEY2ZS.js +33225 -0
  84. package/chunks/chunk-C2WXWFBB.js +1070 -0
  85. package/chunks/chunk-CMKXP5RR.js +917 -0
  86. package/chunks/chunk-DW5UWPFY.js +275 -0
  87. package/chunks/chunk-F3WBKITT.js +687 -0
  88. package/chunks/chunk-GMT2AZKM.js +2439 -0
  89. package/chunks/chunk-H2FFLZNK.js +3 -0
  90. package/chunks/chunk-IOL7D5YV.js +515 -0
  91. package/chunks/chunk-IR537GON.js +49 -0
  92. package/chunks/chunk-JQHOLLTD.js +3729 -0
  93. package/chunks/chunk-KLTNTE2Z.js +121 -0
  94. package/chunks/chunk-LP3HHYQU.js +245 -0
  95. package/chunks/chunk-MYVT64FN.js +16 -0
  96. package/chunks/chunk-N7BOUYEV.js +852 -0
  97. package/chunks/chunk-OEFNRYI2.js +150 -0
  98. package/chunks/chunk-P6WKNFWX.js +1968 -0
  99. package/chunks/chunk-QI233I24.js +333 -0
  100. package/chunks/chunk-RJWOYEOG.js +271 -0
  101. package/chunks/chunk-RRMJC3ZE.js +105 -0
  102. package/chunks/chunk-RWONANDA.js +973 -0
  103. package/chunks/chunk-SAFFWQW4.js +5921 -0
  104. package/chunks/chunk-SF4KZ4O3.js +502 -0
  105. package/chunks/chunk-SVJEDVYK.js +808 -0
  106. package/chunks/chunk-TSK2AG6J.js +5108 -0
  107. package/chunks/chunk-U5FLXGHT.js +2010 -0
  108. package/chunks/chunk-UCYRA73C.js +662 -0
  109. package/chunks/chunk-UR4ELX2Y.js +4784 -0
  110. package/chunks/chunk-VQG4FT5D.js +685 -0
  111. package/chunks/chunk-WEBMRWEG.js +9337 -0
  112. package/chunks/chunk-WU6AFRAZ.js +1167 -0
  113. package/chunks/chunk-WVTBZEQO.js +1531 -0
  114. package/chunks/chunk-WXQ6BJ6A.js +596 -0
  115. package/chunks/chunk-XM5NLHYU.js +600 -0
  116. package/chunks/chunk-YLMN3N25.js +4054 -0
  117. package/chunks/chunk-YYRBQVFE.js +2572 -0
  118. package/chunks/chunk-Z5FA2XOX.js +2798 -0
  119. package/chunks/commands-TBC2F5CE.js +16999 -0
  120. package/chunks/corpus-v1.json +403 -0
  121. package/chunks/cost-ledger-NU63MYZM.js +13 -0
  122. package/chunks/data/appsec-archetypes.json +102 -0
  123. package/chunks/data/chromium-archetypes.json +204 -0
  124. package/chunks/data/freebsd-archetypes.json +171 -0
  125. package/chunks/data/kernel-archetypes.json +611 -0
  126. package/chunks/db-KFWOAUUB.js +16 -0
  127. package/chunks/disclose-EKTWSCGW.js +132 -0
  128. package/chunks/dist-4MAW5X6L.js +74 -0
  129. package/chunks/dist-4YICS2J2.js +2776 -0
  130. package/chunks/dist-FMGSR3DW.js +159 -0
  131. package/chunks/eval-runner-7ZF472KV.js +27 -0
  132. package/chunks/example-manifest.json +95 -0
  133. package/chunks/exploit-agent-45YQOHPJ.js +98 -0
  134. package/chunks/exploit-autoclimb-UZGEMGYT.js +81 -0
  135. package/chunks/exploit-climb-SG23KB2G.js +358 -0
  136. package/chunks/fix-IG7LYXH3.js +12 -0
  137. package/chunks/github-issues-MJ6OYOOU.js +157 -0
  138. package/chunks/harness-7ODOLOWU.js +22 -0
  139. package/chunks/http-conformance-DU66MZIU.js +11 -0
  140. package/chunks/http-sender-GWH2IYEA.js +10 -0
  141. package/chunks/hunt-scan-MMKUOETU.js +38 -0
  142. package/chunks/identity-6ZAIIWOR.js +191 -0
  143. package/chunks/kernel-primitive-7U6CWHXD.js +44 -0
  144. package/chunks/kernel-vm-runner-3JAU4O6J.js +62 -0
  145. package/chunks/memsafety-scan-J7SECV5W.js +16 -0
  146. package/chunks/native-loop-RJCJPOUS.js +54 -0
  147. package/chunks/npm-detectors-KB5Y5ZFX.js +69 -0
  148. package/chunks/npm-dynamic-discovery-AHROOZDB.js +13 -0
  149. package/chunks/orchestrate-OC2VZN2X.js +62 -0
  150. package/chunks/pipeline-BZK5BLJR.js +14 -0
  151. package/chunks/pre-recon-cve-66EB6G4M.js +351 -0
  152. package/chunks/prepare-MYY743TK.js +13 -0
  153. package/chunks/process-LQRCS5OY.js +13 -0
  154. package/chunks/replay-runner-45G3VU7X.js +39 -0
  155. package/chunks/run-D56MPDKY.js +32716 -0
  156. package/chunks/runtime-G7YWIO3B.js +43 -0
  157. package/chunks/runtime-J7PLXZNM.js +12 -0
  158. package/chunks/scan-stream-FHI2FYZE.js +96 -0
  159. package/chunks/scope-BI7BF4ZY.js +18 -0
  160. package/chunks/session-store-GZ4A4KYT.js +28 -0
  161. package/chunks/source-files-PWRQR6LY.js +12 -0
  162. package/chunks/specdrift-WCLH6TTQ.js +19 -0
  163. package/chunks/variant-candidates-YERCYMPD.js +13 -0
  164. package/chunks/web-recon-prepass-JJGPEOLE.js +1148 -0
  165. package/dashboard/assets/0sec-icon-66SreztZ.gif +0 -0
  166. package/dashboard/assets/bot-yILPnRgD.js +1 -0
  167. package/dashboard/assets/chevron-down-BeDJ-Vka.js +1 -0
  168. package/dashboard/assets/circle-alert-BEnMBMT-.js +1 -0
  169. package/dashboard/assets/client-DRYsuOGl.js +9 -0
  170. package/dashboard/assets/copy-Bi5vzoF9.js +1 -0
  171. package/dashboard/assets/desktop-CXTQonNm.js +32 -0
  172. package/dashboard/assets/desktop-NOekk4QS.css +1 -0
  173. package/dashboard/assets/dist-CmX-h7a4.js +1 -0
  174. package/dashboard/assets/dist-DAwYQmf_.js +45 -0
  175. package/dashboard/assets/findings-page-CACW9nw2.js +5 -0
  176. package/dashboard/assets/format-PoISqsES.js +1 -0
  177. package/dashboard/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  178. package/dashboard/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  179. package/dashboard/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  180. package/dashboard/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  181. package/dashboard/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  182. package/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  183. package/dashboard/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  184. package/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  185. package/dashboard/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  186. package/dashboard/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  187. package/dashboard/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  188. package/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  189. package/dashboard/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  190. package/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  191. package/dashboard/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  192. package/dashboard/assets/jsx-runtime-C7oxC63R.js +1 -0
  193. package/dashboard/assets/live-page-DrgQqQK5.js +1 -0
  194. package/dashboard/assets/meta-tile-CcskIV_o.js +1 -0
  195. package/dashboard/assets/operations-BKE8T-vY.css +2 -0
  196. package/dashboard/assets/operations-D8nUP5_m.js +4 -0
  197. package/dashboard/assets/operations-app-CQQhG54n.js +2 -0
  198. package/dashboard/assets/overview-page-DTGS8dPo.js +1 -0
  199. package/dashboard/assets/page-header-MFVvEtZW.js +1 -0
  200. package/dashboard/assets/play-Dwo-9xt6.js +1 -0
  201. package/dashboard/assets/scans-page-ChVtq8Us.js +1 -0
  202. package/dashboard/assets/search-CiooTLck.js +1 -0
  203. package/dashboard/assets/siren-CCBwTSuk.js +1 -0
  204. package/dashboard/assets/table-BYS-nIVA.js +1 -0
  205. package/dashboard/assets/tabs-DivxbhQy.js +1 -0
  206. package/dashboard/desktop.html +21 -0
  207. package/dashboard/index.html +15 -0
  208. package/package.json +30 -18
  209. package/bin/0sec.cjs +0 -361
@@ -0,0 +1,287 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __0secCreateRequire } from "node:module";
3
+ const require = __0secCreateRequire(import.meta.url);
4
+ import {
5
+ allowlistedChildEnv
6
+ } from "./chunk-KLTNTE2Z.js";
7
+
8
+ // packages/core/dist/stages/npm-detectors/osv-lookup.js
9
+ var DEFAULT_ENDPOINT = "https://api.osv.dev/v1/querybatch";
10
+ var DEFAULT_TIMEOUT_MS = 8e3;
11
+ var DEFAULT_RETRIES = 1;
12
+ var RETRY_BACKOFF_MS = 400;
13
+ var OsvLookupError = class extends Error {
14
+ cause;
15
+ constructor(message, cause) {
16
+ super(message);
17
+ this.cause = cause;
18
+ this.name = "OsvLookupError";
19
+ }
20
+ };
21
+ function deriveForkSiblings(name) {
22
+ const out = /* @__PURE__ */ new Set();
23
+ const dotted = /^([a-z0-9][a-z0-9-]*)\.[a-z0-9.-]+$/.exec(name);
24
+ if (dotted)
25
+ out.add(dotted[1]);
26
+ const scoped = /^@([a-z0-9][a-z0-9-]*)\/([a-z0-9][a-z0-9._-]*)$/.exec(name);
27
+ if (scoped && scoped[1] !== "types")
28
+ out.add(scoped[2]);
29
+ out.delete(name);
30
+ return [...out];
31
+ }
32
+ function createOsvAdvisoryLookup(options = {}) {
33
+ const endpoint = options.endpoint ?? DEFAULT_ENDPOINT;
34
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
35
+ const retries = options.retries ?? DEFAULT_RETRIES;
36
+ const deriveSiblings = options.deriveSiblings ?? deriveForkSiblings;
37
+ return async (name, version, _cwe) => {
38
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
39
+ if (typeof fetchImpl !== "function") {
40
+ throw new OsvLookupError("no fetch implementation available for OSV lookup");
41
+ }
42
+ const siblings = deriveSiblings(name).filter((s) => s && s !== name);
43
+ const queries = [
44
+ { package: { ecosystem: "npm", name }, ...version ? { version } : {} },
45
+ ...siblings.map((s) => ({ package: { ecosystem: "npm", name: s } }))
46
+ ];
47
+ const data = await postBatch(fetchImpl, endpoint, { queries }, timeoutMs, retries);
48
+ const results = data.results ?? [];
49
+ const advisories = [];
50
+ for (const v of results[0]?.vulns ?? []) {
51
+ if (v?.id)
52
+ advisories.push(v.id);
53
+ }
54
+ siblings.forEach((sib, i) => {
55
+ for (const v of results[i + 1]?.vulns ?? []) {
56
+ if (v?.id)
57
+ advisories.push(`sibling:${sib}:${v.id}`);
58
+ }
59
+ });
60
+ return [...new Set(advisories)];
61
+ };
62
+ }
63
+ async function postBatch(fetchImpl, endpoint, body, timeoutMs, retries) {
64
+ let lastErr;
65
+ for (let attempt = 0; attempt <= retries; attempt++) {
66
+ const controller = new AbortController();
67
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
68
+ try {
69
+ const res = await fetchImpl(endpoint, {
70
+ method: "POST",
71
+ headers: { "content-type": "application/json", accept: "application/json" },
72
+ body: JSON.stringify(body),
73
+ signal: controller.signal
74
+ });
75
+ if (res.status === 429 || res.status >= 500) {
76
+ lastErr = new OsvLookupError(`OSV transient status ${res.status}`);
77
+ if (attempt < retries) {
78
+ await delay(RETRY_BACKOFF_MS * (attempt + 1));
79
+ continue;
80
+ }
81
+ throw lastErr;
82
+ }
83
+ if (!res.ok) {
84
+ throw new OsvLookupError(`OSV lookup failed: HTTP ${res.status}`);
85
+ }
86
+ const json = await res.json();
87
+ if (!json || typeof json !== "object" || !("results" in json)) {
88
+ throw new OsvLookupError("OSV lookup returned a malformed response (no `results`)");
89
+ }
90
+ return json;
91
+ } catch (err) {
92
+ lastErr = err;
93
+ const transient = isAbortOrNetwork(err);
94
+ if (transient && attempt < retries) {
95
+ await delay(RETRY_BACKOFF_MS * (attempt + 1));
96
+ continue;
97
+ }
98
+ if (err instanceof OsvLookupError)
99
+ throw err;
100
+ throw new OsvLookupError(`OSV lookup errored: ${errMsg(err)}`, err);
101
+ } finally {
102
+ clearTimeout(timer);
103
+ }
104
+ }
105
+ throw new OsvLookupError(`OSV lookup exhausted retries: ${errMsg(lastErr)}`, lastErr);
106
+ }
107
+ function isAbortOrNetwork(err) {
108
+ if (err instanceof OsvLookupError)
109
+ return false;
110
+ const name = err?.name;
111
+ return name === "AbortError" || name === "TypeError" || err instanceof Error;
112
+ }
113
+ function delay(ms) {
114
+ return new Promise((resolve) => setTimeout(resolve, ms));
115
+ }
116
+ function errMsg(e) {
117
+ return e instanceof Error ? e.message.split("\n")[0].slice(0, 160) : String(e);
118
+ }
119
+
120
+ // packages/core/dist/stages/npm-detectors/probe.js
121
+ import { createRequire } from "node:module";
122
+ import { pathToFileURL } from "node:url";
123
+ function inProcessProbe(pkg, baseDir, note) {
124
+ const req = createRequire(pathToFileURL(baseDir.endsWith("/") ? baseDir : `${baseDir}/`).href);
125
+ return {
126
+ pkg,
127
+ baseDir,
128
+ load(moduleId) {
129
+ try {
130
+ return req(moduleId);
131
+ } catch {
132
+ return void 0;
133
+ }
134
+ },
135
+ note
136
+ };
137
+ }
138
+ function staticProbe(pkg, modules, note) {
139
+ return {
140
+ pkg,
141
+ baseDir: "/dev/null",
142
+ load(moduleId) {
143
+ return Object.prototype.hasOwnProperty.call(modules, moduleId) ? modules[moduleId] : void 0;
144
+ },
145
+ note
146
+ };
147
+ }
148
+
149
+ // packages/core/dist/stages/npm-detectors/sandbox-probe.js
150
+ import { execFile } from "node:child_process";
151
+ import { mkdtemp, rm } from "node:fs/promises";
152
+ import { tmpdir } from "node:os";
153
+ import { join } from "node:path";
154
+ import { fileURLToPath } from "node:url";
155
+ var DEFAULT_INSTALL_TIMEOUT_MS = 18e4;
156
+ var DEFAULT_RUN_TIMEOUT_MS = 12e4;
157
+ function defaultHarnessPath() {
158
+ return fileURLToPath(new URL("./sandbox-harness.js", import.meta.url));
159
+ }
160
+ function localSandboxProvider() {
161
+ return {
162
+ async create() {
163
+ const workdir = await mkdtemp(join(tmpdir(), "0sec-npm-dyn-"));
164
+ return {
165
+ workdir,
166
+ run(cmd, args, runOpts) {
167
+ return new Promise((resolve, reject) => {
168
+ execFile(cmd, args, {
169
+ cwd: runOpts?.cwd ?? workdir,
170
+ timeout: runOpts?.timeoutMs ?? DEFAULT_RUN_TIMEOUT_MS,
171
+ maxBuffer: 64 * 1024 * 1024,
172
+ // This child runs UNTRUSTED npm package code (install + harness
173
+ // exec). Inheriting process.env would hand every provider /
174
+ // cloud credential to attacker-authored package code via one
175
+ // `process.env` read. Build from the allowlist instead; a fresh
176
+ // npm install needs only PATH/HOME/TMPDIR, all carried there.
177
+ env: allowlistedChildEnv(runOpts?.env ?? {})
178
+ }, (err, stdout, stderr) => {
179
+ const anyErr = err;
180
+ if (anyErr && typeof anyErr.code !== "number") {
181
+ reject(anyErr);
182
+ return;
183
+ }
184
+ resolve({
185
+ stdout: stdout?.toString() ?? "",
186
+ stderr: stderr?.toString() ?? "",
187
+ exitCode: typeof anyErr?.code === "number" ? anyErr.code : 0
188
+ });
189
+ });
190
+ });
191
+ },
192
+ async dispose() {
193
+ await rm(workdir, { recursive: true, force: true });
194
+ }
195
+ };
196
+ }
197
+ };
198
+ }
199
+ function parseHarnessResult(stdout) {
200
+ const lines = stdout.split("\n").map((l) => l.trim()).filter(Boolean);
201
+ for (let i = lines.length - 1; i >= 0; i--) {
202
+ const line = lines[i];
203
+ if (!line.startsWith("{"))
204
+ continue;
205
+ try {
206
+ const parsed = JSON.parse(line);
207
+ if (parsed && Array.isArray(parsed.outcomes)) {
208
+ return { outcomes: parsed.outcomes, warnings: Array.isArray(parsed.warnings) ? parsed.warnings : [] };
209
+ }
210
+ } catch {
211
+ }
212
+ }
213
+ return void 0;
214
+ }
215
+ function createSandboxPackageRunner(options = {}) {
216
+ const provider = options.provider ?? localSandboxProvider();
217
+ const harnessPath = options.harnessPath ?? defaultHarnessPath();
218
+ const nodeBin = options.nodeBin ?? process.execPath;
219
+ const installTimeoutMs = options.installTimeoutMs ?? DEFAULT_INSTALL_TIMEOUT_MS;
220
+ const runTimeoutMs = options.runTimeoutMs ?? DEFAULT_RUN_TIMEOUT_MS;
221
+ const log = options.log ?? (() => {
222
+ });
223
+ return async function sandboxRunner(pkg, detectorIds) {
224
+ let session;
225
+ try {
226
+ session = await provider.create();
227
+ } catch (e) {
228
+ log(`SKIP ${pkg.name}: sandbox create failed: ${errMsg2(e)}`);
229
+ return void 0;
230
+ }
231
+ let result;
232
+ try {
233
+ const spec = pkg.version ? `${pkg.name}@${pkg.version}` : pkg.name;
234
+ const install = await session.run("npm", ["install", "--ignore-scripts", "--no-audit", "--no-fund", "--no-package-lock", "--prefix", session.workdir, spec], { cwd: session.workdir, timeoutMs: installTimeoutMs });
235
+ if (install.exitCode !== 0) {
236
+ log(`SKIP ${pkg.name}: npm install exited ${install.exitCode}: ${firstLine(install.stderr)}`);
237
+ return void 0;
238
+ }
239
+ const config = JSON.stringify({
240
+ installDir: session.workdir,
241
+ pkg,
242
+ detectorIds,
243
+ offlineDedup: options.offlineDedup ?? false
244
+ });
245
+ const harness = await session.run(nodeBin, [harnessPath, config], {
246
+ cwd: session.workdir,
247
+ timeoutMs: runTimeoutMs
248
+ });
249
+ if (harness.exitCode !== 0) {
250
+ log(`SKIP ${pkg.name}: harness exited ${harness.exitCode}: ${firstLine(harness.stderr)}`);
251
+ return void 0;
252
+ }
253
+ const parsed = parseHarnessResult(harness.stdout);
254
+ if (!parsed) {
255
+ log(`SKIP ${pkg.name}: harness produced no parseable result`);
256
+ return void 0;
257
+ }
258
+ result = parsed;
259
+ } catch (e) {
260
+ log(`SKIP ${pkg.name}: sandbox run threw: ${errMsg2(e)}`);
261
+ result = void 0;
262
+ } finally {
263
+ try {
264
+ await session.dispose();
265
+ } catch (e) {
266
+ log(`WARN ${pkg.name}: sandbox dispose failed: ${errMsg2(e)}`);
267
+ }
268
+ }
269
+ return result;
270
+ };
271
+ }
272
+ function errMsg2(e) {
273
+ return e instanceof Error ? e.message.split("\n")[0].slice(0, 200) : String(e);
274
+ }
275
+ function firstLine(s) {
276
+ return (s.split("\n").find(Boolean) ?? "").slice(0, 200);
277
+ }
278
+
279
+ export {
280
+ OsvLookupError,
281
+ deriveForkSiblings,
282
+ createOsvAdvisoryLookup,
283
+ inProcessProbe,
284
+ staticProbe,
285
+ localSandboxProvider,
286
+ createSandboxPackageRunner
287
+ };