diff options
Diffstat (limited to 'lib/app.ts')
| -rw-r--r-- | lib/app.ts | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -13,6 +13,7 @@ import dns from "node:dns"; import * as path from "path"; import { jwtStrategy } from "$lib/auth"; +import { adminIpAllowed, clientIp } from "$lib/adminip"; declare module "fastify" { interface FastifyRequest { @@ -246,4 +247,13 @@ app.setNotFoundHandler((_, reply) => reply.code(404).type("text/html").send("Not Found"), ); +// Admin sessions only from config.adminIps (lib/adminip.ts). preHandler runs +// after each route's auth, so req.user is set for every authenticated route. +app.addHook("preHandler", async (req: any, reply) => { + if (req.user?.username && req.user.username === config.admin && !adminIpAllowed(req)) { + req.log?.warn?.({ ip: clientIp(req), url: req.url }, "admin session refused: address not allowed"); + return reply.code(403).send("forbidden"); + } +}); + export default app; |
