mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat(api): ✨ Add safeguard for incorrectly configured proxies
This commit is contained in:
parent
7a591a024e
commit
c28628ebb3
4 changed files with 58 additions and 4 deletions
17
middlewares/url-check.ts
Normal file
17
middlewares/url-check.ts
Normal 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();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue