Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import type { MiddlewareHandler } from "astro";

const ALLOW = new Set(["GET", "HEAD", "POST"]);
const ALLOW = new Set(["GET", "HEAD"]);

export const onRequest: MiddlewareHandler = async (context, next) => {
const method = context.request.method.toUpperCase();
const pathname = new URL(context.request.url).pathname;

if (
(pathname === "/api/v1/monitoring/pull-check" || pathname === "/api/v1/monitoring/ingest") &&
method === "POST"
) {
const res = await next();
res.headers.set("X-Frame-Options", "DENY");
res.headers.set("X-Content-Type-Options", "nosniff");
res.headers.set("Referrer-Policy", "no-referrer");
res.headers.set("Permissions-Policy", "geolocation=(), microphone=(), camera=()");
res.headers.set(
"Content-Security-Policy",
"default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self'; base-uri 'none'; frame-ancestors 'none'"
);
res.headers.delete("Set-Cookie");
const ct = res.headers.get("Content-Type") ?? "";
if (ct.includes("text/html")) {
res.headers.set("Cache-Control", "public, max-age=15, stale-while-revalidate=60");
}
return res;
}

// Read-only hard gate (no control plane)
if (!ALLOW.has(method)) {
Expand Down Expand Up @@ -32,6 +54,4 @@ export const onRequest: MiddlewareHandler = async (context, next) => {
}

return res;
};


};