feat(api): Add safeguard for incorrectly configured proxies

This commit is contained in:
Jesse Wierzbinski 2024-05-17 09:38:38 -10:00
parent 7a591a024e
commit c28628ebb3
No known key found for this signature in database
4 changed files with 58 additions and 4 deletions

17
middlewares/url-check.ts Normal file
View file

@ -0,0 +1,17 @@
import { errorResponse } from "@response";
import { createMiddleware } from "hono/factory";
import { config } from "~packages/config-manager";
export const urlCheck = createMiddleware(async (context, next) => {
// Check that request URL matches base_url
const baseUrl = new URL(config.http.base_url);
if (new URL(context.req.url).origin !== baseUrl.origin) {
return errorResponse(
`Request URL ${context.req.url} does not match base URL ${baseUrl.origin}`,
400,
);
}
await next();
});