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 greptile comments
Thiago Araujo da Silva3df377753177
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex 76450b15af..12337c3355 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -6017,7 +6017,6 @@ interface UpdateAuditLogSettingsEvent {type: EventType.UPDATE_AUDIT_LOG_SETTINGS;metadata: {scope: "organization" | "project";- projectId?: string;eventClasses: { eventClass: string; isEnabled: boolean }[];};}diff --git a/backend/src/server/plugins/audit-log-permission-denied.test.ts b/backend/src/server/plugins/audit-log-permission-denied.test.tsnew file mode 100644index 0000000000..25dda6611c--- /dev/null+++ b/backend/src/server/plugins/audit-log-permission-denied.test.ts@@ -0,0 +1,107 @@+import { createMongoAbility, ForbiddenError } from "@casl/ability";+import { fastifyRequestContext } from "@fastify/request-context";+import Fastify, { FastifyInstance } from "fastify";+import { afterEach, describe, expect, test, vi } from "vitest";+import { z } from "zod";++import { ActorType } from "@app/services/auth/auth-type";++import { injectPermissionDeniedAuditLog } from "./audit-log-permission-denied";+import { serializerCompiler, validatorCompiler, ZodTypeProvider } from "./fastify-zod";++const ORG_ID = "org-1";+const PROJECT_ID = "11111111-1111-1111-1111-111111111111";++const deny = () => ForbiddenError.from(createMongoAbility([])).throwUnlessCan("read", "Thing");++const buildServer = async () => {+ const recordPermissionDenied = vi.fn().mockResolvedValue(undefined);++ const app = Fastify({ logger: false }).withTypeProvider<ZodTypeProvider>();+ app.setValidatorCompiler(validatorCompiler);+ app.setSerializerCompiler(serializerCompiler);+ await app.register(fastifyRequestContext);++ app.decorate("services", { auditLog: { recordPermissionDenied } } as never);+ app.addHook("onRequest", async (req) => {+ Object.assign(req, {+ auth: { authMode: "jwt" },+ permission: { orgId: ORG_ID },+ auditLogInfo: { actor: { type: ActorType.USER, metadata: { userId: "user-1" } }, orgId: ORG_ID }+ });+ });+ await app.register(injectPermissionDeniedAuditLog);++ app.route({ method: "PUT", url: "/org-settings", handler: async () => deny() });+ app.route({+ method: "PUT",+ url: "/org-settings-with-query",+ schema: { querystring: z.object({ page: z.coerce.number().optional() }) },+ handler: async () => deny()+ });+ app.route({+ method: "GET",+ url: "/things",+ schema: { querystring: z.object({ projectId: z.string() }) },+ handler: async () => deny()+ });+ app.route({+ method: "GET",+ url: "/projects/:projectId/things",+ schema: { params: z.object({ projectId: z.string() }) },+ handler: async () => deny()+ });++ await app.ready();+ return { app, recordPermissionDenied };+};++const recordedProjectId = (recordPermissionDenied: ReturnType<typeof vi.fn>) =>+ (recordPermissionDenied.mock.calls[0][0] as { projectId?: string }).projectId;++describe("permission denied audit hook", () => {+ let app: FastifyInstance | undefined;++ afterEach(async () => {+ await app?.close();+ app = undefined;+ });++ test("ignores a projectId in the query when the route declares no querystring schema", async () => {+ const server = await buildServer();+ app = server.app;++ await app.inject({ method: "PUT", url: "/org-settings?projectId=unused" });++ expect(server.recordPermissionDenied).toHaveBeenCalledTimes(1);+ expect(recordedProjectId(server.recordPermissionDenied)).toBeUndefined();+ });++ test("ignores a projectId the declared querystring schema does not include", async () => {+ const server = await buildServer();+ app = server.app;++ await app.inject({ method: "PUT", url: "/org-settings-with-query?projectId=unused&page=1" });++ expect(server.recordPermissionDenied).toHaveBeenCalledTimes(1);+ expect(recordedProjectId(server.recordPermissionDenied)).toBeUndefined();+ });++ test("uses a projectId the route declares in its querystring", async () => {+ const server = await buildServer();+ app = server.app;++ await app.inject({ method: "GET", url: `/things?projectId=${PROJECT_ID}` });++ expect(recordedProjectId(server.recordPermissionDenied)).toBe(PROJECT_ID);+ });++ test("uses a projectId from the route params", async () => {+ const server = await buildServer();+ app = server.app;++ await app.inject({ method: "GET", url: `/projects/${PROJECT_ID}/things` });++ expect(recordedProjectId(server.recordPermissionDenied)).toBe(PROJECT_ID);+ });+});diff --git a/backend/src/server/plugins/audit-log-permission-denied.ts b/backend/src/server/plugins/audit-log-permission-denied.tsindex 089c05e0f9..8ab999af19 100644--- a/backend/src/server/plugins/audit-log-permission-denied.ts+++ b/backend/src/server/plugins/audit-log-permission-denied.ts@@ -37,10 +37,12 @@ const readProjectId = (source: unknown) => {return typeof projectId === "string" ? projectId : undefined;};-// Every RBAC denial is a CASL ForbiddenError or PermissionBoundaryError, and onError hooks run-// before the error handler, so this one hook sees all of them. ForbiddenRequestError is skipped-// on purpose: it's used for auth-mode mismatches, plan gating and admin-only checks, none of-// which are permission decisions.+// RBAC denials surface as a CASL ForbiddenError or PermissionBoundaryError, and onError hooks run+// before the error handler, so this one hook sees them all. ForbiddenRequestError is skipped on+// purpose: most of its throw sites are auth-mode mismatches, plan gating, admin-only checks and+// ownership checks that carry no action or subject, so recording them would bury real denials.+// The few services that evaluate permission.can() by hand and throw ForbiddenRequestError are+// not captured here; move them onto throwUnlessCan to record them.export const injectPermissionDeniedAuditLog = fp(async (server: FastifyZodProvider) => {server.addHook("onError", async (req, _reply, error) => {const isCaslDenial = error instanceof ForbiddenError;@@ -52,11 +54,13 @@ export const injectPermissionDeniedAuditLog = fp(async (server: FastifyZodProvidconst caslError = isCaslDenial ? (error as unknown as ForbiddenError<AnyAbility>) : undefined;const missing = isCaslDenial ? undefined : readMissingPermission((error as PermissionBoundaryError).details);++ const { schema } = req.routeOptions;const projectId =requestContext.get(RequestContextKey.ProjectDetails)?.id ??readProjectId(req.params) ??- readProjectId(req.body) ??- readProjectId(req.query);+ (schema?.body ? readProjectId(req.body) : undefined) ??+ (schema?.querystring ? readProjectId(req.query) : undefined);void server.services.auditLog.recordPermissionDenied({...req.auditLogInfo,diff --git a/backend/src/server/routes/v1/project-router.ts b/backend/src/server/routes/v1/project-router.tsindex 3fd8d10a72..bc72ef074e 100644--- a/backend/src/server/routes/v1/project-router.ts+++ b/backend/src/server/routes/v1/project-router.ts@@ -737,7 +737,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {tags: [ApiDocsTags.AuditLogs],description: "Get which audit log event classes the project records",params: z.object({- projectId: z.string().trim().describe(AUDIT_LOG_SETTINGS.GET_PROJECT.projectId)+ projectId: z.string().uuid().describe(AUDIT_LOG_SETTINGS.GET_PROJECT.projectId)}),response: {200: AuditLogSettingsResponseSchema@@ -768,7 +768,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {tags: [ApiDocsTags.AuditLogs],description: "Update which audit log event classes the project records",params: z.object({- projectId: z.string().trim().describe(AUDIT_LOG_SETTINGS.UPDATE_PROJECT.projectId)+ projectId: z.string().uuid().describe(AUDIT_LOG_SETTINGS.UPDATE_PROJECT.projectId)}),body: updateAuditLogSettingsBodySchema(AUDIT_LOG_SETTINGS.UPDATE_PROJECT.isEnabled),response: {@@ -794,7 +794,6 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {type: EventType.UPDATE_AUDIT_LOG_SETTINGS,metadata: {scope: "project",- projectId: req.params.projectId,eventClasses: req.body.eventClasses}}diff --git a/frontend/src/components/auditLogSettings/AuditLogEventClassRow.tsx b/frontend/src/components/auditLogSettings/AuditLogEventClassRow.tsxindex d78b1423a6..f56f8b87ae 100644--- a/frontend/src/components/auditLogSettings/AuditLogEventClassRow.tsx+++ b/frontend/src/components/auditLogSettings/AuditLogEventClassRow.tsx@@ -57,16 +57,14 @@ export const AuditLogEventClassRow = ({return (<Field orientation="horizontal" className="gap-8 px-6 py-6"><FieldContent>- <FieldTitle className="text-base leading-5">+ <FieldTitle><label htmlFor={id}>{auditLogEventClassToNameMap[eventClass]}</label></FieldTitle>- <FieldDescription className="max-w-2xl text-sm text-accent">+ <FieldDescription className="max-w-2xl">{auditLogEventClassToDescriptionMap[eventClass]}</FieldDescription>{descriptionExtra && (- <FieldDescription className="max-w-2xl text-sm text-accent">- {descriptionExtra}- </FieldDescription>+ <FieldDescription className="max-w-2xl">{descriptionExtra}</FieldDescription>)}{warning && (<Alert variant="warning" className="mt-2 max-w-2xl">