2024-12-18 20:42:40 +01:00
|
|
|
import { createMiddleware } from "hono/factory";
|
2024-12-30 18:00:23 +01:00
|
|
|
import { ApiError } from "~/classes/errors/api-error";
|
2024-05-29 02:59:49 +02:00
|
|
|
import { config } from "~/packages/config-manager";
|
2024-05-06 10:19:42 +02:00
|
|
|
|
|
|
|
|
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)) {
|
2024-12-30 18:00:23 +01:00
|
|
|
throw new ApiError(403, "Forbidden");
|
2024-05-06 10:19:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await next();
|
|
|
|
|
});
|