Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: webhook registration when github radar is not configured
Matheus Nogueira2d3c6b7e8bfc
diff --git a/backend/e2e-test/secret-scanning-webhooks.spec.ts b/backend/e2e-test/secret-scanning-webhooks.spec.tsnew file mode 100644index 0000000000..32ee8d6792--- /dev/null+++ b/backend/e2e-test/secret-scanning-webhooks.spec.ts@@ -0,0 +1,19 @@+// The shared test server boots without INF_APP_CONNECTION_GITHUB_RADAR_*, so these cases cover the+// unconfigured deployment. Registration used to bail out entirely when the GitHub Radar app was+// missing, which took the Bitbucket and GitLab webhooks down with it even though neither touches it.+describe("secret scanning v2 webhooks without a GitHub Radar app", () => {+ test.each([+ { provider: "bitbucket", url: "/secret-scanning/webhooks/bitbucket" },+ { provider: "gitlab", url: "/secret-scanning/webhooks/gitlab" }+ ])("registers the $provider webhook", ({ url }) => {+ expect(testServer.hasRoute({ method: "POST", url })).toBe(true);+ });++ test("does not register the github webhook", async () => {+ expect(testServer.hasRoute({ method: "POST", url: "/secret-scanning/webhooks/github" })).toBe(false);++ // 404 rather than 401: the route is absent, not merely refusing the caller.+ const res = await testServer.inject({ method: "POST", url: "/secret-scanning/webhooks/github" });+ expect(res.statusCode).toBe(404);+ });+});diff --git a/backend/src/lib/config/env.ts b/backend/src/lib/config/env.tsindex 5c69295a71..c9d38bc780 100644--- a/backend/src/lib/config/env.ts+++ b/backend/src/lib/config/env.ts@@ -691,7 +691,7 @@ const envSchema = zBoolean(data.SECRET_SCANNING_GIT_APP_ID) &&Boolean(data.SECRET_SCANNING_PRIVATE_KEY) &&Boolean(data.SECRET_SCANNING_WEBHOOK_SECRET),- isSecretScanningV2Configured:+ isGithubRadarConfigured:Boolean(data.INF_APP_CONNECTION_GITHUB_RADAR_APP_ID) &&Boolean(data.INF_APP_CONNECTION_GITHUB_RADAR_APP_PRIVATE_KEY) &&Boolean(data.INF_APP_CONNECTION_GITHUB_RADAR_APP_SLUG) &&diff --git a/backend/src/server/plugins/secret-scanner-v2.ts b/backend/src/server/plugins/secret-scanner-v2.tsindex 3c0813be32..7324aeaebc 100644--- a/backend/src/server/plugins/secret-scanner-v2.ts+++ b/backend/src/server/plugins/secret-scanner-v2.ts@@ -11,62 +11,61 @@ import { logger } from "@app/lib/logger";import { writeLimit } from "@app/server/config/rateLimiter";export const registerSecretScanningV2Webhooks = async (server: FastifyZodProvider) => {- const probotApp = (app: Probot) => {- app.on("installation.deleted", async (context) => {- const { payload } = context;- const { installation } = payload;-- await server.services.secretScanningV2.github.handleInstallationDeletedEvent(installation.id);- });-- app.on("installation", async (context) => {- const { payload } = context;- logger.info({ repositories: payload.repositories }, "Installed secret scanner to");- });-- app.on("push", async (context) => {- const { payload } = context;- await server.services.secretScanningV2.github.handlePushEvent(payload as PushEvent);- });- };-const appCfg = getConfig();- if (!appCfg.isSecretScanningV2Configured) {- logger.info("Secret Scanning V2 is not configured. Skipping registration of secret scanning v2 webhooks.");- return;- }+ if (appCfg.isGithubRadarConfigured) {+ const probotApp = (app: Probot) => {+ app.on("installation.deleted", async (context) => {+ const { payload } = context;+ const { installation } = payload;- const probot = new Probot({- appId: appCfg.INF_APP_CONNECTION_GITHUB_RADAR_APP_ID as string,- privateKey: appCfg.INF_APP_CONNECTION_GITHUB_RADAR_APP_PRIVATE_KEY as string,- secret: appCfg.INF_APP_CONNECTION_GITHUB_RADAR_APP_WEBHOOK_SECRET as string- });+ await server.services.secretScanningV2.github.handleInstallationDeletedEvent(installation.id);+ });- await probot.load(probotApp);+ app.on("installation", async (context) => {+ const { payload } = context;+ logger.info({ repositories: payload.repositories }, "Installed secret scanner to");+ });- // github push event webhook- server.route({- method: "POST",- url: "/github",- config: {- rateLimit: writeLimit- },- handler: async (req, res) => {- const eventName = req.headers["x-github-event"] as EmitterWebhookEventName;- const signatureSHA256 = req.headers["x-hub-signature-256"] as string;- const id = req.headers["x-github-delivery"] as string;-- await probot.webhooks.verifyAndReceive({- id,- name: eventName,- payload: JSON.stringify(req.body),- signature: signatureSHA256+ app.on("push", async (context) => {+ const { payload } = context;+ await server.services.secretScanningV2.github.handlePushEvent(payload as PushEvent);});+ };- return res.send("ok");- }- });+ const probot = new Probot({+ appId: appCfg.INF_APP_CONNECTION_GITHUB_RADAR_APP_ID as string,+ privateKey: appCfg.INF_APP_CONNECTION_GITHUB_RADAR_APP_PRIVATE_KEY as string,+ secret: appCfg.INF_APP_CONNECTION_GITHUB_RADAR_APP_WEBHOOK_SECRET as string+ });++ await probot.load(probotApp);++ // github push event webhook+ server.route({+ method: "POST",+ url: "/github",+ config: {+ rateLimit: writeLimit+ },+ handler: async (req, res) => {+ const eventName = req.headers["x-github-event"] as EmitterWebhookEventName;+ const signatureSHA256 = req.headers["x-hub-signature-256"] as string;+ const id = req.headers["x-github-delivery"] as string;++ await probot.webhooks.verifyAndReceive({+ id,+ name: eventName,+ payload: JSON.stringify(req.body),+ signature: signatureSHA256+ });++ return res.send("ok");+ }+ });+ } else {+ logger.info("GitHub Radar app is not configured. Skipping registration of the GitHub secret scanning webhook.");+ }// bitbucket push event webhookserver.route({