mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
16 lines
472 B
TypeScript
16 lines
472 B
TypeScript
import { createMiddleware } from "hono/factory";
|
|
import { config } from "~/packages/config-manager";
|
|
|
|
export const agentBans = createMiddleware(async (context, next) => {
|
|
// Check for banned user agents (regex)
|
|
const ua = context.req.header("user-agent") ?? "";
|
|
|
|
for (const agent of config.http.banned_user_agents) {
|
|
if (new RegExp(agent).test(ua)) {
|
|
return context.json({ error: "Forbidden" }, 403);
|
|
}
|
|
}
|
|
|
|
await next();
|
|
});
|