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
address grep review
Andrey747e91b24f93
diff --git a/backend/src/ee/services/pam-access-request/pam-access-approval-resource.ts b/backend/src/ee/services/pam-access-request/pam-access-approval-resource.tsindex da219a9e18..55b56176c6 100644--- a/backend/src/ee/services/pam-access-request/pam-access-approval-resource.ts+++ b/backend/src/ee/services/pam-access-request/pam-access-approval-resource.ts@@ -506,13 +506,13 @@ export const pamAccessApprovalResourceFactory = ({requestData,tx}) => {- const { accountId } = requestData as { accountId?: string };+ const { accountId, folderId } = requestData as { accountId?: string; folderId?: string };if (!accountId) return false;const account = tx? await pamAccountDAL.findTemplatePoliciesForShare(accountId, tx): await pamAccountDAL.findByIdWithDetails(accountId);- if (!account || account.projectId !== projectId) return false;+ if (!account || account.projectId !== projectId || (account.folderId ?? null) !== (folderId ?? null)) return false;return resolveAccessControls(account.templatePolicies).allowAutoApproval;};diff --git a/backend/src/ee/services/pam-account/pam-account-dal.ts b/backend/src/ee/services/pam-account/pam-account-dal.tsindex 5f38fa3a00..2871ebe97e 100644--- a/backend/src/ee/services/pam-account/pam-account-dal.ts+++ b/backend/src/ee/services/pam-account/pam-account-dal.ts@@ -262,11 +262,14 @@ export const pamAccountDALFactory = (db: TDbClient) => {.where({ id: account.templateId }).forShare().first("policies");- const locked = await tx(TableName.PamAccount).where({ id: accountId }).forShare().first("projectId", "templateId");+ const locked = await tx(TableName.PamAccount)+ .where({ id: accountId })+ .forShare()+ .first("projectId", "folderId", "templateId");// The account moved to another template before it was locked, so these policies may not be its ownif (!template || !locked || locked.templateId !== account.templateId) return undefined;- return { projectId: locked.projectId, templatePolicies: template.policies as unknown };+ return { projectId: locked.projectId, folderId: locked.folderId, templatePolicies: template.policies as unknown };};const findByIdsWithDetails = async (diff --git a/backend/src/services/approval-policy/approval-policy-service.ts b/backend/src/services/approval-policy/approval-policy-service.tsindex 1f5d94c500..80660bbadb 100644--- a/backend/src/services/approval-policy/approval-policy-service.ts+++ b/backend/src/services/approval-policy/approval-policy-service.ts@@ -1184,11 +1184,13 @@ export const approvalPolicyServiceFactory = ({const resource = $resource(policy.type as ApprovalPolicyType);const approved = await approvalRequestDAL.transaction(async (tx) => {- await approvalPolicyDAL.findByIdForShare(policy.id, tx);+ const lockedPolicy = await approvalPolicyDAL.findByIdForShare(policy.id, tx);const current = (await autoApprovalService.findByPolicyIds([policy.id], tx)).get(policy.id);- if (!current?.rules.some((rule) => rule.id === evidence.approvedByRuleId)) {+ const isPolicyUnchanged =+ lockedPolicy && new Date(lockedPolicy.updatedAt).getTime() === new Date(policy.updatedAt).getTime();+ if (!isPolicyUnchanged || !current?.rules.some((rule) => rule.id === evidence.approvedByRuleId)) {throw new BadRequestError({- message: "The auto-approval rules changed while this request was being checked. Submit it again."+ message: "This request's approval policy changed while it was being checked. Submit it again."});}const stillAllowed =@@ -1196,7 +1198,7 @@ export const approvalPolicyServiceFactory = ({true;if (!stillAllowed) {throw new BadRequestError({- message: "Auto-approval was turned off for this request while it was being checked. Submit it again."+ message: "Auto-approval no longer applies to this request. Submit it again."});}await $claimUnusedRecords(policy.id, evidence, tx);@@ -1292,53 +1294,59 @@ export const approvalPolicyServiceFactory = ({const resource = $resource(policyType);- const policy = await resource.matchPolicy(projectId, requestData);+ const checkAgainstPolicy = async () => {+ const matched = await resource.matchPolicy(projectId, requestData);- if (!policy) {- throw new ForbiddenRequestError({- message:- resources[policyType]?.noMatchingPolicyMessage ??- "No policies match the requested resource, you can access it without a request"- });- }+ if (!matched) {+ throw new ForbiddenRequestError({+ message:+ resources[policyType]?.noMatchingPolicyMessage ??+ "No policies match the requested resource, you can access it without a request"+ });+ }- const constraintValidation = resource.validateConstraints(policy, requestData);- if (!constraintValidation.valid) {- const errorMessage = constraintValidation.errors- ? `Policy constraints not met: ${constraintValidation.errors.join("; ")}`- : "Policy constraints not met";- throw new BadRequestError({ message: errorMessage });- }+ const constraintValidation = resource.validateConstraints(matched, requestData);+ if (!constraintValidation.valid) {+ const errorMessage = constraintValidation.errors+ ? `Policy constraints not met: ${constraintValidation.errors.join("; ")}`+ : "Policy constraints not met";+ throw new BadRequestError({ message: errorMessage });+ }- const storedAutoApproval = (await autoApprovalService.findByPolicyIds([policy.id])).get(policy.id);+ const stored = (await autoApprovalService.findByPolicyIds([matched.id])).get(matched.id);- if (assertDomainCanCreateRequest) {- await assertDomainCanCreateRequest({- projectId,- policy,- requestData: requestData as TApprovalRequestData,- actor,- hasAutoApprovalRules: Boolean(storedAutoApproval?.rules.length),- skipsAutoApproval: Boolean(skipAutoApproval)- });- }+ if (assertDomainCanCreateRequest) {+ await assertDomainCanCreateRequest({+ projectId,+ policy: matched,+ requestData: requestData as TApprovalRequestData,+ actor,+ hasAutoApprovalRules: Boolean(stored?.rules.length),+ skipsAutoApproval: Boolean(skipAutoApproval)+ });+ }- let expiresAt: Date | undefined;+ let expires: Date | undefined;- if (requestDuration) {- const ttlMs = ms(requestDuration);+ if (requestDuration) {+ const ttlMs = ms(requestDuration);- expiresAt = new Date(Date.now() + ttlMs);+ expires = new Date(Date.now() + ttlMs);- if (policy.maxRequestTtl) {- const maxTtlMs = ms(policy.maxRequestTtl);- if (ttlMs > maxTtlMs) {- throw new BadRequestError({- message: `Expiration time exceeds the maximum allowed TTL of ${policy.maxRequestTtl}`- });+ if (matched.maxRequestTtl) {+ const maxTtlMs = ms(matched.maxRequestTtl);+ if (ttlMs > maxTtlMs) {+ throw new BadRequestError({+ message: `Expiration time exceeds the maximum allowed TTL of ${matched.maxRequestTtl}`+ });+ }}}- }++ return { policy: matched, storedAutoApproval: stored, expiresAt: expires };+ };++ let { policy, storedAutoApproval, expiresAt } = await checkAgainstPolicy();let autoApprovalEvidence: TAutoApprovalEvidence | null = null;if (storedAutoApproval?.rules.length && !skipAutoApproval && actor.type === ActorType.USER) {@@ -1352,15 +1360,24 @@ export const approvalPolicyServiceFactory = ({orgId: actor.orgId,projectId});+ const evaluatedPolicyId = policy.id;autoApprovalEvidence = await autoApprovalService.evaluate({stored: storedAutoApproval,parsedInputs,isRecordUsed: (record) =>- approvalRequestDAL.hasApprovedRequestLinkingRecord({ policyId: policy.id, ...record }),+ approvalRequestDAL.hasApprovedRequestLinkingRecord({ policyId: evaluatedPolicyId, ...record }),orgId: actor.orgId,projectId,ctx: { requester: { email: requesterEmail || null } }});++ const current = await checkAgainstPolicy();+ if (current.policy.id !== evaluatedPolicyId) {+ throw new BadRequestError({+ message: "This request's approval policy changed while it was being checked. Submit it again."+ });+ }+ ({ policy, storedAutoApproval, expiresAt } = current);}}diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/JiraConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/JiraConnectionForm.tsxindex 16e95dd181..686063e80e 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/JiraConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/JiraConnectionForm.tsx@@ -33,6 +33,7 @@ import { GatewayPicker } from "@app/components/v3/platform/GatewayPicker";import { OrgPermissionSubjects } from "@app/context";import { OrgGatewayPermissionActions } from "@app/context/OrgPermissionContext/types";import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";+import { isValidEmail } from "@app/helpers/email";import { useScopeVariant } from "@app/hooks";import { JiraConnectionMethod, TJiraConnection } from "@app/hooks/api/appConnections";import { AppConnection } from "@app/hooks/api/appConnections/enums";@@ -101,7 +102,7 @@ const formSchema = z.discriminatedUnion("method", [.trim().min(1, "Email required").max(320, "Email cannot exceed 320 characters")- .email("Email must be a valid email address"),+ .refine(isValidEmail, "Email must be a valid email address"),apiToken: z.string().trim()