Fix: Reject literal dots and slashes in pathname

This commit is contained in:
2026-02-17 19:51:50 -08:00
parent a045461df4
commit f7232b61e6

View File

@@ -8,17 +8,19 @@ export async function onRequest(context) {
return env.ASSETS.fetch(request);
}
// Reject literal dots and slashes (bot probes like info.php or wp-admin/setup-config.php)
// We check the raw pathname (excluding leading slash and trailing slashes) to allow encoded dots (%2E) and slashes (%2F)
const rawQueryPart = url.pathname.slice(1).replace(/\/+$/, "");
if (rawQueryPart.includes(".") || rawQueryPart.includes("/")) {
const badReq = new Request(new URL("/bad.webp", url.origin));
return env.ASSETS.fetch(badReq);
}
const query = normalizeQuery(path);
if (!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
if (query.length > 200) {
return jsonResponse(400, { error: "Query too long (max 200 characters)" });