feat: implement R4 production hardening

- Add configurable ingestion batch item limits
- Improve client serialization and sanitization
- Add graceful handling for corrupt GZIP partitions in data API
- Expand admin session token scope
- Update project documentation for R4 status
This commit is contained in:
Team Dark Devil committed 2026-11-21 22:15:32 +06:00
1 parent 8132087085
commit ae9b554189
59 files changed
+16879 -1074

No files matched your search

+19 -11
View File
@@ -1,4 +1,5 @@
import crypto from "node:crypto";
import { validateOutboundUrlAsync } from "@/core/Security/ssrfGuard";
export type WebhookAlertEventType =
| "DISK_SPACE_LOW"
@@ -30,6 +31,7 @@ export interface WebhookDispatchResult {
ok: boolean;
skipped?: boolean;
reason?: string;
code?: string;
status?: number;
error?: string;
}
@@ -106,21 +108,17 @@ export async function dispatchWebhookAlertAsync(
};
}
let parsedUrl: URL;
try {
parsedUrl = new URL(webhookUrl);
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
return {
ok: false,
error: "Webhook URL must use http:// or https://.",
};
}
} catch {
const ssrfCheck = await validateOutboundUrlAsync(webhookUrl, {
fieldName: "Webhook URL",
});
if (!ssrfCheck.allowed || !ssrfCheck.url) {
return {
ok: false,
error: "Webhook URL is not a valid URL.",
code: ssrfCheck.code || "SSRF_BLOCKED_HOST",
error: ssrfCheck.error || "Webhook URL is not allowed.",
};
}
const parsedUrl = ssrfCheck.url;
const dedupeKey = `${payload.event}:${payload.clientId || "global"}`;
const cooldownMs = Math.max(0, (Number(config.cooldownSec) || 300) * 1000);
@@ -156,9 +154,19 @@ export async function dispatchWebhookAlertAsync(
headers,
body: bodyStr,
cache: "no-store",
redirect: "manual",
signal: AbortSignal.timeout(timeoutMs),
});
if (res.status >= 300 && res.status < 400) {
return {
ok: false,
code: "SSRF_BLOCKED_HOST",
status: res.status,
error: `Webhook endpoint attempted an unsupported HTTP ${res.status} redirect.`,
};
}
if (!res.ok) {
if (!options?.bypassCooldown) {
// Keep cooldown entry so failing webhooks don't DDOS a broken upstream endpoint