Skip to content

Commit 7fb7004

Browse files
committed
feat: Add X-Powered-By + ContentSecurityPolicy headers to all responses
1 parent 56f2b5e commit 7fb7004

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/webserver/FastifyWebServer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ export default class FastifyWebServer {
4040
.code(500)
4141
.send({ error: 'Internal Server Error' });
4242
});
43-
this.fastify.addHook('onResponse', (request: FastifyRequest, reply: FastifyReply): void => {
43+
this.fastify.addHook('onRequest', (_request: FastifyRequest, reply: FastifyReply, done: Fastify.HookHandlerDoneFunction): void => {
44+
reply
45+
.header('X-Powered-By', 'fastify')
46+
.header('Content-Security-Policy', `default-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none';`);
47+
done();
48+
});
49+
this.fastify.addHook('onResponse', (request: FastifyRequest, reply: FastifyReply, done: Fastify.HookHandlerDoneFunction): void => {
4450
if (!['/metrics', '/status', '/favicon.ico'].includes(request.originalUrl)) {
4551
this.metrics.collectIncomingHttpRequest(request.method, reply.statusCode);
4652
}
53+
done();
4754
});
4855

4956
this.setupRouters(routers);

0 commit comments

Comments
 (0)