Skip to content

Commit 9830059

Browse files
fix(engine): downloads refuse hosts that resolve to private addresses (#6571)
* fix(engine): downloads refuse hosts that resolve to private addresses * fix(core): shorten the env proxy doc comment * test(producer): remote-media tests stub the download fetch seam
1 parent 3ca1005 commit 9830059

22 files changed

Lines changed: 349 additions & 183 deletions

‎.fallowrc.jsonc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@
437437
// as a direct dep to guarantee installation even when transitive
438438
// resolution fails (corrupted cache, dedup edge cases).
439439
"debug",
440+
// The engine loads it at runtime; tsup keeps it external in the CLI bundle.
441+
"undici",
440442
// @puppeteer/browsers' optional peer: its zip fallback when no system `unzip` exists.
441443
"yauzl",
442444
// Loaded through the optional package loader for Gemini vision captioning.

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@ jobs:
841841
- name: Install dependencies
842842
if: runner.os == 'Windows'
843843
run: bun install --frozen-lockfile --ignore-scripts --linker=hoisted
844+
- run: bun run --filter '@hyperframes/{parsers,lint,studio-server}' build
845+
- run: bun run --cwd packages/core build
844846
- run: bun run --cwd packages/cli test src/utils/npxCommand.test.ts src/commands/skills.test.ts
845847

846848
sdk-tests:

‎bun.lock‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/cli/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"open": "^10.0.0",
7171
"postcss": "^8.5.8",
7272
"puppeteer-core": "^25.10.0",
73+
"undici": "7.25.0",
7374
"yauzl": "^3.4.0"
7475
},
7576
"devDependencies": {

‎packages/cli/src/utils/hostAnswers.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { promises as dns } from "node:dns";
2+
import { fetchGoesThroughEnvProxy } from "@hyperframes/core/env-proxy";
23

34
const PROBE_TIMEOUT_MS = 1000;
45

5-
function fetchGoesThroughEnvProxy(): boolean {
6-
if (!(process.env["HTTPS_PROXY"] ?? process.env["https_proxy"])?.trim()) return false;
7-
const flags = [...process.execArgv, ...(process.env["NODE_OPTIONS"]?.split(/\s+/u) ?? [])];
8-
return process.env["NODE_USE_ENV_PROXY"] === "1" || flags.includes("--use-env-proxy");
9-
}
10-
116
/**
127
* Whether DNS answers for `host` via c-ares, one short try per nameserver. The system lookup
138
* `fetch` makes cannot be aborted and holds even `process.exit`, so background requests ask this first.

‎packages/cli/src/utils/publishProject.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { envProxyEnabled } from "@hyperframes/core/env-proxy";
12
import { basename, dirname, join, posix, relative, resolve } from "node:path";
23
import {
34
closeSync,
@@ -235,11 +236,7 @@ function proxySupportHint(): string {
235236
const proxyConfigured = ["HTTPS_PROXY", "HTTP_PROXY", "https_proxy", "http_proxy"].some((key) =>
236237
Boolean(process.env[key]?.trim()),
237238
);
238-
const proxyEnabled =
239-
process.env["NODE_USE_ENV_PROXY"] === "1" ||
240-
process.execArgv.includes("--use-env-proxy") ||
241-
process.env["NODE_OPTIONS"]?.split(/\s+/u).includes("--use-env-proxy") === true;
242-
if (!proxyConfigured || proxyEnabled) return "";
239+
if (!proxyConfigured || envProxyEnabled()) return "";
243240
return (
244241
". Proxy variables are set but ignored by Node fetch; if this network requires them, retry with " +
245242
"NODE_USE_ENV_PROXY=1 (Node 22.21+)"

‎packages/cli/tsup.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var __dirname = __hf_dirname(__filename);`,
4444
},
4545
external: [
4646
"puppeteer-core",
47+
"undici",
4748
"puppeteer",
4849
"@puppeteer/browsers",
4950
// Native module — its platform binary (@img/sharp-<os>-<arch>) must be

‎packages/core/package-subpaths.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
"types": "./dist/removeTree.d.ts",
7575
"environments": ["bun", "node"]
7676
},
77+
"./env-proxy": {
78+
"source": "./src/envProxy.ts",
79+
"runtime": "./dist/envProxy.js",
80+
"types": "./dist/envProxy.d.ts",
81+
"environments": ["bun", "node"]
82+
},
7783
"./rename-retry": {
7884
"source": "./src/renameWithRetry.ts",
7985
"runtime": "./dist/renameWithRetry.js",

‎packages/core/package.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
"import": "./src/removeTree.ts",
8787
"types": "./src/removeTree.ts"
8888
},
89+
"./env-proxy": {
90+
"bun": "./src/envProxy.ts",
91+
"node": "./dist/envProxy.js",
92+
"import": "./src/envProxy.ts",
93+
"types": "./src/envProxy.ts"
94+
},
8995
"./rename-retry": {
9096
"bun": "./src/renameWithRetry.ts",
9197
"node": "./dist/renameWithRetry.js",
@@ -660,6 +666,10 @@
660666
"import": "./dist/removeTree.js",
661667
"types": "./dist/removeTree.d.ts"
662668
},
669+
"./env-proxy": {
670+
"import": "./dist/envProxy.js",
671+
"types": "./dist/envProxy.d.ts"
672+
},
663673
"./rename-retry": {
664674
"import": "./dist/renameWithRetry.js",
665675
"types": "./dist/renameWithRetry.d.ts"

‎packages/core/src/envProxy.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, it } from "vitest";
2+
import { envProxyEnabled, fetchGoesThroughEnvProxy } from "./envProxy.js";
3+
4+
describe("env proxy", () => {
5+
it("needs a proxy variable and Node started with env-proxy support", () => {
6+
const proxy = { HTTPS_PROXY: "http://proxy.test:3128" };
7+
expect(fetchGoesThroughEnvProxy({ ...proxy, NODE_USE_ENV_PROXY: "1" }, [])).toBe(true);
8+
expect(fetchGoesThroughEnvProxy(proxy, ["--use-env-proxy"])).toBe(true);
9+
expect(
10+
fetchGoesThroughEnvProxy({ ...proxy, NODE_OPTIONS: "--no-warnings --use-env-proxy" }, []),
11+
).toBe(true);
12+
expect(
13+
fetchGoesThroughEnvProxy({ https_proxy: " http://proxy.test ", NODE_USE_ENV_PROXY: "1" }, []),
14+
).toBe(true);
15+
expect(fetchGoesThroughEnvProxy(proxy, [])).toBe(false);
16+
expect(fetchGoesThroughEnvProxy({ NODE_USE_ENV_PROXY: "1" }, [])).toBe(false);
17+
expect(fetchGoesThroughEnvProxy({ HTTPS_PROXY: " ", NODE_USE_ENV_PROXY: "1" }, [])).toBe(false);
18+
});
19+
20+
it("reports env-proxy support separately from the variables", () => {
21+
expect(envProxyEnabled({ NODE_USE_ENV_PROXY: "1" }, [])).toBe(true);
22+
expect(envProxyEnabled({}, [])).toBe(false);
23+
});
24+
});

0 commit comments

Comments
 (0)