mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
17 lines
504 B
TypeScript
17 lines
504 B
TypeScript
import { errorResponse } from "@response";
|
|
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 errorResponse("Forbidden", 403);
|
|
}
|
|
}
|
|
|
|
await next();
|
|
});
|