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
improvement: add organization name constraint
Scott Wilsonabc2ffca574f
diff --git a/backend/src/server/lib/schemas.ts b/backend/src/server/lib/schemas.tsindex ed97cb7d0f..28e6b06976 100644--- a/backend/src/server/lib/schemas.ts+++ b/backend/src/server/lib/schemas.ts@@ -21,3 +21,10 @@ export const slugSchema = ({ min = 1, max = 32, field = "Slug" }: SlugSchemaInpumessage: `${field} field can only contain lowercase letters, numbers, and hyphens`});};++export const OrganizationNameSchema = z+ .string()+ .trim()+ .min(1, { message: "Name must be at least 1 character" })+ .max(64, { message: "Name must be 64 or fewer characters" })+ .regex(/^[a-zA-Z0-9\-_\s]+$/, "Name can only contain alphanumeric characters, dashes, underscores, and spaces");diff --git a/backend/src/server/routes/v1/organization-router.ts b/backend/src/server/routes/v1/organization-router.tsindex db0008ebe2..4e8b120f8e 100644--- a/backend/src/server/routes/v1/organization-router.ts+++ b/backend/src/server/routes/v1/organization-router.ts@@ -13,7 +13,7 @@ import { EventType, UserAgentType } from "@app/ee/services/audit-log/audit-log-timport { AUDIT_LOGS, ORGANIZATIONS } from "@app/lib/api-docs";import { getLastMidnightDateISO, removeTrailingSlash } from "@app/lib/fn";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";-import { slugSchema } from "@app/server/lib/schemas";+import { OrganizationNameSchema, slugSchema } from "@app/server/lib/schemas";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { ActorType, AuthMode, MfaMethod } from "@app/services/auth/auth-type";import { sanitizedOrganizationSchema } from "@app/services/org/org-schema";@@ -251,7 +251,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {schema: {params: z.object({ organizationId: z.string().trim() }),body: z.object({- name: z.string().trim().max(64, { message: "Name must be 64 or fewer characters" }).optional(),+ name: OrganizationNameSchema.optional(),slug: slugSchema({ max: 64 }).optional(),authEnforced: z.boolean().optional(),scimEnabled: z.boolean().optional(),diff --git a/backend/src/server/routes/v2/organization-router.ts b/backend/src/server/routes/v2/organization-router.tsindex 8ca105ad4e..e4f04af52b 100644--- a/backend/src/server/routes/v2/organization-router.ts+++ b/backend/src/server/routes/v2/organization-router.ts@@ -12,6 +12,7 @@ import {import { ORGANIZATIONS } from "@app/lib/api-docs";import { getConfig } from "@app/lib/config/env";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";+import { OrganizationNameSchema } from "@app/server/lib/schemas";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { ActorType, AuthMode } from "@app/services/auth/auth-type";@@ -330,7 +331,7 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {},schema: {body: z.object({- name: z.string().trim()+ name: OrganizationNameSchema}),response: {200: z.object({diff --git a/backend/src/server/routes/v3/signup-router.ts b/backend/src/server/routes/v3/signup-router.tsindex e952548163..b1c7c7ddc6 100644--- a/backend/src/server/routes/v3/signup-router.ts+++ b/backend/src/server/routes/v3/signup-router.ts@@ -4,6 +4,7 @@ import { UsersSchema } from "@app/db/schemas";import { getConfig } from "@app/lib/config/env";import { ForbiddenRequestError } from "@app/lib/errors";import { authRateLimit } from "@app/server/config/rateLimiter";+import { OrganizationNameSchema } from "@app/server/lib/schemas";import { getServerCfg } from "@app/services/super-admin/super-admin-service";import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";@@ -100,7 +101,7 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {encryptedPrivateKeyTag: z.string().trim(),salt: z.string().trim(),verifier: z.string().trim(),- organizationName: z.string().trim().min(1),+ organizationName: OrganizationNameSchema,providerAuthToken: z.string().trim().optional().nullish(),attributionSource: z.string().trim().optional(),password: z.string()diff --git a/frontend/src/components/auth/UserInfoStep.tsx b/frontend/src/components/auth/UserInfoStep.tsxindex 2b7761d1ee..582c2a850a 100644--- a/frontend/src/components/auth/UserInfoStep.tsx+++ b/frontend/src/components/auth/UserInfoStep.tsx@@ -11,6 +11,7 @@ import { encodeBase64 } from "tweetnacl-util";import { initProjectHelper } from "@app/helpers/project";import { completeAccountSignup, useSelectOrganization } from "@app/hooks/api/auth/queries";import { fetchOrganizations } from "@app/hooks/api/organization/queries";+import { onRequestError } from "@app/hooks/api/reactQuery";import InputField from "../basic/InputField";import checkPassword from "../utilities/checks/password/checkPassword";@@ -206,6 +207,7 @@ export default function UserInfoStep({incrementStep();} catch (error) {+ onRequestError(error);setIsLoading(false);console.error(error);}diff --git a/frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsx b/frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsxindex b5712e5969..c91d8280c7 100644--- a/frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsx+++ b/frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsx@@ -78,7 +78,7 @@ export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose }) =>};return (- <Modal isOpen={isOpen}>+ <Modal modal={false} isOpen={isOpen}><ModalContenttitle="Create Organization"subTitle="Looks like you're not part of any organizations. Create one to start using Infisical"diff --git a/frontend/src/hooks/api/reactQuery.tsx b/frontend/src/hooks/api/reactQuery.tsxindex f6ae0ca761..63007a4edc 100644--- a/frontend/src/hooks/api/reactQuery.tsx+++ b/frontend/src/hooks/api/reactQuery.tsx@@ -22,167 +22,143 @@ const camelCaseToSpaces = (input: string) => {return input.replace(/([a-z])([A-Z])/g, "$1 $2");};-export const queryClient = new QueryClient({- mutationCache: new MutationCache({- onError: (error) => {- if (axios.isAxiosError(error)) {- const serverResponse = error.response?.data as TApiErrors;- if (serverResponse?.error === ApiErrorTypes.ValidationError) {- createNotification(- {- title: "Validation Error",- type: "error",- text: "Please check the input and try again.",- callToAction: (- <Modal>- <ModalTrigger asChild>- <Button variant="outline_bg" size="xs">- Show more- </Button>- </ModalTrigger>- <ModalContent title="Validation Error Details">- <TableContainer>- <Table>- <THead>- <Tr>- <Th>Field</Th>- <Th>Issue</Th>- </Tr>- </THead>- <TBody>- {serverResponse.message?.map(({ message, path }) => (- <Tr key={path.join(".")}>- <Td>{path.join(".")}</Td>- <Td>{message.toLowerCase()}</Td>- </Tr>- ))}- </TBody>- </Table>- </TableContainer>- </ModalContent>- </Modal>- ),- copyActions: [- {- value: serverResponse.reqId,- name: "Request ID",- label: `Request ID: ${serverResponse.reqId}`- }- ]- },- { closeOnClick: false }- );- return;- }- if (serverResponse?.error === ApiErrorTypes.ForbiddenError) {- createNotification(+export const onRequestError = (error: unknown) => {+ if (axios.isAxiosError(error)) {+ const serverResponse = error.response?.data as TApiErrors;+ if (serverResponse?.error === ApiErrorTypes.ValidationError) {+ createNotification(+ {+ title: "Validation Error",+ type: "error",+ text: "Please check the input and try again.",+ callToAction: (+ <Modal>+ <ModalTrigger asChild>+ <Button variant="outline_bg" size="xs">+ Show more+ </Button>+ </ModalTrigger>+ <ModalContent title="Validation Error Details">+ <TableContainer>+ <Table>+ <THead>+ <Tr>+ <Th>Field</Th>+ <Th>Issue</Th>+ </Tr>+ </THead>+ <TBody>+ {serverResponse.message?.map(({ message, path }) => (+ <Tr key={path.join(".")}>+ <Td>{path.join(".")}</Td>+ <Td>{message.toLowerCase()}</Td>+ </Tr>+ ))}+ </TBody>+ </Table>+ </TableContainer>+ </ModalContent>+ </Modal>+ ),+ copyActions: [{- title: "Forbidden Access",- type: "error",- text: `${serverResponse.message}.`,- callToAction: serverResponse?.details?.length ? (- <Modal>- <ModalTrigger asChild>- <Button variant="outline_bg" size="xs">- Show more- </Button>- </ModalTrigger>- <ModalContent- title="Validation Rules"- subTitle="Please review the allowed rules below."- >- <div className="flex flex-col gap-2">- {serverResponse.details?.map((el, index) => {- const hasConditions = Boolean(Object.keys(el.conditions || {}).length);- return (- <div- key={`Forbidden-error-details-${index + 1}`}- className="rounded-md border border-gray-600 p-4"- >- <div>- {el.inverted ? "Cannot" : "Can"}{" "}- <span className="text-yellow-600">- {el.action.toString().replaceAll(",", ", ")}- </span>{" "}- {el.subject.toString()} {hasConditions && "with conditions:"}- </div>- {hasConditions && (- <ul className="flex list-disc flex-col gap-1 pl-5 pt-2 text-sm">- {Object.keys(el.conditions || {}).flatMap((field, fieldIndex) => {- const operators = (- el.conditions as Record<- string,- | string- | { [K in PermissionConditionOperators]: string | string[] }- >- )[field];-- const formattedFieldName = camelCaseToSpaces(field).toLowerCase();- if (typeof operators === "string") {- return (- <li- key={`Forbidden-error-details-${index + 1}-${- fieldIndex + 1- }`}- >- <span className="font-bold capitalize">- {formattedFieldName}- </span>{" "}- <span className="text-mineshaft-200">equal to</span>{" "}- <span className="text-yellow-600">{operators}</span>- </li>- );- }-- return Object.keys(operators).map((operator, operatorIndex) => (- <li- key={`Forbidden-error-details-${index + 1}-${- fieldIndex + 1- }-${operatorIndex + 1}`}- >- <span className="font-bold capitalize">- {formattedFieldName}- </span>{" "}- <span className="text-mineshaft-200">- {- formatedConditionsOperatorNames[- operator as PermissionConditionOperators- ]- }- </span>{" "}- <span className="text-yellow-600">- {operators[- operator as PermissionConditionOperators- ].toString()}- </span>- </li>- ));- })}- </ul>- )}- </div>- );- })}- </div>- </ModalContent>- </Modal>- ) : undefined,- copyActions: [- {- value: serverResponse.reqId,- name: "Request ID",- label: `Request ID: ${serverResponse.reqId}`- }- ]- },- { closeOnClick: false }- );- return;- }- createNotification({- title: "Bad Request",+ value: serverResponse.reqId,+ name: "Request ID",+ label: `Request ID: ${serverResponse.reqId}`+ }+ ]+ },+ { closeOnClick: false }+ );+ return;+ }+ if (serverResponse?.error === ApiErrorTypes.ForbiddenError) {+ createNotification(+ {+ title: "Forbidden Access",type: "error",- text: `${serverResponse.message}${serverResponse.message?.endsWith(".") ? "" : "."}`,+ text: `${serverResponse.message}.`,+ callToAction: serverResponse?.details?.length ? (+ <Modal>+ <ModalTrigger asChild>+ <Button variant="outline_bg" size="xs">+ Show more+ </Button>+ </ModalTrigger>+ <ModalContent+ title="Validation Rules"+ subTitle="Please review the allowed rules below."+ >+ <div className="flex flex-col gap-2">+ {serverResponse.details?.map((el, index) => {+ const hasConditions = Boolean(Object.keys(el.conditions || {}).length);+ return (+ <div+ key={`Forbidden-error-details-${index + 1}`}+ className="rounded-md border border-gray-600 p-4"+ >+ <div>+ {el.inverted ? "Cannot" : "Can"}{" "}+ <span className="text-yellow-600">+ {el.action.toString().replaceAll(",", ", ")}+ </span>{" "}+ {el.subject.toString()} {hasConditions && "with conditions:"}+ </div>+ {hasConditions && (+ <ul className="flex list-disc flex-col gap-1 pl-5 pt-2 text-sm">+ {Object.keys(el.conditions || {}).flatMap((field, fieldIndex) => {+ const operators = (+ el.conditions as Record<+ string,+ | string+ | { [K in PermissionConditionOperators]: string | string[] }+ >+ )[field];++ const formattedFieldName = camelCaseToSpaces(field).toLowerCase();+ if (typeof operators === "string") {+ return (+ <li+ key={`Forbidden-error-details-${index + 1}-${fieldIndex + 1}`}+ >+ <span className="font-bold capitalize">+ {formattedFieldName}+ </span>{" "}+ <span className="text-mineshaft-200">equal to</span>{" "}+ <span className="text-yellow-600">{operators}</span>+ </li>+ );+ }++ return Object.keys(operators).map((operator, operatorIndex) => (+ <li+ key={`Forbidden-error-details-${index + 1}-${+ fieldIndex + 1+ }-${operatorIndex + 1}`}+ >+ <span className="font-bold capitalize">{formattedFieldName}</span>{" "}+ <span className="text-mineshaft-200">+ {+ formatedConditionsOperatorNames[+ operator as PermissionConditionOperators+ ]+ }+ </span>{" "}+ <span className="text-yellow-600">+ {operators[operator as PermissionConditionOperators].toString()}+ </span>+ </li>+ ));+ })}+ </ul>+ )}+ </div>+ );+ })}+ </div>+ </ModalContent>+ </Modal>+ ) : undefined,copyActions: [{value: serverResponse.reqId,@@ -190,9 +166,29 @@ export const queryClient = new QueryClient({label: `Request ID: ${serverResponse.reqId}`}]- });- }+ },+ { closeOnClick: false }+ );+ return;}+ createNotification({+ title: "Bad Request",+ type: "error",+ text: `${serverResponse.message}${serverResponse.message?.endsWith(".") ? "" : "."}`,+ copyActions: [+ {+ value: serverResponse.reqId,+ name: "Request ID",+ label: `Request ID: ${serverResponse.reqId}`+ }+ ]+ });+ }+};++export const queryClient = new QueryClient({+ mutationCache: new MutationCache({+ onError: onRequestError}),defaultOptions: {queries: {