@orchestraai/agent-tools 0.10.16 → 0.10.17
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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/.devin/adapter.json +1 -1
- package/.hermes/adapter.json +1 -1
- package/.opencode/adapter.json +1 -1
- package/dist/commands/claude-setup.d.ts +1 -1
- package/dist/runtime/conversation/command-guard.js +1023 -63
- package/dist/runtime/conversation/command-guard.js.map +1 -1
- package/dist/runtime/conversation/shell-parse.d.ts +42 -0
- package/dist/runtime/conversation/shell-parse.js +517 -0
- package/dist/runtime/conversation/shell-parse.js.map +1 -0
- package/docs/security.md +11 -2
- package/node_modules/@hono/node-server/dist/index.cjs +63 -17
- package/node_modules/@hono/node-server/dist/index.mjs +63 -17
- package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -1
- package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -1
- package/node_modules/@hono/node-server/package.json +1 -1
- package/node_modules/cross-spawn/README.md +19 -3
- package/node_modules/cross-spawn/lib/parse.js +38 -10
- package/node_modules/cross-spawn/lib/util/escape.js +84 -25
- package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
- package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
- package/node_modules/cross-spawn/package.json +21 -24
- package/node_modules/hono/README.md +2 -3
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/cjs/client/utils.js +9 -5
- package/node_modules/hono/dist/cjs/context.js +1 -1
- package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/cjs/helper/css/common.js +11 -8
- package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
- package/node_modules/hono/dist/cjs/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
- package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/cjs/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/cjs/hono-base.js +9 -10
- package/node_modules/hono/dist/cjs/hono.js +0 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +51 -32
- package/node_modules/hono/dist/cjs/jsx/components.js +2 -2
- package/node_modules/hono/dist/cjs/jsx/constants.js +2 -0
- package/node_modules/hono/dist/cjs/jsx/context.js +15 -2
- package/node_modules/hono/dist/cjs/jsx/dom/components.js +1 -1
- package/node_modules/hono/dist/cjs/jsx/dom/hooks/index.js +38 -8
- package/node_modules/hono/dist/cjs/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/cjs/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/cjs/jsx/jsx-runtime.js +13 -17
- package/node_modules/hono/dist/cjs/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/cjs/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/cjs/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/cjs/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/cjs/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/cjs/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/cjs/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js +4 -4
- package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +39 -51
- package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/cjs/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/cjs/utils/body.js +2 -1
- package/node_modules/hono/dist/cjs/utils/cookie.js +3 -3
- package/node_modules/hono/dist/cjs/utils/html.js +5 -0
- package/node_modules/hono/dist/cjs/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/cjs/utils/mime.js +3 -2
- package/node_modules/hono/dist/cjs/utils/mount.js +59 -0
- package/node_modules/hono/dist/cjs/utils/url.js +23 -11
- package/node_modules/hono/dist/cjs/validator/validator.js +5 -5
- package/node_modules/hono/dist/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/client/utils.js +9 -5
- package/node_modules/hono/dist/context.js +1 -1
- package/node_modules/hono/dist/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/helper/css/common.js +11 -8
- package/node_modules/hono/dist/helper/css/index.js +1 -1
- package/node_modules/hono/dist/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/helper/route/index.js +3 -1
- package/node_modules/hono/dist/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/hono-base.js +9 -10
- package/node_modules/hono/dist/hono.js +0 -1
- package/node_modules/hono/dist/jsx/base.js +51 -34
- package/node_modules/hono/dist/jsx/components.js +2 -2
- package/node_modules/hono/dist/jsx/constants.js +2 -1
- package/node_modules/hono/dist/jsx/context.js +15 -2
- package/node_modules/hono/dist/jsx/dom/components.js +2 -2
- package/node_modules/hono/dist/jsx/dom/hooks/index.js +39 -9
- package/node_modules/hono/dist/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/jsx/jsx-runtime.js +15 -19
- package/node_modules/hono/dist/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/router/reg-exp-router/prepared-router.js +5 -5
- package/node_modules/hono/dist/router/reg-exp-router/router.js +40 -52
- package/node_modules/hono/dist/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/accepts/accepts.d.ts +5 -0
- package/node_modules/hono/dist/types/helper/factory/index.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/ssg/ssg.d.ts +6 -1
- package/node_modules/hono/dist/types/helper/streaming/sse.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/stream.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/text.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/websocket/index.d.ts +13 -3
- package/node_modules/hono/dist/types/hono-base.d.ts +23 -9
- package/node_modules/hono/dist/types/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +6 -3
- package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/constants.d.ts +1 -0
- package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +5 -3
- package/node_modules/hono/dist/types/jsx/dom/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/dom/server.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/jsx-runtime.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
- package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +1 -0
- package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/mount/index.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/request-id/request-id.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -0
- package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -3
- package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/cookie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/jwt/jwt.d.ts +4 -2
- package/node_modules/hono/dist/types/utils/mount.d.ts +4 -0
- package/node_modules/hono/dist/types/utils/types.d.ts +12 -2
- package/node_modules/hono/dist/utils/body.js +2 -1
- package/node_modules/hono/dist/utils/cookie.js +3 -3
- package/node_modules/hono/dist/utils/html.js +5 -0
- package/node_modules/hono/dist/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/utils/mime.js +3 -2
- package/node_modules/hono/dist/utils/mount.js +58 -0
- package/node_modules/hono/dist/utils/url.js +23 -11
- package/node_modules/hono/dist/validator/validator.js +5 -5
- package/node_modules/hono/package.json +1 -1
- package/package.json +1 -1
|
@@ -169,16 +169,27 @@ const newHeadersFromIncoming = (incoming) => globalThis.Headers === GlobalHeader
|
|
|
169
169
|
const reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;
|
|
170
170
|
const reDotSegment = /\/\.\.?(?:[/?#]|$)/;
|
|
171
171
|
const reValidHost = /^[a-z0-9._-]+(?::(?:[1-5]\d{3,4}|[6-9]\d{3}))?$/;
|
|
172
|
+
const validateRequestTarget = (target) => {
|
|
173
|
+
const backslash = target.indexOf("\\");
|
|
174
|
+
if (backslash !== -1) {
|
|
175
|
+
const query = target.indexOf("?");
|
|
176
|
+
if (query === -1 || backslash < query) throw new RequestError("Backslash in request path");
|
|
177
|
+
}
|
|
178
|
+
};
|
|
172
179
|
const buildUrl = (scheme, host, incomingUrl) => {
|
|
173
180
|
const url = `${scheme}://${host}${incomingUrl}`;
|
|
174
181
|
if (!reValidHost.test(host)) {
|
|
182
|
+
validateRequestTarget(incomingUrl);
|
|
175
183
|
const urlObj = new URL(url);
|
|
176
184
|
if (urlObj.hostname.length !== host.length && urlObj.hostname !== (host.includes(":") ? host.replace(/:\d+$/, "") : host).toLowerCase()) throw new RequestError("Invalid host header");
|
|
177
185
|
return urlObj.href;
|
|
178
186
|
} else if (incomingUrl.length === 0) return url + "/";
|
|
179
187
|
else {
|
|
180
188
|
if (incomingUrl.charCodeAt(0) !== 47) throw new RequestError("Invalid URL");
|
|
181
|
-
if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl))
|
|
189
|
+
if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl)) {
|
|
190
|
+
validateRequestTarget(incomingUrl);
|
|
191
|
+
return new URL(url).href;
|
|
192
|
+
}
|
|
182
193
|
return url;
|
|
183
194
|
}
|
|
184
195
|
};
|
|
@@ -190,7 +201,11 @@ const toRequestError = (e) => {
|
|
|
190
201
|
return new RequestError(e.message, { cause: e });
|
|
191
202
|
};
|
|
192
203
|
const GlobalRequest = global.Request;
|
|
193
|
-
var Request$1 = class extends GlobalRequest {
|
|
204
|
+
var Request$1 = class Request$1 extends GlobalRequest {
|
|
205
|
+
static [Symbol.hasInstance](instance) {
|
|
206
|
+
if (this === Request$1) return instance instanceof GlobalRequest || Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
207
|
+
return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
208
|
+
}
|
|
194
209
|
constructor(input, options) {
|
|
195
210
|
if (typeof input === "object" && getRequestCache in input) {
|
|
196
211
|
const hasReplacementBody = options !== void 0 && "body" in options && options.body != null;
|
|
@@ -229,8 +244,8 @@ const readBodyBufferedBeforeDisconnect = (incoming, chunks) => {
|
|
|
229
244
|
else if (incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] !== void 0 && incoming.readableLength !== incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey]) result = newBodyUnusableError();
|
|
230
245
|
else {
|
|
231
246
|
const bodyChunks = chunks ?? [];
|
|
232
|
-
|
|
233
|
-
|
|
247
|
+
let chunk;
|
|
248
|
+
while ((chunk = incoming.read()) !== null) bodyChunks.push(toBufferChunk(chunk, incoming.readableEncoding));
|
|
234
249
|
const buffer = bodyChunks.length === 1 ? bodyChunks[0] : Buffer.concat(bodyChunks);
|
|
235
250
|
result = buffer;
|
|
236
251
|
const contentLength = incoming.headers["content-length"];
|
|
@@ -534,6 +549,7 @@ Object.defineProperty(requestPrototype, "signal", { get() {
|
|
|
534
549
|
"cache",
|
|
535
550
|
"credentials",
|
|
536
551
|
"destination",
|
|
552
|
+
"duplex",
|
|
537
553
|
"integrity",
|
|
538
554
|
"mode",
|
|
539
555
|
"redirect",
|
|
@@ -567,6 +583,9 @@ Object.defineProperty(requestPrototype, "blob", { value: function() {
|
|
|
567
583
|
return new Response(buf, init).blob();
|
|
568
584
|
});
|
|
569
585
|
} });
|
|
586
|
+
Object.defineProperty(requestPrototype, "bytes", { value: function() {
|
|
587
|
+
return this.arrayBuffer().then((buf) => new Uint8Array(buf));
|
|
588
|
+
} });
|
|
570
589
|
Object.defineProperty(requestPrototype, "json", { value: function() {
|
|
571
590
|
if (this[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
572
591
|
return this.text().then(JSON.parse);
|
|
@@ -591,6 +610,7 @@ const newRequest = (incoming, defaultHostname) => {
|
|
|
591
610
|
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
592
611
|
if (incoming instanceof node_http2.Http2ServerRequest) throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
593
612
|
try {
|
|
613
|
+
validateRequestTarget(incomingUrl);
|
|
594
614
|
req[urlKey] = new URL(incomingUrl).href;
|
|
595
615
|
} catch (e) {
|
|
596
616
|
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
@@ -623,6 +643,10 @@ const GlobalResponse = global.Response;
|
|
|
623
643
|
var Response$1 = class Response$1 {
|
|
624
644
|
#body;
|
|
625
645
|
#init;
|
|
646
|
+
static [Symbol.hasInstance](instance) {
|
|
647
|
+
if (this === Response$1) return instance instanceof GlobalResponse || Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
648
|
+
return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
649
|
+
}
|
|
626
650
|
[getResponseCache]() {
|
|
627
651
|
const cache = this[cacheKey];
|
|
628
652
|
const liveHeaders = cache && cache[2] instanceof Headers ? cache[2] : void 0;
|
|
@@ -643,7 +667,7 @@ var Response$1 = class Response$1 {
|
|
|
643
667
|
this[getResponseCache]();
|
|
644
668
|
return;
|
|
645
669
|
}
|
|
646
|
-
this.#init = init
|
|
670
|
+
this.#init = #init in init ? init.#init : init;
|
|
647
671
|
headers = new Headers(init.headers);
|
|
648
672
|
} else this.#init = init;
|
|
649
673
|
if (body == null || typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
|
|
@@ -684,6 +708,7 @@ var Response$1 = class Response$1 {
|
|
|
684
708
|
[
|
|
685
709
|
"arrayBuffer",
|
|
686
710
|
"blob",
|
|
711
|
+
"bytes",
|
|
687
712
|
"clone",
|
|
688
713
|
"formData",
|
|
689
714
|
"json",
|
|
@@ -759,6 +784,11 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
759
784
|
const cancel = (error) => {
|
|
760
785
|
reader.cancel(error).catch(() => {});
|
|
761
786
|
};
|
|
787
|
+
const stream = writable.stream;
|
|
788
|
+
if (writable.destroyed || stream?.closed || stream?.destroyed) {
|
|
789
|
+
cancel();
|
|
790
|
+
return reader.closed;
|
|
791
|
+
}
|
|
762
792
|
writable.on("close", cancel);
|
|
763
793
|
writable.on("error", cancel);
|
|
764
794
|
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
@@ -776,7 +806,7 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
776
806
|
try {
|
|
777
807
|
if (done) writable.end();
|
|
778
808
|
else if (!writable.write(value)) writable.once("drain", onDrain);
|
|
779
|
-
else
|
|
809
|
+
else reader.read().then(flow, handleStreamError);
|
|
780
810
|
} catch (e) {
|
|
781
811
|
handleStreamError(e);
|
|
782
812
|
}
|
|
@@ -784,7 +814,10 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
784
814
|
}
|
|
785
815
|
function writeFromReadableStream(stream, writable) {
|
|
786
816
|
if (stream.locked) throw new TypeError("ReadableStream is locked.");
|
|
787
|
-
else if (writable.destroyed)
|
|
817
|
+
else if (writable.destroyed) {
|
|
818
|
+
stream.cancel().catch(() => {});
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
788
821
|
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
789
822
|
}
|
|
790
823
|
const buildOutgoingHttpHeaders = (headers, defaultContentType) => {
|
|
@@ -978,10 +1011,7 @@ const responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
978
1011
|
let maxReadCount = 2;
|
|
979
1012
|
for (let i = 0; i < maxReadCount; i++) {
|
|
980
1013
|
currentReadPromise ||= reader.read();
|
|
981
|
-
const chunk = await readWithoutBlocking(currentReadPromise)
|
|
982
|
-
console.error(e);
|
|
983
|
-
done = true;
|
|
984
|
-
});
|
|
1014
|
+
const chunk = await readWithoutBlocking(currentReadPromise);
|
|
985
1015
|
if (!chunk) {
|
|
986
1016
|
if (i === 1) {
|
|
987
1017
|
await new Promise((resolve) => setTimeout(resolve));
|
|
@@ -1143,6 +1173,7 @@ const appendResponseHeaders = (headers, responseHeaders) => {
|
|
|
1143
1173
|
});
|
|
1144
1174
|
};
|
|
1145
1175
|
const rejectUpgradeRequest = (socket, status, responseHeaders) => {
|
|
1176
|
+
if (socket.destroyed) return;
|
|
1146
1177
|
const responseLines = ["Connection: close", "Content-Length: 0"];
|
|
1147
1178
|
appendResponseHeaders(responseLines, responseHeaders);
|
|
1148
1179
|
socket.end(`HTTP/1.1 ${status.toString()} ${node_http.STATUS_CODES[status] ?? ""}\r\n${responseLines.join("\r\n")}\r\n\r
|
|
@@ -1150,7 +1181,12 @@ const rejectUpgradeRequest = (socket, status, responseHeaders) => {
|
|
|
1150
1181
|
};
|
|
1151
1182
|
const createUpgradeRequest = (request) => {
|
|
1152
1183
|
const protocol = request.socket.encrypted ? "https" : "http";
|
|
1153
|
-
const
|
|
1184
|
+
const incomingUrl = request.url ?? "/";
|
|
1185
|
+
let url;
|
|
1186
|
+
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
1187
|
+
validateRequestTarget(incomingUrl);
|
|
1188
|
+
url = new URL(incomingUrl).href;
|
|
1189
|
+
} else url = buildUrl(protocol, request.headers.host ?? "localhost", incomingUrl);
|
|
1154
1190
|
const headers = new Headers();
|
|
1155
1191
|
for (const key in request.headers) {
|
|
1156
1192
|
const value = request.headers[key];
|
|
@@ -1186,7 +1222,14 @@ const setupWebSocket = (options) => {
|
|
|
1186
1222
|
});
|
|
1187
1223
|
};
|
|
1188
1224
|
server.on("upgrade", async (request, socket, head) => {
|
|
1189
|
-
|
|
1225
|
+
const ignoreSocketError = () => {};
|
|
1226
|
+
socket.on("error", ignoreSocketError);
|
|
1227
|
+
if (request.headers.upgrade?.toLowerCase() !== "websocket") {
|
|
1228
|
+
if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, 400);
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
const reclaimWaiterOnClose = () => rejectWaiter(request);
|
|
1232
|
+
socket.once("close", reclaimWaiterOnClose);
|
|
1190
1233
|
const env = {
|
|
1191
1234
|
incoming: request,
|
|
1192
1235
|
outgoing: void 0,
|
|
@@ -1201,8 +1244,12 @@ const setupWebSocket = (options) => {
|
|
|
1201
1244
|
status = response.status;
|
|
1202
1245
|
responseHeaders = response.headers;
|
|
1203
1246
|
}
|
|
1204
|
-
} catch {
|
|
1205
|
-
if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, 500);
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, error instanceof RequestError ? 400 : 500);
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
if (socket.destroyed) {
|
|
1252
|
+
rejectWaiter(request);
|
|
1206
1253
|
return;
|
|
1207
1254
|
}
|
|
1208
1255
|
const waiter = waiterMap.get(request);
|
|
@@ -1214,12 +1261,11 @@ const setupWebSocket = (options) => {
|
|
|
1214
1261
|
const addResponseHeaders = (headers) => {
|
|
1215
1262
|
appendResponseHeaders(headers, responseHeaders);
|
|
1216
1263
|
};
|
|
1217
|
-
const reclaimWaiterOnClose = () => rejectWaiter(request);
|
|
1218
|
-
socket.once("close", reclaimWaiterOnClose);
|
|
1219
1264
|
wss.on("headers", addResponseHeaders);
|
|
1220
1265
|
try {
|
|
1221
1266
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
1222
1267
|
socket.off("close", reclaimWaiterOnClose);
|
|
1268
|
+
socket.off("error", ignoreSocketError);
|
|
1223
1269
|
wss.emit("connection", ws, request);
|
|
1224
1270
|
});
|
|
1225
1271
|
} finally {
|
|
@@ -168,16 +168,27 @@ const newHeadersFromIncoming = (incoming) => globalThis.Headers === GlobalHeader
|
|
|
168
168
|
const reValidRequestUrl = /^\/[!#$&-;=?-\[\]_a-z~]*$/;
|
|
169
169
|
const reDotSegment = /\/\.\.?(?:[/?#]|$)/;
|
|
170
170
|
const reValidHost = /^[a-z0-9._-]+(?::(?:[1-5]\d{3,4}|[6-9]\d{3}))?$/;
|
|
171
|
+
const validateRequestTarget = (target) => {
|
|
172
|
+
const backslash = target.indexOf("\\");
|
|
173
|
+
if (backslash !== -1) {
|
|
174
|
+
const query = target.indexOf("?");
|
|
175
|
+
if (query === -1 || backslash < query) throw new RequestError("Backslash in request path");
|
|
176
|
+
}
|
|
177
|
+
};
|
|
171
178
|
const buildUrl = (scheme, host, incomingUrl) => {
|
|
172
179
|
const url = `${scheme}://${host}${incomingUrl}`;
|
|
173
180
|
if (!reValidHost.test(host)) {
|
|
181
|
+
validateRequestTarget(incomingUrl);
|
|
174
182
|
const urlObj = new URL(url);
|
|
175
183
|
if (urlObj.hostname.length !== host.length && urlObj.hostname !== (host.includes(":") ? host.replace(/:\d+$/, "") : host).toLowerCase()) throw new RequestError("Invalid host header");
|
|
176
184
|
return urlObj.href;
|
|
177
185
|
} else if (incomingUrl.length === 0) return url + "/";
|
|
178
186
|
else {
|
|
179
187
|
if (incomingUrl.charCodeAt(0) !== 47) throw new RequestError("Invalid URL");
|
|
180
|
-
if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl))
|
|
188
|
+
if (!reValidRequestUrl.test(incomingUrl) || reDotSegment.test(incomingUrl)) {
|
|
189
|
+
validateRequestTarget(incomingUrl);
|
|
190
|
+
return new URL(url).href;
|
|
191
|
+
}
|
|
181
192
|
return url;
|
|
182
193
|
}
|
|
183
194
|
};
|
|
@@ -189,7 +200,11 @@ const toRequestError = (e) => {
|
|
|
189
200
|
return new RequestError(e.message, { cause: e });
|
|
190
201
|
};
|
|
191
202
|
const GlobalRequest = global.Request;
|
|
192
|
-
var Request$1 = class extends GlobalRequest {
|
|
203
|
+
var Request$1 = class Request$1 extends GlobalRequest {
|
|
204
|
+
static [Symbol.hasInstance](instance) {
|
|
205
|
+
if (this === Request$1) return instance instanceof GlobalRequest || Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
206
|
+
return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
207
|
+
}
|
|
193
208
|
constructor(input, options) {
|
|
194
209
|
if (typeof input === "object" && getRequestCache in input) {
|
|
195
210
|
const hasReplacementBody = options !== void 0 && "body" in options && options.body != null;
|
|
@@ -228,8 +243,8 @@ const readBodyBufferedBeforeDisconnect = (incoming, chunks) => {
|
|
|
228
243
|
else if (incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey] !== void 0 && incoming.readableLength !== incomingWithRecovery[bodyBufferedLengthBeforeDisconnectKey]) result = newBodyUnusableError();
|
|
229
244
|
else {
|
|
230
245
|
const bodyChunks = chunks ?? [];
|
|
231
|
-
|
|
232
|
-
|
|
246
|
+
let chunk;
|
|
247
|
+
while ((chunk = incoming.read()) !== null) bodyChunks.push(toBufferChunk(chunk, incoming.readableEncoding));
|
|
233
248
|
const buffer = bodyChunks.length === 1 ? bodyChunks[0] : Buffer.concat(bodyChunks);
|
|
234
249
|
result = buffer;
|
|
235
250
|
const contentLength = incoming.headers["content-length"];
|
|
@@ -533,6 +548,7 @@ Object.defineProperty(requestPrototype, "signal", { get() {
|
|
|
533
548
|
"cache",
|
|
534
549
|
"credentials",
|
|
535
550
|
"destination",
|
|
551
|
+
"duplex",
|
|
536
552
|
"integrity",
|
|
537
553
|
"mode",
|
|
538
554
|
"redirect",
|
|
@@ -566,6 +582,9 @@ Object.defineProperty(requestPrototype, "blob", { value: function() {
|
|
|
566
582
|
return new Response(buf, init).blob();
|
|
567
583
|
});
|
|
568
584
|
} });
|
|
585
|
+
Object.defineProperty(requestPrototype, "bytes", { value: function() {
|
|
586
|
+
return this.arrayBuffer().then((buf) => new Uint8Array(buf));
|
|
587
|
+
} });
|
|
569
588
|
Object.defineProperty(requestPrototype, "json", { value: function() {
|
|
570
589
|
if (this[bodyConsumedDirectlyKey]) return rejectBodyUnusable();
|
|
571
590
|
return this.text().then(JSON.parse);
|
|
@@ -590,6 +609,7 @@ const newRequest = (incoming, defaultHostname) => {
|
|
|
590
609
|
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
591
610
|
if (incoming instanceof Http2ServerRequest) throw new RequestError("Absolute URL for :path is not allowed in HTTP/2");
|
|
592
611
|
try {
|
|
612
|
+
validateRequestTarget(incomingUrl);
|
|
593
613
|
req[urlKey] = new URL(incomingUrl).href;
|
|
594
614
|
} catch (e) {
|
|
595
615
|
throw new RequestError("Invalid absolute URL", { cause: e });
|
|
@@ -622,6 +642,10 @@ const GlobalResponse = global.Response;
|
|
|
622
642
|
var Response$1 = class Response$1 {
|
|
623
643
|
#body;
|
|
624
644
|
#init;
|
|
645
|
+
static [Symbol.hasInstance](instance) {
|
|
646
|
+
if (this === Response$1) return instance instanceof GlobalResponse || Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
647
|
+
return Function.prototype[Symbol.hasInstance].call(this, instance);
|
|
648
|
+
}
|
|
625
649
|
[getResponseCache]() {
|
|
626
650
|
const cache = this[cacheKey];
|
|
627
651
|
const liveHeaders = cache && cache[2] instanceof Headers ? cache[2] : void 0;
|
|
@@ -642,7 +666,7 @@ var Response$1 = class Response$1 {
|
|
|
642
666
|
this[getResponseCache]();
|
|
643
667
|
return;
|
|
644
668
|
}
|
|
645
|
-
this.#init = init
|
|
669
|
+
this.#init = #init in init ? init.#init : init;
|
|
646
670
|
headers = new Headers(init.headers);
|
|
647
671
|
} else this.#init = init;
|
|
648
672
|
if (body == null || typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) this[cacheKey] = [
|
|
@@ -683,6 +707,7 @@ var Response$1 = class Response$1 {
|
|
|
683
707
|
[
|
|
684
708
|
"arrayBuffer",
|
|
685
709
|
"blob",
|
|
710
|
+
"bytes",
|
|
686
711
|
"clone",
|
|
687
712
|
"formData",
|
|
688
713
|
"json",
|
|
@@ -758,6 +783,11 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
758
783
|
const cancel = (error) => {
|
|
759
784
|
reader.cancel(error).catch(() => {});
|
|
760
785
|
};
|
|
786
|
+
const stream = writable.stream;
|
|
787
|
+
if (writable.destroyed || stream?.closed || stream?.destroyed) {
|
|
788
|
+
cancel();
|
|
789
|
+
return reader.closed;
|
|
790
|
+
}
|
|
761
791
|
writable.on("close", cancel);
|
|
762
792
|
writable.on("error", cancel);
|
|
763
793
|
(currentReadPromise ?? reader.read()).then(flow, handleStreamError);
|
|
@@ -775,7 +805,7 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
775
805
|
try {
|
|
776
806
|
if (done) writable.end();
|
|
777
807
|
else if (!writable.write(value)) writable.once("drain", onDrain);
|
|
778
|
-
else
|
|
808
|
+
else reader.read().then(flow, handleStreamError);
|
|
779
809
|
} catch (e) {
|
|
780
810
|
handleStreamError(e);
|
|
781
811
|
}
|
|
@@ -783,7 +813,10 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
783
813
|
}
|
|
784
814
|
function writeFromReadableStream(stream, writable) {
|
|
785
815
|
if (stream.locked) throw new TypeError("ReadableStream is locked.");
|
|
786
|
-
else if (writable.destroyed)
|
|
816
|
+
else if (writable.destroyed) {
|
|
817
|
+
stream.cancel().catch(() => {});
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
787
820
|
return writeFromReadableStreamDefaultReader(stream.getReader(), writable);
|
|
788
821
|
}
|
|
789
822
|
const buildOutgoingHttpHeaders = (headers, defaultContentType) => {
|
|
@@ -977,10 +1010,7 @@ const responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
977
1010
|
let maxReadCount = 2;
|
|
978
1011
|
for (let i = 0; i < maxReadCount; i++) {
|
|
979
1012
|
currentReadPromise ||= reader.read();
|
|
980
|
-
const chunk = await readWithoutBlocking(currentReadPromise)
|
|
981
|
-
console.error(e);
|
|
982
|
-
done = true;
|
|
983
|
-
});
|
|
1013
|
+
const chunk = await readWithoutBlocking(currentReadPromise);
|
|
984
1014
|
if (!chunk) {
|
|
985
1015
|
if (i === 1) {
|
|
986
1016
|
await new Promise((resolve) => setTimeout(resolve));
|
|
@@ -1142,6 +1172,7 @@ const appendResponseHeaders = (headers, responseHeaders) => {
|
|
|
1142
1172
|
});
|
|
1143
1173
|
};
|
|
1144
1174
|
const rejectUpgradeRequest = (socket, status, responseHeaders) => {
|
|
1175
|
+
if (socket.destroyed) return;
|
|
1145
1176
|
const responseLines = ["Connection: close", "Content-Length: 0"];
|
|
1146
1177
|
appendResponseHeaders(responseLines, responseHeaders);
|
|
1147
1178
|
socket.end(`HTTP/1.1 ${status.toString()} ${STATUS_CODES[status] ?? ""}\r\n${responseLines.join("\r\n")}\r\n\r
|
|
@@ -1149,7 +1180,12 @@ const rejectUpgradeRequest = (socket, status, responseHeaders) => {
|
|
|
1149
1180
|
};
|
|
1150
1181
|
const createUpgradeRequest = (request) => {
|
|
1151
1182
|
const protocol = request.socket.encrypted ? "https" : "http";
|
|
1152
|
-
const
|
|
1183
|
+
const incomingUrl = request.url ?? "/";
|
|
1184
|
+
let url;
|
|
1185
|
+
if (incomingUrl[0] !== "/" && (incomingUrl.startsWith("http://") || incomingUrl.startsWith("https://"))) {
|
|
1186
|
+
validateRequestTarget(incomingUrl);
|
|
1187
|
+
url = new URL(incomingUrl).href;
|
|
1188
|
+
} else url = buildUrl(protocol, request.headers.host ?? "localhost", incomingUrl);
|
|
1153
1189
|
const headers = new Headers();
|
|
1154
1190
|
for (const key in request.headers) {
|
|
1155
1191
|
const value = request.headers[key];
|
|
@@ -1185,7 +1221,14 @@ const setupWebSocket = (options) => {
|
|
|
1185
1221
|
});
|
|
1186
1222
|
};
|
|
1187
1223
|
server.on("upgrade", async (request, socket, head) => {
|
|
1188
|
-
|
|
1224
|
+
const ignoreSocketError = () => {};
|
|
1225
|
+
socket.on("error", ignoreSocketError);
|
|
1226
|
+
if (request.headers.upgrade?.toLowerCase() !== "websocket") {
|
|
1227
|
+
if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, 400);
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
const reclaimWaiterOnClose = () => rejectWaiter(request);
|
|
1231
|
+
socket.once("close", reclaimWaiterOnClose);
|
|
1189
1232
|
const env = {
|
|
1190
1233
|
incoming: request,
|
|
1191
1234
|
outgoing: void 0,
|
|
@@ -1200,8 +1243,12 @@ const setupWebSocket = (options) => {
|
|
|
1200
1243
|
status = response.status;
|
|
1201
1244
|
responseHeaders = response.headers;
|
|
1202
1245
|
}
|
|
1203
|
-
} catch {
|
|
1204
|
-
if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, 500);
|
|
1246
|
+
} catch (error) {
|
|
1247
|
+
if (server.listenerCount("upgrade") === 1) rejectUpgradeRequest(socket, error instanceof RequestError ? 400 : 500);
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
if (socket.destroyed) {
|
|
1251
|
+
rejectWaiter(request);
|
|
1205
1252
|
return;
|
|
1206
1253
|
}
|
|
1207
1254
|
const waiter = waiterMap.get(request);
|
|
@@ -1213,12 +1260,11 @@ const setupWebSocket = (options) => {
|
|
|
1213
1260
|
const addResponseHeaders = (headers) => {
|
|
1214
1261
|
appendResponseHeaders(headers, responseHeaders);
|
|
1215
1262
|
};
|
|
1216
|
-
const reclaimWaiterOnClose = () => rejectWaiter(request);
|
|
1217
|
-
socket.once("close", reclaimWaiterOnClose);
|
|
1218
1263
|
wss.on("headers", addResponseHeaders);
|
|
1219
1264
|
try {
|
|
1220
1265
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
1221
1266
|
socket.off("close", reclaimWaiterOnClose);
|
|
1267
|
+
socket.off("error", ignoreSocketError);
|
|
1222
1268
|
wss.emit("connection", ws, request);
|
|
1223
1269
|
});
|
|
1224
1270
|
} finally {
|
|
@@ -78,8 +78,8 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
78
78
|
let filename;
|
|
79
79
|
if (optionPath) filename = optionPath;
|
|
80
80
|
else try {
|
|
81
|
-
if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
|
|
82
81
|
filename = tryDecodeURI(c.req.path);
|
|
82
|
+
if (c.req.path.includes("%") && (!options.allowPercentInPath || filename !== c.req.path.replace(/%25/g, "%"))) throw new Error();
|
|
83
83
|
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
|
|
84
84
|
} catch {
|
|
85
85
|
await options.onNotFound?.(c.req.path, c);
|
|
@@ -77,8 +77,8 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
77
77
|
let filename;
|
|
78
78
|
if (optionPath) filename = optionPath;
|
|
79
79
|
else try {
|
|
80
|
-
if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
|
|
81
80
|
filename = tryDecodeURI(c.req.path);
|
|
81
|
+
if (c.req.path.includes("%") && (!options.allowPercentInPath || filename !== c.req.path.replace(/%25/g, "%"))) throw new Error();
|
|
82
82
|
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
|
|
83
83
|
} catch {
|
|
84
84
|
await options.onNotFound?.(c.req.path, c);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
# cross-spawn
|
|
2
2
|
|
|
3
|
-
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url]
|
|
3
|
+
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url]
|
|
4
4
|
|
|
5
5
|
[npm-url]:https://npmjs.org/package/cross-spawn
|
|
6
6
|
[downloads-image]:https://img.shields.io/npm/dm/cross-spawn.svg
|
|
7
7
|
[npm-image]:https://img.shields.io/npm/v/cross-spawn.svg
|
|
8
8
|
[ci-url]:https://github.com/moxystudio/node-cross-spawn/actions/workflows/ci.yaml
|
|
9
9
|
[ci-image]:https://github.com/moxystudio/node-cross-spawn/actions/workflows/ci.yaml/badge.svg
|
|
10
|
-
[appveyor-url]:https://ci.appveyor.com/project/satazor/node-cross-spawn
|
|
11
|
-
[appveyor-image]:https://img.shields.io/appveyor/ci/satazor/node-cross-spawn/master.svg
|
|
12
10
|
|
|
13
11
|
A cross platform solution to node's spawn and spawnSync.
|
|
14
12
|
|
|
@@ -70,6 +68,24 @@ While `cross-spawn` adds support for `options.shell` in node `<v4.8`, all of its
|
|
|
70
68
|
|
|
71
69
|
This mimics the Node.js behavior. More specifically, the command and its arguments will not be automatically escaped nor shebang support will be offered. This is by design because if you are using `options.shell` you are probably targeting a specific platform anyway and you don't want things to get into your way.
|
|
72
70
|
|
|
71
|
+
### Windows argument escaping
|
|
72
|
+
|
|
73
|
+
On Unix systems arguments are passed to a new process as an array of strings, but on Windows they are passed as a single command line string and it is up to the child process to parse it back into an array. Therefore `cross-spawn` and the child process must agree on how the command line is encoded.
|
|
74
|
+
|
|
75
|
+
`cross-spawn` escapes arguments according to the conventions of the Microsoft C runtime, which most programs use, including Node.js, Python, Java and .NET. However, some programs have their own way of parsing the command line, in which case they may see a different array of arguments than the one you passed.
|
|
76
|
+
|
|
77
|
+
Commands that are not executables, such as batch files (`.bat` and `.cmd`), are run through `cmd.exe`, which uses non-standard parsing and is especially vulnerable to malicious input, as it may be used to run arbitrary commands. `cross-spawn` escapes the command and its arguments according to `cmd.exe` rules, similarly to other runtimes such as [Rust](https://doc.rust-lang.org/std/process/index.html#windows-argument-splitting). Still, due to the complexity of `cmd.exe`, there are limitations that no escaping can overcome:
|
|
78
|
+
|
|
79
|
+
- Some characters can't be escaped at all. Line breaks (`\r` and `\n`) can't be escaped and passing them results in an error being thrown.
|
|
80
|
+
- The command must be the name or path of a single program, with its arguments passed in `args`. The command is quoted, so `spawn('npm install')` fails with `ENOENT`, like it does on other platforms, and double quotes in it are ignored, since Windows file names can't contain them.
|
|
81
|
+
- Shell built-ins that run other commands, such as `call` and `start`, pass their arguments to those commands unescaped. Call the program directly instead, e.g. `spawn('tool.bat', args)` instead of `spawn('call', ['tool.bat', ...args])`.
|
|
82
|
+
- Batch files are assumed to forward arguments as received, e.g. with `%*`, `%1` or `"%~1"`. Batch files that use `%~1` unquoted, `call` or enable delayed expansion re-parse their arguments and may be vulnerable to malicious input.
|
|
83
|
+
- Programs called by batch files must follow the Microsoft C runtime conventions. Programs that don't, such as those written in Go or that use `CommandLineToArgvW`, may split arguments containing double quotes differently.
|
|
84
|
+
|
|
85
|
+
Additionally, programs that read their arguments with the legacy ANSI code page instead of Unicode may convert certain Unicode characters into others, such as `"` (U+FF02) into `"`, which changes how arguments are split. This is known as [WorstFit](https://worst.fit) and can't be mitigated by `cross-spawn`.
|
|
86
|
+
|
|
87
|
+
When passing untrusted input on Windows, validate it so that only a safe subset is allowed, and prefer calling executables directly rather than through batch files.
|
|
88
|
+
|
|
73
89
|
### Shebangs support
|
|
74
90
|
|
|
75
91
|
While `cross-spawn` handles shebangs on Windows, its support is limited. More specifically, it just supports `#!/usr/bin/env <program>` where `<program>` must not contain any arguments.
|
|
@@ -7,7 +7,11 @@ const readShebang = require('./util/readShebang');
|
|
|
7
7
|
|
|
8
8
|
const isWin = process.platform === 'win32';
|
|
9
9
|
const isExecutableRegExp = /\.(?:com|exe)$/i;
|
|
10
|
-
const
|
|
10
|
+
const isBatchFileRegExp = /\.(?:bat|cmd)$/i;
|
|
11
|
+
// Windows strips trailing dots and spaces from file names, so `cmd.exe` runs `foo.bat ` as `foo.bat`
|
|
12
|
+
// Other trailing whitespace, such as tabs, is treated the same way to be safe
|
|
13
|
+
// See CVE-2024-36138 for the equivalent Node.js vulnerability
|
|
14
|
+
const trailingDotsAndSpacesRegExp = /[.\s]+$/;
|
|
11
15
|
|
|
12
16
|
function detectShebang(parsed) {
|
|
13
17
|
parsed.file = resolveCommand(parsed);
|
|
@@ -24,11 +28,29 @@ function detectShebang(parsed) {
|
|
|
24
28
|
return parsed.file;
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
function isBatchFile(parsed, commandFile) {
|
|
32
|
+
if (commandFile) {
|
|
33
|
+
return isBatchFileRegExp.test(commandFile.replace(trailingDotsAndSpacesRegExp, ''));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The command couldn't be resolved, but cmd.exe might still find a batch file after stripping
|
|
37
|
+
// trailing dots and spaces, e.g.: `foo ` might run `foo.bat`
|
|
38
|
+
const command = parsed.command.replace(trailingDotsAndSpacesRegExp, '');
|
|
39
|
+
const file = command !== parsed.command ? resolveCommand(Object.assign({}, parsed, { command })) : null;
|
|
40
|
+
|
|
41
|
+
return isBatchFileRegExp.test(file || command);
|
|
42
|
+
}
|
|
43
|
+
|
|
27
44
|
function parseNonShell(parsed) {
|
|
28
45
|
if (!isWin) {
|
|
29
46
|
return parsed;
|
|
30
47
|
}
|
|
31
48
|
|
|
49
|
+
// Windows file names can't contain double quotes, and cmd.exe ignores them in command names, so remove them
|
|
50
|
+
// Otherwise a quoted command, e.g. `"foo.bat"`, wouldn't be found and could be run as a batch file without
|
|
51
|
+
// being detected as one
|
|
52
|
+
parsed.command = parsed.command.replace(/"/g, '');
|
|
53
|
+
|
|
32
54
|
// Detect & add support for shebangs
|
|
33
55
|
const commandFile = detectShebang(parsed);
|
|
34
56
|
|
|
@@ -38,23 +60,29 @@ function parseNonShell(parsed) {
|
|
|
38
60
|
// If a shell is required, use cmd.exe and take care of escaping everything correctly
|
|
39
61
|
// Note that `forceShell` is an hidden option used only in tests
|
|
40
62
|
if (parsed.options.forceShell || needsShell) {
|
|
41
|
-
// Need to double escape meta chars if the command is a cmd-shim located in `node_modules/.bin/`
|
|
42
|
-
// The cmd-shim simply calls execute the package bin file with NodeJS, proxying any argument
|
|
43
|
-
// Because the escape of metachars with ^ gets interpreted when the cmd.exe is first called,
|
|
44
|
-
// we need to double escape them
|
|
45
|
-
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
46
|
-
|
|
47
63
|
// Normalize posix paths into OS compatible paths (e.g.: foo/bar -> foo\bar)
|
|
48
64
|
// This is necessary otherwise it will always fail with ENOENT in those cases
|
|
49
65
|
parsed.command = path.normalize(parsed.command);
|
|
50
66
|
|
|
51
67
|
// Escape command & arguments
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
// Batch files need a different escaping strategy, see `lib/util/escape.js` for more information
|
|
69
|
+
if (isBatchFile(parsed, commandFile)) {
|
|
70
|
+
// Run the batch file by its resolved path, if it was found, otherwise as written
|
|
71
|
+
// When a batch file is run through a quoted name found in PATH, e.g. `"gradle"`, cmd.exe sets `%~dp0` to
|
|
72
|
+
// the current directory instead of the batch file's directory, which breaks batch files that use it to
|
|
73
|
+
// find their own files, such as Gradle's
|
|
74
|
+
parsed.command = escape.batchCommand(commandFile ? path.normalize(commandFile) : parsed.command);
|
|
75
|
+
parsed.args = parsed.args.map((arg) => escape.batchArgument(arg));
|
|
76
|
+
} else {
|
|
77
|
+
parsed.command = escape.command(parsed.command);
|
|
78
|
+
parsed.args = parsed.args.map((arg) => escape.argument(arg));
|
|
79
|
+
}
|
|
54
80
|
|
|
55
81
|
const shellCommand = [parsed.command].concat(parsed.args).join(' ');
|
|
56
82
|
|
|
57
|
-
|
|
83
|
+
// Enable command extensions with /e:on, needed by the %cd:~,% trick, as they might be disabled in the registry
|
|
84
|
+
// Disable delayed expansion with /v:off, otherwise !VAR! would be expanded if enabled in the registry
|
|
85
|
+
parsed.args = ['/d', '/e:on', '/v:off', '/s', '/c', `"${shellCommand}"`];
|
|
58
86
|
parsed.command = process.env.comspec || 'cmd.exe';
|
|
59
87
|
parsed.options.windowsVerbatimArguments = true; // Tell node's spawn that the arguments are already escaped
|
|
60
88
|
}
|