Feat: Reject queries with slashes, serve bad.webp

This commit is contained in:
2026-02-15 09:02:54 -08:00
parent 509a1d7269
commit e5b167d731

View File

@@ -4,7 +4,7 @@ export async function onRequest(context) {
const path = params.path?.join("/") || ""; const path = params.path?.join("/") || "";
// Serve static assets for root or standard files // Serve static assets for root or standard files
if (!path || path === "index.html" || path === "favicon.ico" || path === "robots.txt" || path === "limit.webp") { if (!path || path === "index.html" || path === "favicon.ico" || path === "robots.txt" || path === "limit.webp" || path === "bad.webp") {
return env.ASSETS.fetch(request); return env.ASSETS.fetch(request);
} }
@@ -13,6 +13,12 @@ export async function onRequest(context) {
return jsonResponse(400, { error: "Empty query" }); return jsonResponse(400, { error: "Empty query" });
} }
// Reject queries containing slashes (bot probes like wp-admin/setup-config.php)
if (query.includes("/")) {
const badReq = new Request(new URL("/bad.webp", url.origin));
return env.ASSETS.fetch(badReq);
}
// Max query length: 200 chars after normalization // Max query length: 200 chars after normalization
if (query.length > 200) { if (query.length > 200) {
return jsonResponse(400, { error: "Query too long (max 200 characters)" }); return jsonResponse(400, { error: "Query too long (max 200 characters)" });