From 52278e63f813af1d776c43e0a99feb528f3f654d Mon Sep 17 00:00:00 2001 From: Tristan Bastian Date: Thu, 21 Mar 2024 22:42:17 +0100 Subject: [PATCH] feat(microservice): add custom user-agent header (#45) should allow to e.g. block requests coming from the proxy by identifying them via the user-agent --- backend/Dockerfile | 2 +- backend/src/header-adjustment.ts | 5 +++++ backend/tsconfig.json | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 3d90d38..66f31d5 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -32,6 +32,6 @@ FROM node:18-alpine As production COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules COPY --chown=node:node --from=build /usr/src/app/dist ./dist -CMD [ "node", "dist/index.js" ] +CMD [ "node", "dist/src/index.js" ] EXPOSE 80 \ No newline at end of file diff --git a/backend/src/header-adjustment.ts b/backend/src/header-adjustment.ts index 6eb874d..5d3ccb7 100644 --- a/backend/src/header-adjustment.ts +++ b/backend/src/header-adjustment.ts @@ -1,5 +1,6 @@ import { ConnectionDetails } from "./connection-details"; import { IncomingHttpHeaders } from "http"; +import { name, version } from "../package.json"; export class HeaderAdjustment { private static headersToRemove = ["authorization"]; @@ -12,6 +13,10 @@ export class HeaderAdjustment { continue; } + if (key.toLowerCase() === "user-agent") { + keysToAdd[key] = `${name}/${version}`; + } + if (!key.startsWith(this.headerPrefix)) { continue; } diff --git a/backend/tsconfig.json b/backend/tsconfig.json index b7ffa00..46addf8 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -13,7 +13,8 @@ "isolatedModules": false, "esModuleInterop": true, "skipLibCheck": true, - "strict": false + "strict": false, + "resolveJsonModule": true }, "include": ["**/*.d.ts", "**/*.ts"], "exclude": ["node_modules"]