@parcha/pi-browser 0.1.0-beta.70 → 0.1.0-beta.74
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/CHANGELOG.md +4 -0
- package/dist/core/public-fetch.d.ts +5 -4
- package/dist/core/public-fetch.js +21 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.73 (2026-11-29)
|
|
6
|
+
|
|
7
|
+
- The public-host guard (`publicFetch`, `publicDownload`, `publicCheck`) refuses a URL holding a user name or password itself, on the first hop and at every redirect, before that hop's name is resolved or anything is sent to it: `refused: the URL holds a user name or password`, or `refused: a redirect to a URL holding a user name or password`. The refusal never quotes the URL. Before, a redirect to such a URL was stopped only by undici's own `Request`, whose error quotes the URL whole, and a guard given another fetch followed it. Every hop now goes through the same checks, the first one's included: scheme, user name or password, then name, addresses and port. web_fetch's direct fetch, web_save's download and the server's fal file download answer such a redirect with the guard's refusal. <!-- changes/public-fetch-userinfo-every-hop.md -->
|
|
8
|
+
|
|
5
9
|
## 0.1.0-beta.70 (2026-11-29)
|
|
6
10
|
|
|
7
11
|
- A process that dies inside a browser run on a local Chrome is reattached at once. Before, Stagehand's extension kept the dead client's callback batch running until its own timeout (60 s by default) and held the new process's `Stagehand.create` behind it, so the reattach took about as long as Stagehand's 60 s init deadline and failed when the batch timeout was longer. The copy of the extension the cdp provider gives a local Chrome now aborts a gone client's running batches when the extension releases it. The copy carries Stagehand's LICENSE and a NOTICE saying what changed. A Stagehand release whose worker has moved the code the change rewrites is refused by name at launch. The change isn't applied to a browser that brings its own copy of the extension (Browserbase), which still waits until Stagehand fixes this upstream. A local launch with no private TMPDIR (Windows, or a host temp path too long for one) already runs Stagehand's own extension directory unconfined, so it doesn't get the change either and still waits, like Browserbase. pi-browser now pins Stagehand 4.4.0 exactly, the version the change was written against. <!-- changes/pi-browser-reattach-ends-dead-batch.md -->
|
|
@@ -35,8 +35,8 @@ export type PublicFile = {
|
|
|
35
35
|
bytes: Uint8Array | null;
|
|
36
36
|
};
|
|
37
37
|
type Lookup = (host: string) => Promise<string[]>;
|
|
38
|
-
/** Whether publicFetch's first hop would be dialled for `url`:
|
|
39
|
-
* Resolves when it passes; throws publicFetch's own refusal when it does not. */
|
|
38
|
+
/** Whether publicFetch's first hop would be dialled for `url`: hopUrl's and hopAddresses' checks, http(s), with nothing
|
|
39
|
+
* sent. Resolves when it passes; throws publicFetch's own refusal when it does not. */
|
|
40
40
|
export declare function publicCheck(url: string, options?: {
|
|
41
41
|
lookup?: Lookup;
|
|
42
42
|
signal?: AbortSignal;
|
|
@@ -46,13 +46,14 @@ export declare function publicCheck(url: string, options?: {
|
|
|
46
46
|
* address checked. A 2xx answer of a text type is read whole, up to `maxBytes`, and
|
|
47
47
|
* decoded by the charset it declares (pageText); another status comes back without its
|
|
48
48
|
* body. Refused (`BrowserFailureError` `refused`), on the first hop or a redirect: a scheme other than http(s) (other
|
|
49
|
-
* than https, with `httpsOnly`); a host that is local by name or resolves to any
|
|
49
|
+
* than https, with `httpsOnly`); a URL holding a user name or password; a host that is local by name or resolves to any
|
|
50
|
+
* private address; a port other than 80
|
|
50
51
|
* or 443; too many redirects (any, with `maxRedirects` 0); a 2xx body that is not text or is over the cap. `signal` ends the fetch at any point, a
|
|
51
52
|
* hop's name lookup included (it rejects with the signal's reason), and an aborted hop is never dialled.
|
|
52
53
|
*/
|
|
53
54
|
export declare function publicFetch(url: string, options?: PublicFetchOptions): Promise<PublicAnswer>;
|
|
54
55
|
/**
|
|
55
|
-
* Downloads `url` from a public host: publicFetch's hops and refusals (scheme, local or private host, port, redirects,
|
|
56
|
+
* Downloads `url` from a public host: publicFetch's hops and refusals (scheme, user name or password, local or private host, port, redirects,
|
|
56
57
|
* the signal), with any content type accepted and the body kept as bytes, up to `maxBytes` (default 5 MiB). A 2xx answer
|
|
57
58
|
* is read whole; another status comes back with `bytes` null. A body over the cap is refused (`refused: the file is over
|
|
58
59
|
* <cap>`): before a byte is read when its content-length says so, else as soon as it passes it. A body whose length its
|
|
@@ -163,29 +163,36 @@ async function hopAddresses(target, lookup, signal) {
|
|
|
163
163
|
signal?.throwIfAborted();
|
|
164
164
|
return addresses;
|
|
165
165
|
}
|
|
166
|
-
/**
|
|
167
|
-
*
|
|
166
|
+
/** One hop's URL checks, before its name is resolved: its scheme matches `scheme`, and it holds no user name or password
|
|
167
|
+
* (no credentials go out, and undici's own refusal of such a URL quotes it whole). `redirected` when the hop is a
|
|
168
|
+
* redirect's target. The refusal never quotes the URL. */
|
|
169
|
+
function hopUrl(target, [scheme, schemeName], redirected) {
|
|
170
|
+
if (!scheme.test(target.protocol))
|
|
171
|
+
throw refusedError(redirected ? `refused: a redirect left ${schemeName}` : `refused: ${target.protocol} is not ${schemeName}`);
|
|
172
|
+
if (target.username || target.password)
|
|
173
|
+
throw refusedError(`refused: ${redirected ? "a redirect to a URL holding" : "the URL holds"} a user name or password`);
|
|
174
|
+
}
|
|
175
|
+
/** Whether publicFetch's first hop would be dialled for `url`: hopUrl's and hopAddresses' checks, http(s), with nothing
|
|
176
|
+
* sent. Resolves when it passes; throws publicFetch's own refusal when it does not. */
|
|
168
177
|
export async function publicCheck(url, options = {}) {
|
|
169
178
|
const target = new URL(url);
|
|
170
|
-
|
|
171
|
-
throw refusedError(`refused: ${target.protocol} is not http(s)`);
|
|
179
|
+
hopUrl(target, [/^https?:$/, "http(s)"], false);
|
|
172
180
|
await hopAddresses(target, options.lookup ?? systemLookup, options.signal);
|
|
173
181
|
}
|
|
174
182
|
/**
|
|
175
|
-
* The hop loop both answers share: `url` fetched from a public host, following at most 5 redirects, each hop
|
|
176
|
-
* checked and dialled at the address checked, asking for
|
|
177
|
-
* which reads what it needs of it; whatever it leaves
|
|
178
|
-
* returns or throws.
|
|
183
|
+
* The hop loop both answers share: `url` fetched from a public host, following at most 5 redirects, each hop, the first
|
|
184
|
+
* and every redirect's alike, checked (hopUrl, then hopAddresses) and dialled at the address checked, asking for
|
|
185
|
+
* `accept`. The answer that ends the redirects goes to `answer`, which reads what it needs of it; whatever it leaves
|
|
186
|
+
* unread is cancelled, and the hop's connection closed, once it returns or throws.
|
|
179
187
|
*/
|
|
180
188
|
async function publicHops(url, options, accept, answer) {
|
|
181
189
|
const lookup = options.lookup ?? systemLookup;
|
|
182
190
|
const request = options.fetchImpl ?? ((target, init) => undiciFetch(target, init));
|
|
183
|
-
const
|
|
191
|
+
const scheme = options.httpsOnly ? [/^https:$/, "https"] : [/^https?:$/, "http(s)"];
|
|
184
192
|
const most = options.maxRedirects ?? MAX_REDIRECTS;
|
|
185
193
|
let target = new URL(url);
|
|
186
|
-
if (!scheme.test(target.protocol))
|
|
187
|
-
throw refusedError(`refused: ${target.protocol} is not ${schemeName}`);
|
|
188
194
|
for (let hop = 0;; hop += 1) {
|
|
195
|
+
hopUrl(target, scheme, hop > 0);
|
|
189
196
|
const addresses = await hopAddresses(target, lookup, options.signal);
|
|
190
197
|
const dispatcher = new Agent({ connect: { lookup: pinnedLookup(addresses[0]) } });
|
|
191
198
|
let res;
|
|
@@ -195,8 +202,6 @@ async function publicHops(url, options, accept, answer) {
|
|
|
195
202
|
if (hop >= most)
|
|
196
203
|
throw refusedError(most === 0 ? "refused: a redirect, and this download follows none" : "refused: too many redirects");
|
|
197
204
|
target = new URL(res.headers.get("location"), target);
|
|
198
|
-
if (!scheme.test(target.protocol))
|
|
199
|
-
throw refusedError(`refused: a redirect left ${schemeName}`);
|
|
200
205
|
continue;
|
|
201
206
|
}
|
|
202
207
|
return await answer(res, target);
|
|
@@ -268,7 +273,8 @@ function statedLength(headers) {
|
|
|
268
273
|
* address checked. A 2xx answer of a text type is read whole, up to `maxBytes`, and
|
|
269
274
|
* decoded by the charset it declares (pageText); another status comes back without its
|
|
270
275
|
* body. Refused (`BrowserFailureError` `refused`), on the first hop or a redirect: a scheme other than http(s) (other
|
|
271
|
-
* than https, with `httpsOnly`); a host that is local by name or resolves to any
|
|
276
|
+
* than https, with `httpsOnly`); a URL holding a user name or password; a host that is local by name or resolves to any
|
|
277
|
+
* private address; a port other than 80
|
|
272
278
|
* or 443; too many redirects (any, with `maxRedirects` 0); a 2xx body that is not text or is over the cap. `signal` ends the fetch at any point, a
|
|
273
279
|
* hop's name lookup included (it rejects with the signal's reason), and an aborted hop is never dialled.
|
|
274
280
|
*/
|
|
@@ -288,7 +294,7 @@ export async function publicFetch(url, options = {}) {
|
|
|
288
294
|
});
|
|
289
295
|
}
|
|
290
296
|
/**
|
|
291
|
-
* Downloads `url` from a public host: publicFetch's hops and refusals (scheme, local or private host, port, redirects,
|
|
297
|
+
* Downloads `url` from a public host: publicFetch's hops and refusals (scheme, user name or password, local or private host, port, redirects,
|
|
292
298
|
* the signal), with any content type accepted and the body kept as bytes, up to `maxBytes` (default 5 MiB). A 2xx answer
|
|
293
299
|
* is read whole; another status comes back with `bytes` null. A body over the cap is refused (`refused: the file is over
|
|
294
300
|
* <cap>`): before a byte is read when its content-length says so, else as soon as it passes it. A body whose length its
|