edgeaegis 2026.10.1
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/LICENSE +202 -0
- package/NOTICE +10 -0
- package/README.md +215 -0
- package/config.yml +29 -0
- package/origin/cloudflare/app/config.yml +2 -0
- package/origin/cloudflare/app/index.js +4 -0
- package/origin/edgeone/app/config.yml +2 -0
- package/origin/edgeone/app/index.js +4 -0
- package/origin/esa/app/config.yml +2 -0
- package/origin/esa/app/index.js +4 -0
- package/origin/netlify/app/config.yml +2 -0
- package/origin/netlify/app/index.js +4 -0
- package/origin/vercel/app/config.yml +2 -0
- package/origin/vercel/app/index.js +4 -0
- package/package.json +123 -0
- package/respond/403.html +2 -0
- package/respond/403.json +1 -0
- package/rules/allowlist.yml +2 -0
- package/rules/emergency.conf +4 -0
- package/rules/local.conf +2 -0
- package/rules/seclang-bundle.json +360 -0
- package/rules/seclang-upstreams.json +14 -0
- package/rules/setup.conf +15 -0
- package/secret/credentials.example.yml +7 -0
- package/secret/relay-server.example.yml +10 -0
- package/tools/.build/scr/adapters/cloudflare/runtime.d.ts +18 -0
- package/tools/.build/scr/adapters/cloudflare/runtime.js +16 -0
- package/tools/.build/scr/adapters/cloudflare/runtime.js.map +1 -0
- package/tools/.build/scr/adapters/cloudflare/worker.js +25 -0
- package/tools/.build/scr/adapters/edgeone/worker.js +7 -0
- package/tools/.build/scr/adapters/esa/worker.js +5 -0
- package/tools/.build/scr/adapters/forward.d.ts +4 -0
- package/tools/.build/scr/adapters/forward.js +25 -0
- package/tools/.build/scr/adapters/forward.js.map +1 -0
- package/tools/.build/scr/adapters/handler.js +39 -0
- package/tools/.build/scr/adapters/ingress.d.ts +10 -0
- package/tools/.build/scr/adapters/ingress.js +62 -0
- package/tools/.build/scr/adapters/ingress.js.map +1 -0
- package/tools/.build/scr/adapters/netlify/worker.js +7 -0
- package/tools/.build/scr/adapters/runtime.d.ts +33 -0
- package/tools/.build/scr/adapters/runtime.js +50 -0
- package/tools/.build/scr/adapters/runtime.js.map +1 -0
- package/tools/.build/scr/adapters/vercel/worker.js +7 -0
- package/tools/.build/scr/cli/config.d.ts +2 -0
- package/tools/.build/scr/cli/config.js +23 -0
- package/tools/.build/scr/cli/config.js.map +1 -0
- package/tools/.build/scr/cli/deployment.d.ts +15 -0
- package/tools/.build/scr/cli/deployment.js +108 -0
- package/tools/.build/scr/cli/deployment.js.map +1 -0
- package/tools/.build/scr/cli/init.d.ts +2 -0
- package/tools/.build/scr/cli/init.js +62 -0
- package/tools/.build/scr/cli/init.js.map +1 -0
- package/tools/.build/scr/cli/main.d.ts +2 -0
- package/tools/.build/scr/cli/main.js +99 -0
- package/tools/.build/scr/cli/main.js.map +1 -0
- package/tools/.build/scr/cli/relay-serve.d.ts +1 -0
- package/tools/.build/scr/cli/relay-serve.js +48 -0
- package/tools/.build/scr/cli/relay-serve.js.map +1 -0
- package/tools/.build/scr/cli/responses.d.ts +2 -0
- package/tools/.build/scr/cli/responses.js +31 -0
- package/tools/.build/scr/cli/responses.js.map +1 -0
- package/tools/.build/scr/cli/serve.d.ts +1 -0
- package/tools/.build/scr/cli/serve.js +132 -0
- package/tools/.build/scr/cli/serve.js.map +1 -0
- package/tools/.build/scr/config.d.ts +39 -0
- package/tools/.build/scr/config.js +89 -0
- package/tools/.build/scr/config.js.map +1 -0
- package/tools/.build/scr/core/types.d.ts +27 -0
- package/tools/.build/scr/core/types.js +34 -0
- package/tools/.build/scr/core/types.js.map +1 -0
- package/tools/.build/scr/core/version.d.ts +1 -0
- package/tools/.build/scr/core/version.js +3 -0
- package/tools/.build/scr/core/version.js.map +1 -0
- package/tools/.build/scr/http-boundary/index.d.ts +19 -0
- package/tools/.build/scr/http-boundary/index.js +173 -0
- package/tools/.build/scr/http-boundary/index.js.map +1 -0
- package/tools/.build/scr/http-boundary/json.d.ts +2 -0
- package/tools/.build/scr/http-boundary/json.js +90 -0
- package/tools/.build/scr/http-boundary/json.js.map +1 -0
- package/tools/.build/scr/origin/relay.d.ts +20 -0
- package/tools/.build/scr/origin/relay.js +221 -0
- package/tools/.build/scr/origin/relay.js.map +1 -0
- package/tools/.build/scr/origin/replay-node.d.ts +8 -0
- package/tools/.build/scr/origin/replay-node.js +36 -0
- package/tools/.build/scr/origin/replay-node.js.map +1 -0
- package/tools/.build/scr/origin/types.d.ts +18 -0
- package/tools/.build/scr/origin/types.js +2 -0
- package/tools/.build/scr/origin/types.js.map +1 -0
- package/tools/.build/scr/runtime/allowlist.d.ts +21 -0
- package/tools/.build/scr/runtime/allowlist.js +84 -0
- package/tools/.build/scr/runtime/allowlist.js.map +1 -0
- package/tools/.build/scr/runtime/browser-cache.d.ts +7 -0
- package/tools/.build/scr/runtime/browser-cache.js +50 -0
- package/tools/.build/scr/runtime/browser-cache.js.map +1 -0
- package/tools/.build/scr/runtime/error-pages.d.ts +10 -0
- package/tools/.build/scr/runtime/error-pages.js +72 -0
- package/tools/.build/scr/runtime/error-pages.js.map +1 -0
- package/tools/.build/scr/runtime/index.d.ts +54 -0
- package/tools/.build/scr/runtime/index.js +355 -0
- package/tools/.build/scr/runtime/index.js.map +1 -0
- package/tools/.build/scr/runtime/node.d.ts +3 -0
- package/tools/.build/scr/runtime/node.js +97 -0
- package/tools/.build/scr/runtime/node.js.map +1 -0
- package/tools/.build/scr/runtime/proxy.d.ts +12 -0
- package/tools/.build/scr/runtime/proxy.js +177 -0
- package/tools/.build/scr/runtime/proxy.js.map +1 -0
- package/tools/.build/scr/runtime/stream.d.ts +8 -0
- package/tools/.build/scr/runtime/stream.js +72 -0
- package/tools/.build/scr/runtime/stream.js.map +1 -0
- package/tools/.build/scr/seclang/body.d.ts +13 -0
- package/tools/.build/scr/seclang/body.js +109 -0
- package/tools/.build/scr/seclang/body.js.map +1 -0
- package/tools/.build/scr/seclang/bytes.d.ts +5 -0
- package/tools/.build/scr/seclang/bytes.js +38 -0
- package/tools/.build/scr/seclang/bytes.js.map +1 -0
- package/tools/.build/scr/seclang/index.d.ts +166 -0
- package/tools/.build/scr/seclang/index.js +1519 -0
- package/tools/.build/scr/seclang/index.js.map +1 -0
- package/tools/.build/scr/seclang/json.d.ts +2 -0
- package/tools/.build/scr/seclang/json.js +87 -0
- package/tools/.build/scr/seclang/json.js.map +1 -0
- package/tools/.build/scr/seclang/libinjection.d.ts +9 -0
- package/tools/.build/scr/seclang/libinjection.js +59 -0
- package/tools/.build/scr/seclang/libinjection.js.map +1 -0
- package/tools/.build/scr/seclang/node.d.ts +22 -0
- package/tools/.build/scr/seclang/node.js +113 -0
- package/tools/.build/scr/seclang/node.js.map +1 -0
- package/tools/.build/scr/seclang/pcre2.d.ts +23 -0
- package/tools/.build/scr/seclang/pcre2.js +153 -0
- package/tools/.build/scr/seclang/pcre2.js.map +1 -0
- package/tools/.build/scr/seclang/sources.d.ts +6 -0
- package/tools/.build/scr/seclang/sources.js +59 -0
- package/tools/.build/scr/seclang/sources.js.map +1 -0
- package/tools/.build/scr/seclang/state.d.ts +17 -0
- package/tools/.build/scr/seclang/state.js +53 -0
- package/tools/.build/scr/seclang/state.js.map +1 -0
- package/tools/.build/scr/seclang/syntax.d.ts +9 -0
- package/tools/.build/scr/seclang/syntax.js +74 -0
- package/tools/.build/scr/seclang/syntax.js.map +1 -0
- package/tools/.build/scr/seclang/transforms.d.ts +3 -0
- package/tools/.build/scr/seclang/transforms.js +157 -0
- package/tools/.build/scr/seclang/transforms.js.map +1 -0
- package/tools/.build/scr/seclang/unicode.d.ts +2 -0
- package/tools/.build/scr/seclang/unicode.js +19 -0
- package/tools/.build/scr/seclang/unicode.js.map +1 -0
- package/tools/.build/scr/seclang/vendor/LIBINJECTION-LICENSE +33 -0
- package/tools/.build/scr/seclang/vendor/PCRE2-NOTICE +47 -0
- package/tools/.build/scr/seclang/vendor/PCRE2-WRAPPER-LICENSE +21 -0
- package/tools/.build/scr/seclang/vendor/UNICODE-DATA-NOTICE +6 -0
- package/tools/.build/scr/seclang/vendor/libinjection.json +7 -0
- package/tools/.build/scr/seclang/vendor/libinjection.wasm +0 -0
- package/tools/.build/scr/seclang/vendor/pcre2.json +7 -0
- package/tools/.build/scr/seclang/vendor/pcre2.wasm +0 -0
- package/tools/.build/scr/seclang/vendor/unicode.json +378 -0
- package/tools/build-platform.mjs +199 -0
- package/tools/platform-command.mjs +59 -0
- package/tools/sync-native-seclang.mjs +155 -0
- package/tools/verify-full-crs.mjs +118 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { requireInteger, ShieldError } from "../core/types.js";
|
|
2
|
+
import { applyBrowserCache } from "./browser-cache.js";
|
|
3
|
+
import { protectStream } from "./stream.js";
|
|
4
|
+
const hop = [
|
|
5
|
+
"connection",
|
|
6
|
+
"keep-alive",
|
|
7
|
+
"proxy-authenticate",
|
|
8
|
+
"proxy-authorization",
|
|
9
|
+
"te",
|
|
10
|
+
"trailer",
|
|
11
|
+
"transfer-encoding",
|
|
12
|
+
"upgrade",
|
|
13
|
+
"host",
|
|
14
|
+
"content-length",
|
|
15
|
+
];
|
|
16
|
+
export function createProxy(options) {
|
|
17
|
+
const origin = new URL(options.origin);
|
|
18
|
+
const loopback = ["127.0.0.1", "[::1]"].includes(origin.hostname);
|
|
19
|
+
if (origin.username ||
|
|
20
|
+
origin.password ||
|
|
21
|
+
origin.pathname !== "/" ||
|
|
22
|
+
origin.search ||
|
|
23
|
+
origin.hash ||
|
|
24
|
+
!options.allowedOrigins.includes(origin.origin))
|
|
25
|
+
throw new Error("Origin must be an exact allowlisted origin without credentials/path/query");
|
|
26
|
+
if (origin.protocol !== "https:" &&
|
|
27
|
+
!(options.allowLoopbackHttp && loopback && origin.protocol === "http:"))
|
|
28
|
+
throw new Error("Upstream TLS required (only explicit loopback development HTTP allowed)");
|
|
29
|
+
const originToken = options.originToken;
|
|
30
|
+
if (!/^[\x21-\x7e]{32,2048}$/.test(originToken))
|
|
31
|
+
throw new Error("Origin authentication token must contain 32..2048 visible ASCII characters");
|
|
32
|
+
const timeout = requireInteger(options.timeoutMs ?? 10000, 1, 120000, "proxy timeout");
|
|
33
|
+
const maxResponse = requireInteger(options.maxResponseBytes ?? 16777216, 1, 1073741824, "response bytes");
|
|
34
|
+
const transport = options.fetch ?? fetch;
|
|
35
|
+
let consecutiveFailures = 0;
|
|
36
|
+
let openUntil = 0;
|
|
37
|
+
return async (incoming, url, path, body, onComplete = () => { }, websocket = false, browserCache) => {
|
|
38
|
+
if (Date.now() < openUntil)
|
|
39
|
+
throw new ShieldError("origin-circuit-open", 503);
|
|
40
|
+
const target = new URL(origin);
|
|
41
|
+
target.pathname = path;
|
|
42
|
+
target.search = url.search;
|
|
43
|
+
if (target.origin !== origin.origin)
|
|
44
|
+
throw new ShieldError("origin-allowlist", 502);
|
|
45
|
+
const headers = new Headers(incoming.headers);
|
|
46
|
+
for (const name of [...headers.keys()]) {
|
|
47
|
+
if (hop.includes(name) ||
|
|
48
|
+
name === "forwarded" ||
|
|
49
|
+
name === "x-real-ip" ||
|
|
50
|
+
name.startsWith("x-forwarded-") ||
|
|
51
|
+
name.startsWith("cf-") ||
|
|
52
|
+
name.startsWith("x-vercel-") ||
|
|
53
|
+
name.startsWith("x-nf-") ||
|
|
54
|
+
name.startsWith("x-shield-") ||
|
|
55
|
+
name.startsWith("x-edgeshield-"))
|
|
56
|
+
headers.delete(name);
|
|
57
|
+
}
|
|
58
|
+
headers.set("x-shield-origin-auth", originToken);
|
|
59
|
+
headers.set("accept-encoding", "identity");
|
|
60
|
+
if (websocket)
|
|
61
|
+
headers.set("upgrade", "websocket");
|
|
62
|
+
const abort = new AbortController();
|
|
63
|
+
let completed = false;
|
|
64
|
+
const timer = setTimeout(() => {
|
|
65
|
+
abort.abort();
|
|
66
|
+
cleanup();
|
|
67
|
+
}, timeout);
|
|
68
|
+
const abortFromClient = () => abort.abort();
|
|
69
|
+
incoming.signal.addEventListener("abort", abortFromClient, { once: true });
|
|
70
|
+
const cleanup = () => {
|
|
71
|
+
if (completed)
|
|
72
|
+
return;
|
|
73
|
+
completed = true;
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
incoming.signal.removeEventListener("abort", abortFromClient);
|
|
76
|
+
onComplete();
|
|
77
|
+
};
|
|
78
|
+
try {
|
|
79
|
+
const init = {
|
|
80
|
+
method: incoming.method,
|
|
81
|
+
headers,
|
|
82
|
+
redirect: "manual",
|
|
83
|
+
signal: abort.signal,
|
|
84
|
+
};
|
|
85
|
+
if (!["GET", "HEAD"].includes(incoming.method) && body.length)
|
|
86
|
+
init.body = body;
|
|
87
|
+
if (incoming.signal.aborted)
|
|
88
|
+
throw new ShieldError("client-aborted", 408);
|
|
89
|
+
const upstream = await transport(target, init);
|
|
90
|
+
if (abort.signal.aborted) {
|
|
91
|
+
void upstream.body?.cancel().catch(() => { });
|
|
92
|
+
throw new ShieldError("origin-timeout-or-abort", 504);
|
|
93
|
+
}
|
|
94
|
+
if (upstream.status >= 500) {
|
|
95
|
+
consecutiveFailures++;
|
|
96
|
+
if (consecutiveFailures >= 5)
|
|
97
|
+
openUntil = Date.now() + 5000;
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
consecutiveFailures = 0;
|
|
101
|
+
if (upstream.status === 101) {
|
|
102
|
+
const socket = upstream
|
|
103
|
+
.webSocket;
|
|
104
|
+
cleanup();
|
|
105
|
+
if (!websocket || !socket) {
|
|
106
|
+
try {
|
|
107
|
+
socket?.close(1008);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
/* Already closed. */
|
|
111
|
+
}
|
|
112
|
+
throw new ShieldError("unexpected-origin-upgrade", 502);
|
|
113
|
+
}
|
|
114
|
+
const output = new Headers(upstream.headers);
|
|
115
|
+
for (const name of [...output.keys()])
|
|
116
|
+
if (["server", "x-powered-by"].includes(name) ||
|
|
117
|
+
name.startsWith("x-shield-") ||
|
|
118
|
+
name.startsWith("x-edgeshield-"))
|
|
119
|
+
output.delete(name);
|
|
120
|
+
output.set("cache-control", "no-store");
|
|
121
|
+
// Preserve the native socket. SecLang inspects this response before ownership is transferred.
|
|
122
|
+
return new Response(null, {
|
|
123
|
+
status: 101,
|
|
124
|
+
headers: output,
|
|
125
|
+
webSocket: socket,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// Avoid fetch implementations disagreeing about automatic decompression.
|
|
129
|
+
if (upstream.headers.has("content-encoding") &&
|
|
130
|
+
upstream.headers.get("content-encoding") !== "identity") {
|
|
131
|
+
void upstream.body?.cancel().catch(() => { });
|
|
132
|
+
throw new ShieldError("unexpected-origin-encoding", 502);
|
|
133
|
+
}
|
|
134
|
+
const responseHeaders = new Headers(upstream.headers);
|
|
135
|
+
for (const token of (responseHeaders.get("connection") ?? "").split(","))
|
|
136
|
+
if (token.trim())
|
|
137
|
+
responseHeaders.delete(token.trim());
|
|
138
|
+
for (const name of [...responseHeaders.keys()])
|
|
139
|
+
if (hop.includes(name) ||
|
|
140
|
+
["server", "x-powered-by"].includes(name) ||
|
|
141
|
+
name.startsWith("x-shield-"))
|
|
142
|
+
responseHeaders.delete(name);
|
|
143
|
+
applyBrowserCache(incoming, upstream, responseHeaders, browserCache);
|
|
144
|
+
if (!upstream.body ||
|
|
145
|
+
incoming.method === "HEAD" ||
|
|
146
|
+
[204, 205, 304].includes(upstream.status)) {
|
|
147
|
+
cleanup();
|
|
148
|
+
void upstream.body?.cancel().catch(() => { });
|
|
149
|
+
return new Response(null, { status: upstream.status, headers: responseHeaders });
|
|
150
|
+
}
|
|
151
|
+
const stream = protectStream(upstream.body, {
|
|
152
|
+
maxBytes: maxResponse,
|
|
153
|
+
idleTimeoutMs: timeout,
|
|
154
|
+
signal: abort.signal,
|
|
155
|
+
abort: () => abort.abort(),
|
|
156
|
+
complete: cleanup,
|
|
157
|
+
});
|
|
158
|
+
return new Response(stream, {
|
|
159
|
+
status: upstream.status,
|
|
160
|
+
statusText: upstream.statusText,
|
|
161
|
+
headers: responseHeaders,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
const wasAborted = abort.signal.aborted;
|
|
166
|
+
cleanup();
|
|
167
|
+
abort.abort();
|
|
168
|
+
consecutiveFailures++;
|
|
169
|
+
if (consecutiveFailures >= 5)
|
|
170
|
+
openUntil = Date.now() + 5000;
|
|
171
|
+
if (error instanceof ShieldError)
|
|
172
|
+
throw error;
|
|
173
|
+
throw new ShieldError(wasAborted ? "origin-timeout-or-abort" : "origin-unavailable", wasAborted ? 504 : 502);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../../scr/runtime/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAA2B,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAW5C,MAAM,GAAG,GAAG;IACV,YAAY;IACZ,YAAY;IACZ,oBAAoB;IACpB,qBAAqB;IACrB,IAAI;IACJ,SAAS;IACT,mBAAmB;IACnB,SAAS;IACT,MAAM;IACN,gBAAgB;CACjB,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,OAAqB;IAC/C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClE,IACE,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,QAAQ,KAAK,GAAG;QACvB,MAAM,CAAC,MAAM;QACb,MAAM,CAAC,IAAI;QACX,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;QAE/C,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,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AAQ,CAAC,IAAI,EAAE;gBAC1C,QAAQ,EAAE,WAAW;gBACrB,aAAa,EAAE,OAAO;gBACtB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE;gBAC1B,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAC;YACH,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;gBAC1B,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,OAAO,EAAE,eAAe;aACzB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;YACxC,OAAO,EAAE,CAAC;YACV,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,mBAAmB,EAAE,CAAC;YACtB,IAAI,mBAAmB,IAAI,CAAC;gBAAE,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;YAC5D,IAAI,KAAK,YAAY,WAAW;gBAAE,MAAM,KAAK,CAAC;YAC9C,MAAM,IAAI,WAAW,CACnB,UAAU,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,oBAAoB,EAC7D,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CACvB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** No fixed total deadline: continuously progressing transfers can last longer than headerTimeoutMs. */
|
|
2
|
+
export declare function protectStream(input: ReadableStream<Uint8Array>, options: {
|
|
3
|
+
maxBytes: number;
|
|
4
|
+
idleTimeoutMs: number;
|
|
5
|
+
signal: AbortSignal;
|
|
6
|
+
abort: () => void;
|
|
7
|
+
complete: () => void;
|
|
8
|
+
}): ReadableStream<Uint8Array>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { requireInteger } from "../core/types.js";
|
|
2
|
+
/** No fixed total deadline: continuously progressing transfers can last longer than headerTimeoutMs. */
|
|
3
|
+
export function protectStream(input, options) {
|
|
4
|
+
requireInteger(options.maxBytes, 1, 1073741824, "stream bytes");
|
|
5
|
+
requireInteger(options.idleTimeoutMs, 1, 300000, "stream idle deadline");
|
|
6
|
+
const reader = input.getReader();
|
|
7
|
+
let controller;
|
|
8
|
+
let timer;
|
|
9
|
+
let ended = false;
|
|
10
|
+
let total = 0;
|
|
11
|
+
const cleanup = () => {
|
|
12
|
+
if (ended)
|
|
13
|
+
return;
|
|
14
|
+
ended = true;
|
|
15
|
+
if (timer)
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
options.signal.removeEventListener("abort", interrupted);
|
|
18
|
+
options.complete();
|
|
19
|
+
};
|
|
20
|
+
const fail = (error) => {
|
|
21
|
+
if (ended)
|
|
22
|
+
return;
|
|
23
|
+
cleanup();
|
|
24
|
+
options.abort();
|
|
25
|
+
void reader.cancel(error).catch(() => { });
|
|
26
|
+
controller.error(error);
|
|
27
|
+
};
|
|
28
|
+
const interrupted = () => fail(new Error("origin-stream-aborted"));
|
|
29
|
+
const reset = () => {
|
|
30
|
+
if (timer)
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
timer = setTimeout(() => fail(new Error("origin-stream-idle-timeout")), options.idleTimeoutMs);
|
|
33
|
+
};
|
|
34
|
+
return new ReadableStream({
|
|
35
|
+
start(c) {
|
|
36
|
+
controller = c;
|
|
37
|
+
options.signal.addEventListener("abort", interrupted, { once: true });
|
|
38
|
+
if (options.signal.aborted)
|
|
39
|
+
interrupted();
|
|
40
|
+
else
|
|
41
|
+
reset();
|
|
42
|
+
},
|
|
43
|
+
async pull(c) {
|
|
44
|
+
if (ended)
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
const item = await reader.read();
|
|
48
|
+
if (ended)
|
|
49
|
+
return;
|
|
50
|
+
if (item.done) {
|
|
51
|
+
cleanup();
|
|
52
|
+
c.close();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
total += item.value.byteLength;
|
|
56
|
+
if (total > options.maxBytes)
|
|
57
|
+
throw new Error("origin-response-too-large");
|
|
58
|
+
reset();
|
|
59
|
+
c.enqueue(item.value);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
fail(error instanceof Error ? error : new Error("stream-failure"));
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
cancel(reason) {
|
|
66
|
+
cleanup();
|
|
67
|
+
options.abort();
|
|
68
|
+
return reader.cancel(reason);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../scr/runtime/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,wGAAwG;AACxG,MAAM,UAAU,aAAa,CAC3B,KAAiC,EACjC,OAMC;IAED,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;IAChE,cAAc,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IACjC,IAAI,UAAuD,CAAC;IAC5D,IAAI,KAAgD,CAAC;IACrD,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,IAAI,KAAK;YAAE,OAAO;QAClB,KAAK,GAAG,IAAI,CAAC;QACb,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OA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AI,EAAE,CAAC;oBACd,OAAO,EAAE,CAAC;oBACV,CAAC,CAAC,KAAK,EAAE,CAAC;oBACV,OAAO;gBACT,CAAC;gBACD,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;gBAC/B,IAAI,KAAK,GAAG,OAAO,CAAC,QAAQ;oBAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;gBAC3E,KAAK,EAAE,CAAC;gBACR,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;QACD,MAAM,CAAC,MAAM;YACX,OAAO,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type BodyProcessor = "" | "URLENCODED" | "JSON" | "XML" | "MULTIPART";
|
|
2
|
+
export declare function bodyProcessor(headers: Headers): BodyProcessor;
|
|
3
|
+
export declare function parseBody(body: string, headers: Headers, processor: BodyProcessor, bytes?: Uint8Array, maxBodyBytes?: number): {
|
|
4
|
+
args: [string, string][];
|
|
5
|
+
files: {
|
|
6
|
+
name: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
size: number;
|
|
9
|
+
}[];
|
|
10
|
+
partHeaders: [string, string][];
|
|
11
|
+
xml: import("@xmldom/xmldom").Document | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare function xmlValues(document: NonNullable<ReturnType<typeof parseBody>["xml"]>, expression: string): [string, string][];
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { DOMParser } from "@xmldom/xmldom";
|
|
2
|
+
import xpath from "xpath";
|
|
3
|
+
import { formEntries, fromOctets, utf8Bytes } from "./bytes.js";
|
|
4
|
+
import { jsonArguments } from "./json.js";
|
|
5
|
+
export function bodyProcessor(headers) {
|
|
6
|
+
const type = headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
7
|
+
if (type === "application/x-www-form-urlencoded")
|
|
8
|
+
return "URLENCODED";
|
|
9
|
+
if (type === "application/json")
|
|
10
|
+
return "JSON";
|
|
11
|
+
if (type === "text/xml" || type === "application/xml")
|
|
12
|
+
return "XML";
|
|
13
|
+
if (type === "multipart/form-data")
|
|
14
|
+
return "MULTIPART";
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
export function parseBody(body, headers, processor, bytes, maxBodyBytes = 2 * 1024 * 1024) {
|
|
18
|
+
const args = [];
|
|
19
|
+
const files = [];
|
|
20
|
+
const partHeaders = [];
|
|
21
|
+
let xml;
|
|
22
|
+
if ((bytes?.length ?? new TextEncoder().encode(body).length) > maxBodyBytes)
|
|
23
|
+
throw new Error("SecLang body limit exceeded");
|
|
24
|
+
const binary = bytes ? fromOctets(bytes) : utf8Bytes(body);
|
|
25
|
+
if (processor === "URLENCODED")
|
|
26
|
+
args.push(...formEntries(binary, true));
|
|
27
|
+
if (bytes && (processor === "JSON" || processor === "XML"))
|
|
28
|
+
body = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
29
|
+
if (processor === "JSON" && body) {
|
|
30
|
+
args.push(...jsonArguments(body).map(([path, value]) => [utf8Bytes(path), utf8Bytes(value)]));
|
|
31
|
+
}
|
|
32
|
+
if (processor === "XML" && body) {
|
|
33
|
+
if (/<!DOCTYPE|<!ENTITY/i.test(body))
|
|
34
|
+
throw new Error("XML DTD/entities are disabled");
|
|
35
|
+
xml = new DOMParser({
|
|
36
|
+
onError: (_level, message) => {
|
|
37
|
+
throw new Error(`Invalid XML: ${message}`);
|
|
38
|
+
},
|
|
39
|
+
}).parseFromString(body, "application/xml");
|
|
40
|
+
}
|
|
41
|
+
if (processor === "MULTIPART" && binary) {
|
|
42
|
+
body = binary;
|
|
43
|
+
const type = headers.get("content-type") ?? "";
|
|
44
|
+
const boundary = /(?:^|;)\s*boundary=(?:"([^"\r\n]+)"|([^;\s]+))/i.exec(type);
|
|
45
|
+
const token = boundary?.[1] ?? boundary?.[2];
|
|
46
|
+
if (!token || token.length > 70 || !/^[\x20-\x7e]+$/.test(token))
|
|
47
|
+
throw new Error("Invalid multipart boundary");
|
|
48
|
+
const escaped = token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
49
|
+
const delimiters = [];
|
|
50
|
+
for (const match of body.matchAll(new RegExp(`(?:^|\\r?\\n)--${escaped}(--)?[ \\t]*(?:\\r?\\n|$)`, "g"))) {
|
|
51
|
+
delimiters.push(match);
|
|
52
|
+
if (delimiters.length > 129)
|
|
53
|
+
throw new Error("Multipart part limit exceeded");
|
|
54
|
+
if (match[1])
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
if (!delimiters.length || !delimiters.at(-1)?.[1])
|
|
58
|
+
throw new Error("Malformed multipart body");
|
|
59
|
+
for (let i = 0; i < delimiters.length - 1; i++) {
|
|
60
|
+
const opening = delimiters[i], next = delimiters[i + 1];
|
|
61
|
+
const part = body.slice(opening.index + opening[0].length, next.index);
|
|
62
|
+
const separator = /\r?\n\r?\n/.exec(part), end = separator?.index ?? -1;
|
|
63
|
+
if (end < 0 || end > 16384)
|
|
64
|
+
throw new Error("Invalid multipart part headers");
|
|
65
|
+
const lines = part.slice(0, end).split(/\r?\n/);
|
|
66
|
+
const disposition = lines.find((line) => /^content-disposition:/i.test(line));
|
|
67
|
+
if (lines.filter((line) => /^content-disposition:/i.test(line)).length !== 1)
|
|
68
|
+
throw new Error("Ambiguous multipart disposition");
|
|
69
|
+
const parameter = (name) => {
|
|
70
|
+
const pattern = name === "name"
|
|
71
|
+
? /(?:^|;)\s*name=(?:"((?:\\.|[^"\\\r\n])*)"|([^;\s]*))/i
|
|
72
|
+
: /(?:^|;)\s*filename=(?:"((?:\\.|[^"\\\r\n])*)"|([^;\s]*))/i;
|
|
73
|
+
const match = pattern.exec(disposition ?? "");
|
|
74
|
+
return match ? (match[1] ?? match[2] ?? "").replace(/\\(["\\])/g, "$1") : undefined;
|
|
75
|
+
};
|
|
76
|
+
const name = parameter("name");
|
|
77
|
+
if (name === undefined)
|
|
78
|
+
throw new Error("Multipart field name missing");
|
|
79
|
+
const filename = parameter("filename");
|
|
80
|
+
for (const line of lines) {
|
|
81
|
+
if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+:[^\0\r\n]*$/.test(line))
|
|
82
|
+
throw new Error("Invalid multipart header");
|
|
83
|
+
partHeaders.push([name, line]);
|
|
84
|
+
}
|
|
85
|
+
const content = part.slice(end + separator[0].length);
|
|
86
|
+
if (filename !== undefined)
|
|
87
|
+
files.push({
|
|
88
|
+
name,
|
|
89
|
+
filename,
|
|
90
|
+
size: content.length,
|
|
91
|
+
});
|
|
92
|
+
else
|
|
93
|
+
args.push([name, content]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { args, files, partHeaders, xml };
|
|
97
|
+
}
|
|
98
|
+
export function xmlValues(document, expression) {
|
|
99
|
+
const result = xpath.select(expression, document);
|
|
100
|
+
if (!Array.isArray(result))
|
|
101
|
+
return [[expression, String(result)]];
|
|
102
|
+
return result.map((value, index) => [
|
|
103
|
+
String(index),
|
|
104
|
+
typeof value === "object" && value !== null
|
|
105
|
+
? (value.textContent ?? "")
|
|
106
|
+
: String(value),
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../../../scr/seclang/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,MAAM,OAA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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function utf8Bytes(value: string): string;
|
|
2
|
+
export declare function fromOctets(bytes: Uint8Array): string;
|
|
3
|
+
export declare function octets(value: string): Uint8Array;
|
|
4
|
+
export declare const asciiLower: (value: string) => string;
|
|
5
|
+
export declare function formEntries(value: string, binary?: boolean): [string, string][];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Internal SecLang strings represent octets, including NUL and invalid UTF-8. */
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
export function utf8Bytes(value) {
|
|
4
|
+
// ASCII already has exactly the required octets, including embedded NUL.
|
|
5
|
+
if (!/[^\x00-\x7f]/.test(value))
|
|
6
|
+
return value;
|
|
7
|
+
return fromOctets(encoder.encode(value));
|
|
8
|
+
}
|
|
9
|
+
export function fromOctets(bytes) {
|
|
10
|
+
let result = "";
|
|
11
|
+
for (let i = 0; i < bytes.length; i += 8192)
|
|
12
|
+
result += String.fromCharCode(...bytes.subarray(i, i + 8192));
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
export function octets(value) {
|
|
16
|
+
const result = new Uint8Array(value.length);
|
|
17
|
+
for (let i = 0; i < value.length; i++) {
|
|
18
|
+
const code = value.charCodeAt(i);
|
|
19
|
+
if (code > 255)
|
|
20
|
+
throw new Error("SecLang byte string contains a non-byte character");
|
|
21
|
+
result[i] = code;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
export const asciiLower = (value) => value.replace(/[A-Z]+/g, (part) => part.toLowerCase());
|
|
26
|
+
export function formEntries(value, binary = false) {
|
|
27
|
+
if (!value)
|
|
28
|
+
return [];
|
|
29
|
+
return (binary ? value : utf8Bytes(value))
|
|
30
|
+
.split("&")
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.map((part) => {
|
|
33
|
+
const at = part.indexOf("=");
|
|
34
|
+
const decode = (v) => v.replace(/%([\da-f]{2})|\+/gi, (all, hex) => hex ? String.fromCharCode(Number.parseInt(hex, 16)) : all === "+" ? " " : all);
|
|
35
|
+
return [decode(at < 0 ? part : part.slice(0, at)), decode(at < 0 ? "" : part.slice(at + 1))];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../../scr/seclang/bytes.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,yEAAyE;IACzE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3C,CAAC;AACD,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI;QACzC,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAChE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,IAAI,GAAG,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,m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,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/F,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EdgeAegis's first-party SecLang state machine (no ModSecurity process).
|
|
3
|
+
* Compiles native rules, source includes and data into executable transaction instructions.
|
|
4
|
+
* Data is a Request-like object or real Web Request; no I/O occurs while executing.
|
|
5
|
+
*/
|
|
6
|
+
import type { InjectionDetectors } from "./libinjection.js";
|
|
7
|
+
import type { SecLangRegex, SecLangRegexBackend } from "./pcre2.js";
|
|
8
|
+
import { type SecLangSourceOptions } from "./sources.js";
|
|
9
|
+
import { CollectionStore } from "./state.js";
|
|
10
|
+
export { createInjectionDetectors } from "./libinjection.js";
|
|
11
|
+
export type { SecLangRegexBackend } from "./pcre2.js";
|
|
12
|
+
export { createPCRE2Backend, PCRE2Error } from "./pcre2.js";
|
|
13
|
+
export declare function splitActions(source: any): string[];
|
|
14
|
+
/** Compile an entire file; strict mode prevents using a partial CRS policy as a full WAF. */
|
|
15
|
+
export interface CompileSecLangOptions extends SecLangSourceOptions {
|
|
16
|
+
now?: () => number;
|
|
17
|
+
requestBodyLimit?: number;
|
|
18
|
+
phraseFiles?: Record<string, string[]>;
|
|
19
|
+
strict?: boolean;
|
|
20
|
+
regexBackend?: SecLangRegexBackend;
|
|
21
|
+
detectors?: InjectionDetectors;
|
|
22
|
+
}
|
|
23
|
+
export declare function compileSecLang(source: any, { phraseFiles, strict, regexBackend, detectors, fileName, files, requestBodyLimit, now, }?: CompileSecLangOptions): {
|
|
24
|
+
instructions: ({
|
|
25
|
+
type: string;
|
|
26
|
+
name: string | undefined;
|
|
27
|
+
line: number;
|
|
28
|
+
} | {
|
|
29
|
+
type: string;
|
|
30
|
+
selectors: {
|
|
31
|
+
negative: any;
|
|
32
|
+
count: any;
|
|
33
|
+
name: any;
|
|
34
|
+
key: any;
|
|
35
|
+
keyRegex: SecLangRegex | undefined;
|
|
36
|
+
foldedKey: string | undefined;
|
|
37
|
+
}[];
|
|
38
|
+
operator: {
|
|
39
|
+
op: string;
|
|
40
|
+
operand: string;
|
|
41
|
+
negated: any;
|
|
42
|
+
regex: SecLangRegex | undefined;
|
|
43
|
+
phrases: string[] | undefined;
|
|
44
|
+
dynamic: any;
|
|
45
|
+
detectors: any;
|
|
46
|
+
ranges: any;
|
|
47
|
+
networks: any;
|
|
48
|
+
dynamicRegexBackend: any;
|
|
49
|
+
} | undefined;
|
|
50
|
+
actions: {
|
|
51
|
+
phase: undefined;
|
|
52
|
+
transformations: never[];
|
|
53
|
+
changes: never[];
|
|
54
|
+
controls: never[];
|
|
55
|
+
initializers: never[];
|
|
56
|
+
effects: never[];
|
|
57
|
+
tags: never[];
|
|
58
|
+
log: boolean;
|
|
59
|
+
audit: boolean;
|
|
60
|
+
};
|
|
61
|
+
unconditional: boolean;
|
|
62
|
+
line: number;
|
|
63
|
+
file: string | undefined;
|
|
64
|
+
})[];
|
|
65
|
+
phaseInstructions: Map<number, ({
|
|
66
|
+
type: string;
|
|
67
|
+
name: string | undefined;
|
|
68
|
+
line: number;
|
|
69
|
+
} | {
|
|
70
|
+
type: string;
|
|
71
|
+
selectors: {
|
|
72
|
+
negative: any;
|
|
73
|
+
count: any;
|
|
74
|
+
name: any;
|
|
75
|
+
key: any;
|
|
76
|
+
keyRegex: SecLangRegex | undefined;
|
|
77
|
+
foldedKey: string | undefined;
|
|
78
|
+
}[];
|
|
79
|
+
operator: {
|
|
80
|
+
op: string;
|
|
81
|
+
operand: string;
|
|
82
|
+
negated: any;
|
|
83
|
+
regex: SecLangRegex | undefined;
|
|
84
|
+
phrases: string[] | undefined;
|
|
85
|
+
dynamic: any;
|
|
86
|
+
detectors: any;
|
|
87
|
+
ranges: any;
|
|
88
|
+
networks: any;
|
|
89
|
+
dynamicRegexBackend: any;
|
|
90
|
+
} | undefined;
|
|
91
|
+
actions: {
|
|
92
|
+
phase: undefined;
|
|
93
|
+
transformations: never[];
|
|
94
|
+
changes: never[];
|
|
95
|
+
controls: never[];
|
|
96
|
+
initializers: never[];
|
|
97
|
+
effects: never[];
|
|
98
|
+
tags: never[];
|
|
99
|
+
log: boolean;
|
|
100
|
+
audit: boolean;
|
|
101
|
+
};
|
|
102
|
+
unconditional: boolean;
|
|
103
|
+
line: number;
|
|
104
|
+
file: string | undefined;
|
|
105
|
+
})[]>;
|
|
106
|
+
unsupported: ({
|
|
107
|
+
line: any;
|
|
108
|
+
file: any;
|
|
109
|
+
reason: any;
|
|
110
|
+
rule: any;
|
|
111
|
+
} | {
|
|
112
|
+
line: number;
|
|
113
|
+
reason: string;
|
|
114
|
+
rule: any;
|
|
115
|
+
})[];
|
|
116
|
+
supportedRules: number;
|
|
117
|
+
sourceRules: number;
|
|
118
|
+
components: (string | undefined)[];
|
|
119
|
+
requestBodyLimit: number;
|
|
120
|
+
unicodeMap: Map<number, number>;
|
|
121
|
+
settings: {
|
|
122
|
+
engine: string;
|
|
123
|
+
requestBodyAccess: boolean;
|
|
124
|
+
responseBodyAccess: boolean;
|
|
125
|
+
removedIds: never[];
|
|
126
|
+
};
|
|
127
|
+
now: () => number;
|
|
128
|
+
collections: CollectionStore;
|
|
129
|
+
dispose: () => void;
|
|
130
|
+
readonly disposed: boolean;
|
|
131
|
+
};
|
|
132
|
+
/** Evaluate request phases with per-transaction TX state and deterministic order. */
|
|
133
|
+
export interface SecLangTransaction {
|
|
134
|
+
tx: Map<string, string | number>;
|
|
135
|
+
matchedVars: [string, string][];
|
|
136
|
+
uniqueId: string;
|
|
137
|
+
[key: string]: unknown;
|
|
138
|
+
}
|
|
139
|
+
export interface ExecuteSecLangOptions {
|
|
140
|
+
tx?: Record<string, string | number>;
|
|
141
|
+
phases?: number[];
|
|
142
|
+
anomalyThreshold?: number;
|
|
143
|
+
shouldSkip?: ((id: string) => boolean) | undefined;
|
|
144
|
+
transaction?: SecLangTransaction;
|
|
145
|
+
}
|
|
146
|
+
export declare function executeSecLang(program: any, request: any, { tx: inputTx, phases, anomalyThreshold, shouldSkip, transaction, }?: ExecuteSecLangOptions): {
|
|
147
|
+
blocked: boolean;
|
|
148
|
+
status: number;
|
|
149
|
+
matched: any[];
|
|
150
|
+
events: {
|
|
151
|
+
id: any;
|
|
152
|
+
phase: number;
|
|
153
|
+
log: any;
|
|
154
|
+
audit: any;
|
|
155
|
+
message: any;
|
|
156
|
+
logdata: any;
|
|
157
|
+
truncated: boolean;
|
|
158
|
+
severity: any;
|
|
159
|
+
tags: any;
|
|
160
|
+
}[];
|
|
161
|
+
score: number;
|
|
162
|
+
tx: {
|
|
163
|
+
[k: string]: string | number;
|
|
164
|
+
};
|
|
165
|
+
transaction: SecLangTransaction;
|
|
166
|
+
};
|