@rogatio/cli 6.16.3 → 6.16.5
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/dist/editor/index.js +5 -1
- package/dist/node/index.js +228 -96
- package/package.json +1 -1
package/dist/editor/index.js
CHANGED
|
@@ -531,7 +531,11 @@ function createAIAssistPanel(_container, _editor, onApply, onClose, onSend) {
|
|
|
531
531
|
`;
|
|
532
532
|
const addDetail = (label, value) => {
|
|
533
533
|
const detail = document.createElement("div");
|
|
534
|
-
|
|
534
|
+
const labelEl = document.createElement("span");
|
|
535
|
+
labelEl.style.color = "#666";
|
|
536
|
+
labelEl.textContent = `${label}:`;
|
|
537
|
+
detail.appendChild(labelEl);
|
|
538
|
+
detail.appendChild(document.createTextNode(` ${value}`));
|
|
535
539
|
ruleDetails.appendChild(detail);
|
|
536
540
|
};
|
|
537
541
|
if (rule.source) {
|
package/dist/node/index.js
CHANGED
|
@@ -2200,19 +2200,21 @@ function compileProject(value) {
|
|
|
2200
2200
|
};
|
|
2201
2201
|
}
|
|
2202
2202
|
}
|
|
2203
|
-
function
|
|
2204
|
-
|
|
2205
|
-
if (regex === null) return false;
|
|
2206
|
-
if (source.key === "url") {
|
|
2207
|
-
return regex.test(url);
|
|
2208
|
-
}
|
|
2203
|
+
function sourceMatchText(source, url) {
|
|
2204
|
+
if (source.key === "url") return url;
|
|
2209
2205
|
try {
|
|
2210
|
-
|
|
2211
|
-
return regex.test(hostname);
|
|
2206
|
+
return new URL(url).hostname;
|
|
2212
2207
|
} catch {
|
|
2213
|
-
return
|
|
2208
|
+
return null;
|
|
2214
2209
|
}
|
|
2215
2210
|
}
|
|
2211
|
+
function sourceMatches(source, url) {
|
|
2212
|
+
const regex = compileUrlRegex(source.value);
|
|
2213
|
+
if (regex === null) return false;
|
|
2214
|
+
const text = sourceMatchText(source, url);
|
|
2215
|
+
if (text === null) return false;
|
|
2216
|
+
return regex.test(text);
|
|
2217
|
+
}
|
|
2216
2218
|
var PAC_STEER_MARKER = "steer:";
|
|
2217
2219
|
function decodePacSteer(entry) {
|
|
2218
2220
|
if (!entry.startsWith(PAC_STEER_MARKER)) return null;
|
|
@@ -20073,7 +20075,7 @@ var require_x509_cjs = __commonJS({
|
|
|
20073
20075
|
var _X509Certificate_signature;
|
|
20074
20076
|
var _X509Certificate_extensions;
|
|
20075
20077
|
var _X509Certificate_publicKey;
|
|
20076
|
-
var
|
|
20078
|
+
var X509Certificate4 = class extends PemData {
|
|
20077
20079
|
get publicKey() {
|
|
20078
20080
|
if (!tslib.__classPrivateFieldGet(this, _X509Certificate_publicKey, "f")) {
|
|
20079
20081
|
tslib.__classPrivateFieldSet(this, _X509Certificate_publicKey, new PublicKey(this.asn.tbsCertificate.subjectPublicKeyInfo, this.parseOptions), "f");
|
|
@@ -20316,7 +20318,7 @@ var require_x509_cjs = __commonJS({
|
|
|
20316
20318
|
}
|
|
20317
20319
|
};
|
|
20318
20320
|
_X509Certificate_tbs = /* @__PURE__ */ new WeakMap(), _X509Certificate_serialNumber = /* @__PURE__ */ new WeakMap(), _X509Certificate_subjectName = /* @__PURE__ */ new WeakMap(), _X509Certificate_subject = /* @__PURE__ */ new WeakMap(), _X509Certificate_issuerName = /* @__PURE__ */ new WeakMap(), _X509Certificate_issuer = /* @__PURE__ */ new WeakMap(), _X509Certificate_notBefore = /* @__PURE__ */ new WeakMap(), _X509Certificate_notAfter = /* @__PURE__ */ new WeakMap(), _X509Certificate_signatureAlgorithm = /* @__PURE__ */ new WeakMap(), _X509Certificate_signature = /* @__PURE__ */ new WeakMap(), _X509Certificate_extensions = /* @__PURE__ */ new WeakMap(), _X509Certificate_publicKey = /* @__PURE__ */ new WeakMap();
|
|
20319
|
-
|
|
20321
|
+
X509Certificate4.NAME = "Certificate";
|
|
20320
20322
|
var _X509Certificates_options;
|
|
20321
20323
|
var X509Certificates = class extends Array {
|
|
20322
20324
|
constructor(param, options) {
|
|
@@ -20324,7 +20326,7 @@ var require_x509_cjs = __commonJS({
|
|
|
20324
20326
|
_X509Certificates_options.set(this, void 0);
|
|
20325
20327
|
if (PemData.isAsnEncoded(param)) {
|
|
20326
20328
|
this.import(param, options);
|
|
20327
|
-
} else if (param instanceof
|
|
20329
|
+
} else if (param instanceof X509Certificate4) {
|
|
20328
20330
|
this.push(param);
|
|
20329
20331
|
} else if (Array.isArray(param)) {
|
|
20330
20332
|
for (const item of param) {
|
|
@@ -20362,7 +20364,7 @@ var require_x509_cjs = __commonJS({
|
|
|
20362
20364
|
const certificates = [];
|
|
20363
20365
|
for (const item of signedData.certificates || []) {
|
|
20364
20366
|
if (item.certificate) {
|
|
20365
|
-
certificates.push(new
|
|
20367
|
+
certificates.push(new X509Certificate4(item.certificate, options));
|
|
20366
20368
|
}
|
|
20367
20369
|
}
|
|
20368
20370
|
this.clear();
|
|
@@ -20554,7 +20556,7 @@ var require_x509_cjs = __commonJS({
|
|
|
20554
20556
|
throw Error("Cannot convert ASN.1 signature value to WebCrypto format");
|
|
20555
20557
|
}
|
|
20556
20558
|
asnX509.signatureValue = asnSignature;
|
|
20557
|
-
return new
|
|
20559
|
+
return new X509Certificate4(asn1Schema.AsnConvert.serialize(asnX509));
|
|
20558
20560
|
}
|
|
20559
20561
|
};
|
|
20560
20562
|
var _X509CrlEntry_serialNumber;
|
|
@@ -20775,7 +20777,7 @@ var require_x509_cjs = __commonJS({
|
|
|
20775
20777
|
let publicKey;
|
|
20776
20778
|
const paramsKey = params.publicKey;
|
|
20777
20779
|
try {
|
|
20778
|
-
if (paramsKey instanceof
|
|
20780
|
+
if (paramsKey instanceof X509Certificate4) {
|
|
20779
20781
|
keyAlgorithm = {
|
|
20780
20782
|
...paramsKey.publicKey.algorithm,
|
|
20781
20783
|
...paramsKey.signatureAlgorithm
|
|
@@ -20979,7 +20981,7 @@ var require_x509_cjs = __commonJS({
|
|
|
20979
20981
|
exports.TextObject = TextObject;
|
|
20980
20982
|
exports.UPN = UPN;
|
|
20981
20983
|
exports.URL = URL2;
|
|
20982
|
-
exports.X509Certificate =
|
|
20984
|
+
exports.X509Certificate = X509Certificate4;
|
|
20983
20985
|
exports.X509CertificateGenerator = X509CertificateGenerator2;
|
|
20984
20986
|
exports.X509Certificates = X509Certificates;
|
|
20985
20987
|
exports.X509ChainBuilder = X509ChainBuilder;
|
|
@@ -24419,34 +24421,6 @@ async function resolveConfinedRoot(value) {
|
|
|
24419
24421
|
await directory?.close().catch(() => void 0);
|
|
24420
24422
|
}
|
|
24421
24423
|
}
|
|
24422
|
-
var MOCK_LISTENER_PREFIX = "/.rogatio/mock/";
|
|
24423
|
-
function isSingleSegment(value) {
|
|
24424
|
-
return value.length > 0 && value.length <= 2048 && value !== "." && value !== ".." && !value.includes("/") && !value.includes("\\") && !value.includes("?") && !hasControl(value);
|
|
24425
|
-
}
|
|
24426
|
-
function parseMockRedirect(rawUrl) {
|
|
24427
|
-
const queryAt = rawUrl.indexOf("?");
|
|
24428
|
-
const path2 = queryAt === -1 ? rawUrl : rawUrl.slice(0, queryAt);
|
|
24429
|
-
if (!path2.startsWith(MOCK_LISTENER_PREFIX)) return null;
|
|
24430
|
-
const rest = path2.slice(MOCK_LISTENER_PREFIX.length);
|
|
24431
|
-
const slash = rest.indexOf("/");
|
|
24432
|
-
if (slash <= 0) return null;
|
|
24433
|
-
if (rest.indexOf("/", slash + 1) !== -1) return null;
|
|
24434
|
-
let token;
|
|
24435
|
-
let digest;
|
|
24436
|
-
try {
|
|
24437
|
-
token = decodeURIComponent(rest.slice(0, slash));
|
|
24438
|
-
digest = decodeURIComponent(rest.slice(slash + 1));
|
|
24439
|
-
} catch {
|
|
24440
|
-
return null;
|
|
24441
|
-
}
|
|
24442
|
-
if (!isSingleSegment(token) || !isSingleSegment(digest)) return null;
|
|
24443
|
-
return { token, digest };
|
|
24444
|
-
}
|
|
24445
|
-
function supportedContentType(value) {
|
|
24446
|
-
if (value === void 0) return false;
|
|
24447
|
-
const mediaType = value.split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
24448
|
-
return mediaType === "application/json" || mediaType.startsWith("application/") && mediaType.endsWith("+json") || mediaType === "application/x-www-form-urlencoded" || mediaType.startsWith("text/");
|
|
24449
|
-
}
|
|
24450
24424
|
var REGEX_WORKER_SOURCE = `
|
|
24451
24425
|
const workerThreads =
|
|
24452
24426
|
typeof process.getBuiltinModule === "function"
|
|
@@ -24455,11 +24429,35 @@ const workerThreads =
|
|
|
24455
24429
|
const { parentPort } = workerThreads;
|
|
24456
24430
|
parentPort.postMessage({ type: "ready" });
|
|
24457
24431
|
parentPort.on("message", (msg) => {
|
|
24458
|
-
if (msg.type !== "replace") return;
|
|
24432
|
+
if (msg.type !== "replace" && msg.type !== "test" && msg.type !== "exec") return;
|
|
24459
24433
|
parentPort.postMessage({ id: msg.id, type: "ack" });
|
|
24460
24434
|
try {
|
|
24461
|
-
|
|
24462
|
-
|
|
24435
|
+
if (msg.type === "replace") {
|
|
24436
|
+
const out = msg.text.replace(new RegExp(msg.pattern, "gu"), msg.replacement);
|
|
24437
|
+
parentPort.postMessage({ id: msg.id, type: "result", ok: true, out });
|
|
24438
|
+
return;
|
|
24439
|
+
}
|
|
24440
|
+
const regex = new RegExp(msg.pattern);
|
|
24441
|
+
if (msg.type === "test") {
|
|
24442
|
+
parentPort.postMessage({
|
|
24443
|
+
id: msg.id,
|
|
24444
|
+
type: "result",
|
|
24445
|
+
ok: true,
|
|
24446
|
+
matched: regex.test(msg.text),
|
|
24447
|
+
});
|
|
24448
|
+
return;
|
|
24449
|
+
}
|
|
24450
|
+
const match = regex.exec(msg.text);
|
|
24451
|
+
const captures =
|
|
24452
|
+
match === null
|
|
24453
|
+
? null
|
|
24454
|
+
: match.slice(1).map((part) => (part === undefined ? null : part));
|
|
24455
|
+
parentPort.postMessage({
|
|
24456
|
+
id: msg.id,
|
|
24457
|
+
type: "result",
|
|
24458
|
+
ok: true,
|
|
24459
|
+
captures,
|
|
24460
|
+
});
|
|
24463
24461
|
} catch (err) {
|
|
24464
24462
|
parentPort.postMessage({
|
|
24465
24463
|
id: msg.id,
|
|
@@ -24475,6 +24473,7 @@ var regexWorker = null;
|
|
|
24475
24473
|
var regexWorkerBoot = null;
|
|
24476
24474
|
var nextRegexJobId = 1;
|
|
24477
24475
|
var regexWorkerBootDelayForTestsMs = 0;
|
|
24476
|
+
var failNextRegexWorkerBootForTests = false;
|
|
24478
24477
|
function discardRegexWorker(worker) {
|
|
24479
24478
|
if (regexWorker === worker) {
|
|
24480
24479
|
regexWorker = null;
|
|
@@ -24484,6 +24483,10 @@ function discardRegexWorker(worker) {
|
|
|
24484
24483
|
});
|
|
24485
24484
|
}
|
|
24486
24485
|
function bootRegexWorker() {
|
|
24486
|
+
if (failNextRegexWorkerBootForTests) {
|
|
24487
|
+
failNextRegexWorkerBootForTests = false;
|
|
24488
|
+
return Promise.reject(new Error("regex-worker-boot-failed"));
|
|
24489
|
+
}
|
|
24487
24490
|
if (regexWorker !== null) return Promise.resolve(regexWorker);
|
|
24488
24491
|
if (regexWorkerBoot !== null) return regexWorkerBoot;
|
|
24489
24492
|
const boot = new Promise((resolve12, reject) => {
|
|
@@ -24551,7 +24554,7 @@ function bootRegexWorker() {
|
|
|
24551
24554
|
});
|
|
24552
24555
|
return boot;
|
|
24553
24556
|
}
|
|
24554
|
-
function runOnRegexWorker(worker, id2, text, pattern, replacement, deadlineMs) {
|
|
24557
|
+
function runOnRegexWorker(worker, id2, type, text, pattern, replacement, deadlineMs) {
|
|
24555
24558
|
return new Promise((resolve12, reject) => {
|
|
24556
24559
|
let timer = null;
|
|
24557
24560
|
const cleanup = () => {
|
|
@@ -24572,8 +24575,15 @@ function runOnRegexWorker(worker, id2, text, pattern, replacement, deadlineMs) {
|
|
|
24572
24575
|
}
|
|
24573
24576
|
if (msg.type === "result") {
|
|
24574
24577
|
cleanup();
|
|
24575
|
-
if (msg.ok
|
|
24576
|
-
|
|
24578
|
+
if (!msg.ok) {
|
|
24579
|
+
reject(new Error(msg.error || "regex-invalid"));
|
|
24580
|
+
return;
|
|
24581
|
+
}
|
|
24582
|
+
resolve12({
|
|
24583
|
+
...typeof msg.out === "string" ? { out: msg.out } : {},
|
|
24584
|
+
...typeof msg.matched === "boolean" ? { matched: msg.matched } : {},
|
|
24585
|
+
...msg.captures !== void 0 ? { captures: msg.captures } : {}
|
|
24586
|
+
});
|
|
24577
24587
|
}
|
|
24578
24588
|
};
|
|
24579
24589
|
const onError = (error) => {
|
|
@@ -24587,23 +24597,114 @@ function runOnRegexWorker(worker, id2, text, pattern, replacement, deadlineMs) {
|
|
|
24587
24597
|
worker.on("message", onMessage);
|
|
24588
24598
|
worker.once("error", onError);
|
|
24589
24599
|
worker.once("exit", onExit);
|
|
24590
|
-
worker.postMessage({
|
|
24600
|
+
worker.postMessage({
|
|
24601
|
+
id: id2,
|
|
24602
|
+
type,
|
|
24603
|
+
text,
|
|
24604
|
+
pattern,
|
|
24605
|
+
...replacement !== void 0 ? { replacement } : {}
|
|
24606
|
+
});
|
|
24591
24607
|
});
|
|
24592
24608
|
}
|
|
24593
|
-
function
|
|
24609
|
+
function nextJobId() {
|
|
24594
24610
|
const id2 = nextRegexJobId;
|
|
24595
24611
|
nextRegexJobId += 1;
|
|
24612
|
+
return id2;
|
|
24613
|
+
}
|
|
24614
|
+
function runRegexReplace(text, pattern, replacement, deadlineMs) {
|
|
24615
|
+
const id2 = nextJobId();
|
|
24596
24616
|
return bootRegexWorker().then(
|
|
24597
|
-
(worker) => runOnRegexWorker(
|
|
24598
|
-
|
|
24599
|
-
|
|
24600
|
-
|
|
24601
|
-
|
|
24602
|
-
|
|
24603
|
-
|
|
24604
|
-
|
|
24617
|
+
(worker) => runOnRegexWorker(
|
|
24618
|
+
worker,
|
|
24619
|
+
id2,
|
|
24620
|
+
"replace",
|
|
24621
|
+
text,
|
|
24622
|
+
pattern,
|
|
24623
|
+
replacement,
|
|
24624
|
+
deadlineMs
|
|
24625
|
+
).then((result) => {
|
|
24626
|
+
if (typeof result.out !== "string") throw new Error("regex-invalid");
|
|
24627
|
+
return result.out;
|
|
24628
|
+
})
|
|
24629
|
+
);
|
|
24630
|
+
}
|
|
24631
|
+
function capturesFromWorker(captures) {
|
|
24632
|
+
if (captures === null || captures === void 0) return null;
|
|
24633
|
+
return captures.map((part) => part === null ? void 0 : part);
|
|
24634
|
+
}
|
|
24635
|
+
function runRegexTest(text, pattern, deadlineMs) {
|
|
24636
|
+
const id2 = nextJobId();
|
|
24637
|
+
return bootRegexWorker().then(
|
|
24638
|
+
(worker) => runOnRegexWorker(
|
|
24639
|
+
worker,
|
|
24640
|
+
id2,
|
|
24641
|
+
"test",
|
|
24642
|
+
text,
|
|
24643
|
+
pattern,
|
|
24644
|
+
void 0,
|
|
24645
|
+
deadlineMs
|
|
24646
|
+
).then(
|
|
24647
|
+
(result) => result.matched === true,
|
|
24648
|
+
() => false
|
|
24649
|
+
),
|
|
24650
|
+
() => false
|
|
24605
24651
|
);
|
|
24606
24652
|
}
|
|
24653
|
+
function runRegexExec(text, pattern, deadlineMs) {
|
|
24654
|
+
const id2 = nextJobId();
|
|
24655
|
+
return bootRegexWorker().then(
|
|
24656
|
+
(worker) => runOnRegexWorker(
|
|
24657
|
+
worker,
|
|
24658
|
+
id2,
|
|
24659
|
+
"exec",
|
|
24660
|
+
text,
|
|
24661
|
+
pattern,
|
|
24662
|
+
void 0,
|
|
24663
|
+
deadlineMs
|
|
24664
|
+
).then(
|
|
24665
|
+
(result) => capturesFromWorker(result.captures),
|
|
24666
|
+
() => null
|
|
24667
|
+
),
|
|
24668
|
+
() => null
|
|
24669
|
+
);
|
|
24670
|
+
}
|
|
24671
|
+
async function sourceMatchesWithinDeadline(source, url) {
|
|
24672
|
+
if (compileUrlRegex(source.value) === null) return false;
|
|
24673
|
+
const text = sourceMatchText(source, url);
|
|
24674
|
+
if (text === null) return false;
|
|
24675
|
+
return runRegexTest(text, source.value, RUNTIME_LIMITS.maxRegexDeadlineMs);
|
|
24676
|
+
}
|
|
24677
|
+
function matchUrlCapturesWithinDeadline(urlRegex, url) {
|
|
24678
|
+
return runRegexExec(url, urlRegex, RUNTIME_LIMITS.maxRegexDeadlineMs);
|
|
24679
|
+
}
|
|
24680
|
+
var MOCK_LISTENER_PREFIX = "/.rogatio/mock/";
|
|
24681
|
+
function isSingleSegment(value) {
|
|
24682
|
+
return value.length > 0 && value.length <= 2048 && value !== "." && value !== ".." && !value.includes("/") && !value.includes("\\") && !value.includes("?") && !hasControl(value);
|
|
24683
|
+
}
|
|
24684
|
+
function parseMockRedirect(rawUrl) {
|
|
24685
|
+
const queryAt = rawUrl.indexOf("?");
|
|
24686
|
+
const path2 = queryAt === -1 ? rawUrl : rawUrl.slice(0, queryAt);
|
|
24687
|
+
if (!path2.startsWith(MOCK_LISTENER_PREFIX)) return null;
|
|
24688
|
+
const rest = path2.slice(MOCK_LISTENER_PREFIX.length);
|
|
24689
|
+
const slash = rest.indexOf("/");
|
|
24690
|
+
if (slash <= 0) return null;
|
|
24691
|
+
if (rest.indexOf("/", slash + 1) !== -1) return null;
|
|
24692
|
+
let token;
|
|
24693
|
+
let digest;
|
|
24694
|
+
try {
|
|
24695
|
+
token = decodeURIComponent(rest.slice(0, slash));
|
|
24696
|
+
digest = decodeURIComponent(rest.slice(slash + 1));
|
|
24697
|
+
} catch {
|
|
24698
|
+
return null;
|
|
24699
|
+
}
|
|
24700
|
+
if (!isSingleSegment(token) || !isSingleSegment(digest)) return null;
|
|
24701
|
+
return { token, digest };
|
|
24702
|
+
}
|
|
24703
|
+
function supportedContentType(value) {
|
|
24704
|
+
if (value === void 0) return false;
|
|
24705
|
+
const mediaType = value.split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
24706
|
+
return mediaType === "application/json" || mediaType.startsWith("application/") && mediaType.endsWith("+json") || mediaType === "application/x-www-form-urlencoded" || mediaType.startsWith("text/");
|
|
24707
|
+
}
|
|
24607
24708
|
async function rewriteRequestBody(input, action, captureContext) {
|
|
24608
24709
|
if (!supportedContentType(input.contentType)) {
|
|
24609
24710
|
return failure("runtime.request-body-unsupported-mime-type");
|
|
@@ -24630,7 +24731,7 @@ async function rewriteRequestBody(input, action, captureContext) {
|
|
|
24630
24731
|
}
|
|
24631
24732
|
outputText = action.body;
|
|
24632
24733
|
if (captureContext !== void 0) {
|
|
24633
|
-
const captures =
|
|
24734
|
+
const captures = await matchUrlCapturesWithinDeadline(
|
|
24634
24735
|
captureContext.urlRegex,
|
|
24635
24736
|
captureContext.url
|
|
24636
24737
|
);
|
|
@@ -24870,7 +24971,7 @@ async function rewriteResponseBody(input, replacements, replaceAction, captureCo
|
|
|
24870
24971
|
if (captureContext === void 0) {
|
|
24871
24972
|
text = replaceAction.body;
|
|
24872
24973
|
} else {
|
|
24873
|
-
const captures =
|
|
24974
|
+
const captures = await matchUrlCapturesWithinDeadline(
|
|
24874
24975
|
captureContext.urlRegex,
|
|
24875
24976
|
captureContext.url
|
|
24876
24977
|
);
|
|
@@ -24882,8 +24983,12 @@ async function rewriteResponseBody(input, replacements, replaceAction, captureCo
|
|
|
24882
24983
|
for (const entry of replacements) {
|
|
24883
24984
|
if (entry.pattern.length === 0 || entry.pattern.length > LIMITS.maxResponseBodyPatternLength || entry.replacement.length > LIMITS.maxResponseBodyReplacementLength)
|
|
24884
24985
|
return failure("runtime.size-limit");
|
|
24885
|
-
|
|
24886
|
-
|
|
24986
|
+
text = await runRegexReplace(
|
|
24987
|
+
text,
|
|
24988
|
+
entry.pattern,
|
|
24989
|
+
entry.replacement,
|
|
24990
|
+
RUNTIME_LIMITS.maxRegexDeadlineMs
|
|
24991
|
+
);
|
|
24887
24992
|
if (new TextEncoder().encode(text).byteLength > RUNTIME_LIMITS.maxResponseBodyBytes)
|
|
24888
24993
|
return failure("runtime.size-limit");
|
|
24889
24994
|
}
|
|
@@ -24898,8 +25003,11 @@ async function rewriteResponseBody(input, replacements, replaceAction, captureCo
|
|
|
24898
25003
|
}
|
|
24899
25004
|
};
|
|
24900
25005
|
}
|
|
24901
|
-
function replaceResponseBody(body, contentType, captureContext) {
|
|
24902
|
-
const captures = captureContext === void 0 ? [] :
|
|
25006
|
+
async function replaceResponseBody(body, contentType, captureContext) {
|
|
25007
|
+
const captures = captureContext === void 0 ? [] : await matchUrlCapturesWithinDeadline(
|
|
25008
|
+
captureContext.urlRegex,
|
|
25009
|
+
captureContext.url
|
|
25010
|
+
);
|
|
24903
25011
|
if (captureContext !== void 0 && captures === null) {
|
|
24904
25012
|
return failure("runtime.url-capture-mismatch");
|
|
24905
25013
|
}
|
|
@@ -24921,7 +25029,7 @@ async function fetchAndRewriteAuthorizedResponse(operation, action, options = {}
|
|
|
24921
25029
|
const response = await fetchAuthorized(operation, options);
|
|
24922
25030
|
if (!response.ok) return response;
|
|
24923
25031
|
const contentType = responseHeader(response.value.headers, "content-type");
|
|
24924
|
-
const transformed = isReplaceAction(action) ? replaceResponseBody(
|
|
25032
|
+
const transformed = isReplaceAction(action) ? await replaceResponseBody(
|
|
24925
25033
|
action.body,
|
|
24926
25034
|
contentType,
|
|
24927
25035
|
operation.sourceValue === void 0 ? void 0 : { url: operation.target, urlRegex: operation.sourceValue }
|
|
@@ -24991,7 +25099,7 @@ function projectHasRule(project, groupId, ruleId) {
|
|
|
24991
25099
|
function isBodyOperation(operation) {
|
|
24992
25100
|
return operation.kind === "request-body" || operation.kind === "response-body";
|
|
24993
25101
|
}
|
|
24994
|
-
function revalidateAuthority(project, operations, request) {
|
|
25102
|
+
async function revalidateAuthority(project, operations, request) {
|
|
24995
25103
|
const projectSnap = snapshotOwnData3(project);
|
|
24996
25104
|
if (!projectSnap.valid) return { allowed: false, reason: "project-invalid" };
|
|
24997
25105
|
const opsSnap = snapshotOwnData3(operations);
|
|
@@ -25012,7 +25120,7 @@ function revalidateAuthority(project, operations, request) {
|
|
|
25012
25120
|
return { allowed: false, reason: "project-inconsistent" };
|
|
25013
25121
|
}
|
|
25014
25122
|
const matcher = operation.matcher;
|
|
25015
|
-
if (!
|
|
25123
|
+
if (!await sourceMatchesWithinDeadline(matcher.source, request.url)) {
|
|
25016
25124
|
return { allowed: false, reason: "url-mismatch" };
|
|
25017
25125
|
}
|
|
25018
25126
|
const requestOrigin = originOf(request.url);
|
|
@@ -25052,18 +25160,19 @@ function revalidateAuthority(project, operations, request) {
|
|
|
25052
25160
|
function isBodyOp(op) {
|
|
25053
25161
|
return op.kind === "request-body" || op.kind === "response-body";
|
|
25054
25162
|
}
|
|
25055
|
-
function matcherMatches(op, url, method) {
|
|
25056
|
-
if (!
|
|
25163
|
+
async function matcherMatches(op, url, method) {
|
|
25164
|
+
if (!await sourceMatchesWithinDeadline(op.matcher.source, url))
|
|
25165
|
+
return false;
|
|
25057
25166
|
if (op.matcher.method !== void 0 && op.matcher.method !== method.toUpperCase()) {
|
|
25058
25167
|
return false;
|
|
25059
25168
|
}
|
|
25060
25169
|
return true;
|
|
25061
25170
|
}
|
|
25062
|
-
function pickHighest(operations, kind, url, method) {
|
|
25171
|
+
async function pickHighest(operations, kind, url, method) {
|
|
25063
25172
|
let best = null;
|
|
25064
25173
|
for (const op of operations) {
|
|
25065
25174
|
if (!isBodyOp(op) || op.kind !== kind) continue;
|
|
25066
|
-
if (!matcherMatches(op, url, method)) continue;
|
|
25175
|
+
if (!await matcherMatches(op, url, method)) continue;
|
|
25067
25176
|
if (best === null || op.matcher.priority > best.matcher.priority || op.matcher.priority === best.matcher.priority && op.ruleId.localeCompare(best.ruleId) < 0) {
|
|
25068
25177
|
best = op;
|
|
25069
25178
|
}
|
|
@@ -25432,17 +25541,21 @@ function initiatorFromHeaders(headers, targetUrl) {
|
|
|
25432
25541
|
return void 0;
|
|
25433
25542
|
}
|
|
25434
25543
|
}
|
|
25435
|
-
function authorizeOp(policy, op, url, method, headers) {
|
|
25544
|
+
async function authorizeOp(policy, op, url, method, headers) {
|
|
25436
25545
|
const resourceType = op.matcher.resourceTypes[0];
|
|
25437
25546
|
const initiator = initiatorFromHeaders(headers, url);
|
|
25438
|
-
const decision = revalidateAuthority(
|
|
25439
|
-
|
|
25440
|
-
|
|
25441
|
-
|
|
25442
|
-
|
|
25443
|
-
|
|
25444
|
-
|
|
25445
|
-
|
|
25547
|
+
const decision = await revalidateAuthority(
|
|
25548
|
+
policy.project,
|
|
25549
|
+
policy.operations,
|
|
25550
|
+
{
|
|
25551
|
+
groupId: op.groupId,
|
|
25552
|
+
ruleId: op.ruleId,
|
|
25553
|
+
url,
|
|
25554
|
+
method,
|
|
25555
|
+
...initiator !== void 0 ? { initiator } : {},
|
|
25556
|
+
...resourceType !== void 0 ? { resourceType } : {}
|
|
25557
|
+
}
|
|
25558
|
+
);
|
|
25446
25559
|
return decision.allowed;
|
|
25447
25560
|
}
|
|
25448
25561
|
async function startInterceptProxy(options = {}) {
|
|
@@ -25490,13 +25603,13 @@ async function startInterceptProxy(options = {}) {
|
|
|
25490
25603
|
}
|
|
25491
25604
|
const method = (req.method ?? "GET").toUpperCase();
|
|
25492
25605
|
const active = policy;
|
|
25493
|
-
const requestOp = active === null ? null : pickHighest(
|
|
25606
|
+
const requestOp = active === null ? null : await pickHighest(
|
|
25494
25607
|
active.operations,
|
|
25495
25608
|
"request-body",
|
|
25496
25609
|
targetUrl,
|
|
25497
25610
|
method
|
|
25498
25611
|
);
|
|
25499
|
-
const responseOp = active === null ? null : pickHighest(
|
|
25612
|
+
const responseOp = active === null ? null : await pickHighest(
|
|
25500
25613
|
active.operations,
|
|
25501
25614
|
"response-body",
|
|
25502
25615
|
targetUrl,
|
|
@@ -25516,7 +25629,13 @@ async function startInterceptProxy(options = {}) {
|
|
|
25516
25629
|
}
|
|
25517
25630
|
let requestBody = bodyResult.body;
|
|
25518
25631
|
if (needsRequestBody && requestOp !== null && active !== null) {
|
|
25519
|
-
if (!authorizeOp(
|
|
25632
|
+
if (!await authorizeOp(
|
|
25633
|
+
active,
|
|
25634
|
+
requestOp,
|
|
25635
|
+
targetUrl,
|
|
25636
|
+
method,
|
|
25637
|
+
req.headers
|
|
25638
|
+
)) {
|
|
25520
25639
|
} else {
|
|
25521
25640
|
const rewritten = await rewriteRequestBody(
|
|
25522
25641
|
{
|
|
@@ -25565,7 +25684,13 @@ async function startInterceptProxy(options = {}) {
|
|
|
25565
25684
|
let responseBody = upstream.body;
|
|
25566
25685
|
if (responseOp !== null && active !== null) {
|
|
25567
25686
|
if (responseBody.byteLength > RUNTIME_LIMITS.maxResponseBodyBytes) {
|
|
25568
|
-
} else if (!authorizeOp(
|
|
25687
|
+
} else if (!await authorizeOp(
|
|
25688
|
+
active,
|
|
25689
|
+
responseOp,
|
|
25690
|
+
targetUrl,
|
|
25691
|
+
method,
|
|
25692
|
+
req.headers
|
|
25693
|
+
)) {
|
|
25569
25694
|
} else {
|
|
25570
25695
|
const action = responseOp.responseBody;
|
|
25571
25696
|
const isReplace = "mode" in action && action.mode === "replace";
|
|
@@ -25689,7 +25814,10 @@ async function startInterceptProxy(options = {}) {
|
|
|
25689
25814
|
const operation = active.operations.find(
|
|
25690
25815
|
(op) => op.kind === "response-body" && op.ruleId === parsed.ruleId
|
|
25691
25816
|
);
|
|
25692
|
-
if (operation === void 0 || !
|
|
25817
|
+
if (operation === void 0 || !await sourceMatchesWithinDeadline(
|
|
25818
|
+
operation.matcher.source,
|
|
25819
|
+
parsed.originalUrl
|
|
25820
|
+
)) {
|
|
25693
25821
|
res.writeHead(404);
|
|
25694
25822
|
res.end();
|
|
25695
25823
|
return;
|
|
@@ -25705,15 +25833,19 @@ async function startInterceptProxy(options = {}) {
|
|
|
25705
25833
|
res.end();
|
|
25706
25834
|
return;
|
|
25707
25835
|
}
|
|
25708
|
-
const allowed = revalidateAuthority(
|
|
25709
|
-
|
|
25710
|
-
|
|
25711
|
-
|
|
25712
|
-
|
|
25713
|
-
|
|
25714
|
-
|
|
25715
|
-
|
|
25716
|
-
|
|
25836
|
+
const allowed = await revalidateAuthority(
|
|
25837
|
+
active.project,
|
|
25838
|
+
active.operations,
|
|
25839
|
+
{
|
|
25840
|
+
groupId: operation.groupId,
|
|
25841
|
+
ruleId: operation.ruleId,
|
|
25842
|
+
url: parsed.originalUrl,
|
|
25843
|
+
target,
|
|
25844
|
+
method: "GET",
|
|
25845
|
+
initiator: initiatorFromHeaders(req.headers, parsed.originalUrl) ?? new URL(target).origin,
|
|
25846
|
+
resourceType: operation.matcher.resourceTypes[0]
|
|
25847
|
+
}
|
|
25848
|
+
);
|
|
25717
25849
|
if (!allowed.allowed) {
|
|
25718
25850
|
res.writeHead(403);
|
|
25719
25851
|
res.end();
|
package/package.json
CHANGED