Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Merge branch 'heads/main' into daniel/request-ids

Daniel Hougaard1cd459fda732
diff --cc backend/src/server/plugins/error-handler.ts
index e60e245eba,63cffa9876..0cbf30f097
--- a/backend/src/server/plugins/error-handler.ts
+++ b/backend/src/server/plugins/error-handler.ts
@@@ -43,41 -43,34 +43,47 @@@ export const fastifyErrHandler = fastif
} else if (error instanceof NotFoundError) {
void res
.status(HttpStatusCodes.NotFound)
- .send({ statusCode: HttpStatusCodes.NotFound, message: error.message, error: error.name });
+ .send({ requestId: req.id, statusCode: HttpStatusCodes.NotFound, message: error.message, error: error.name });
} else if (error instanceof UnauthorizedError) {
- void res
- .status(HttpStatusCodes.Unauthorized)
- .send({ statusCode: HttpStatusCodes.Unauthorized, message: error.message, error: error.name });
+ void res.status(HttpStatusCodes.Unauthorized).send({
+ requestId: req.id,
+ statusCode: HttpStatusCodes.Unauthorized,
+ message: error.message,
+ error: error.name
+ });
} else if (error instanceof DatabaseError || error instanceof InternalServerError) {
- void res
- .status(HttpStatusCodes.InternalServerError)
- .send({ statusCode: HttpStatusCodes.InternalServerError, message: "Something went wrong", error: error.name });
+ void res.status(HttpStatusCodes.InternalServerError).send({
+ requestId: req.id,
+ statusCode: HttpStatusCodes.InternalServerError,
+ message: "Something went wrong",
+ error: error.name
+ });
} else if (error instanceof GatewayTimeoutError) {
- void res
- .status(HttpStatusCodes.GatewayTimeout)
- .send({ statusCode: HttpStatusCodes.GatewayTimeout, message: error.message, error: error.name });
+ void res.status(HttpStatusCodes.GatewayTimeout).send({
+ requestId: req.id,
+ statusCode: HttpStatusCodes.GatewayTimeout,
+ message: error.message,
+ error: error.name
+ });
} else if (error instanceof ZodError) {
- void res
- .status(HttpStatusCodes.Unauthorized)
- .send({ statusCode: HttpStatusCodes.Unauthorized, error: "ValidationFailure", message: error.issues });
+ void res.status(HttpStatusCodes.Unauthorized).send({
+ requestId: req.id,
+ statusCode: HttpStatusCodes.Unauthorized,
+ error: "ValidationFailure",
+ message: error.issues
+ });
} else if (error instanceof ForbiddenError) {
void res.status(HttpStatusCodes.Forbidden).send({
+ requestId: req.id,
statusCode: HttpStatusCodes.Forbidden,
error: "PermissionDenied",
- message: `You are not allowed to ${error.action} on ${error.subjectType} - ${JSON.stringify(error.subject)}`
+ message: `You are not allowed to ${error.action} on ${error.subjectType}`,
+ details: (error.ability as PureAbility).rulesFor(error.action as string, error.subjectType).map((el) => ({
+ action: el.action,
+ inverted: el.inverted,
+ subject: el.subject,
+ conditions: el.conditions
+ }))
});
} else if (error instanceof ForbiddenRequestError) {
void res.status(HttpStatusCodes.Forbidden).send({
diff --cc backend/src/server/routes/sanitizedSchemas.ts
index de4a1d8480,78575e35d7..bbbe57631b
--- a/backend/src/server/routes/sanitizedSchemas.ts
+++ b/backend/src/server/routes/sanitizedSchemas.ts
@@@ -48,9 -45,9 +48,10 @@@ export const DefaultResponseErrorsSchem
error: z.string()
}),
403: z.object({
+ requestId: z.string(),
statusCode: z.literal(403),
message: z.string(),
+ details: z.any().optional(),
error: z.string()
}),
500: z.object({
diff --cc frontend/src/hooks/api/types.ts
index 9126559d3e,34120a15d3..08fc84ffa8
--- a/frontend/src/hooks/api/types.ts
+++ b/frontend/src/hooks/api/types.ts
@@@ -50,15 -51,17 +51,26 @@@ export enum ApiErrorTypes
export type TApiErrors =
| {
+ requestId: string;
error: ApiErrorTypes.ValidationError;
message: ZodIssue[];
+ statusCode: 401;
+ }
+ | {
++ requestId: string;
++ error: ApiErrorTypes.UnauthorizedError;
++ message: string;
++ statusCode: 401;
++ }
++ | {
++ requestId: string;
+ error: ApiErrorTypes.ForbiddenError;
+ message: string;
+ details: PureAbility["rules"];
statusCode: 403;
}
- | { requestId: string; error: ApiErrorTypes.ForbiddenError; message: string; statusCode: 403 }
- | { requestId: string; error: ApiErrorTypes.UnauthorizedError; message: string; statusCode: 401 }
| {
+ requestId: string;
statusCode: 400;
message: string;
error: ApiErrorTypes.BadRequestError;
diff --cc frontend/src/reactQuery.tsx
index 464efe1053,7b9735c9b1..c897c6e02d
--- a/frontend/src/reactQuery.tsx
+++ b/frontend/src/reactQuery.tsx
@@@ -16,38 -28,144 +28,154 @@@ export const queryClient = new QueryCli
if (axios.isAxiosError(error)) {
const serverResponse = error.response?.data as TApiErrors;
if (serverResponse?.error === ApiErrorTypes.ValidationError) {
- createNotification({
- title: "Validation Error",
- type: "error",
- text: (
- <div>
- {serverResponse.message?.map(({ message, path }) => (
- <div className="flex space-y-2" key={path.join(".")}>
- <div>
- Field <i>{path.join(".")}</i> {message.toLowerCase()}
- </div>
- </div>
- ))}
- <div className="mt-2">Request ID: {serverResponse.requestId}</div>
- </div>
- )
- });
+ createNotification(
+ {
+ title: "Validation Error",
+ type: "error",
- text: "Please check the input and try again.",
++ text: (
++ <div>
++ <p>Please check the input and try again.</p>
++ <p className="mt-2 text-xs">Request ID: {serverResponse.requestId}</p>
++ </div>
++ ),
+ children: (
+ <Modal>
+ <ModalTrigger>
+ <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>
+ )
+ },
+ { closeOnClick: false }
+ );
return;
}
+ if (serverResponse?.error === ApiErrorTypes.ForbiddenError) {
+ createNotification(
+ {
+ title: "Forbidden Access",
+ type: "error",
- text: serverResponse.message,
++
++ text: `${serverResponse.message} [requestId=${serverResponse.requestId}]`,
+ children: serverResponse?.details?.length ? (
+ <Modal>
+ <ModalTrigger>
+ <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 = 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 title =
- // eslint-disable-next-line no-nested-ternary
- serverResponse.statusCode === 403
- ? "Forbidden Access"
- : serverResponse.statusCode === 401
- ? "Unauthorized Access"
- : "Bad Request";
+ 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
+ },
+ { closeOnClick: false }
+ );
+ return;
+ }
- createNotification({ title: "Bad Request", type: "error", text: serverResponse.message });
+ createNotification({
- title,
++ title: "Bad Request",
+ type: "error",
+ text: `${serverResponse.message} [requestId=${serverResponse.requestId}]`
+ });
}
}
}),