Skip to content

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

truncate error message

Thiago Araujo da Silva0f7d14cb3173
diff --git a/backend/src/ee/services/audit-log-stream/audit-log-stream-service.ts b/backend/src/ee/services/audit-log-stream/audit-log-stream-service.ts
index 1008d27872..1aea3b0a39 100644
--- a/backend/src/ee/services/audit-log-stream/audit-log-stream-service.ts
+++ b/backend/src/ee/services/audit-log-stream/audit-log-stream-service.ts
@@ -32,6 +32,7 @@ const FAILURE_THRESHOLD = 10; // 10 errors threshold
const FAILURE_WINDOW_MINUTES = 5; // counter expires after this much idle time since the last error
const FAILURE_WINDOW_SECONDS = FAILURE_WINDOW_MINUTES * 60;
const FAILURE_ALERT_COOLDOWN_SECONDS = 12 * 60 * 60; // 12 hours alert cooldown
+const LAST_ERROR_MESSAGE_MAX_LENGTH = 1000;
export type TAuditLogStreamServiceFactoryDep = {
auditLogStreamDAL: TAuditLogStreamDALFactory;
@@ -359,7 +360,11 @@ export const auditLogStreamServiceFactory = ({
// Capture the last error message and timestamp inside the cooldown payload so list reads and
// the failure email both surface the most recent root cause to admins.
- const lastError = { message: errorMessage, timestamp: new Date().toISOString() };
+ const truncatedMessage =
+ errorMessage.length > LAST_ERROR_MESSAGE_MAX_LENGTH
+ ? `${errorMessage.slice(0, LAST_ERROR_MESSAGE_MAX_LENGTH)}...`
+ : errorMessage;
+ const lastError = { message: truncatedMessage, timestamp: new Date().toISOString() };
// NX lock ensures only one worker fires the alert within the cooldown window.
const acquired = await keyStore.setItemWithExpiryNX(
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index df2e9ff6e3..f1357845c8 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -379,12 +379,16 @@ export const keyStoreFactory = (
return Number(result);
}
+ const INCREMENT_WITH_EXPYRE = `
+ local v = redis.call('INCRBY', KEYS[1], ARGV[1])
+ redis.call('EXPIRE', KEYS[1], ARGV[2])
+ return v
+ `;
+
// Atomically increment key and (re)set TTL on every call so the expiry rolls forward with each write.
const incrementByWithExpiry = async (key: string, value: number, expiryInSeconds: number): Promise<number> => {
const result = await primaryRedis.eval(
- `local v = redis.call('INCRBY', KEYS[1], ARGV[1])
- redis.call('EXPIRE', KEYS[1], ARGV[2])
- return v`,
+ INCREMENT_WITH_EXPYRE,
1,
key,
String(value),
diff --git a/backend/src/services/smtp/emails/AuditLogStreamFailedTemplate.tsx b/backend/src/services/smtp/emails/AuditLogStreamFailedTemplate.tsx
index 69fd6af7e5..60da48977c 100644
--- a/backend/src/services/smtp/emails/AuditLogStreamFailedTemplate.tsx
+++ b/backend/src/services/smtp/emails/AuditLogStreamFailedTemplate.tsx
@@ -38,13 +38,13 @@ export const AuditLogStreamFailedTemplate = ({
<Text className="text-[14px] text-red-600 mt-[4px]">{windowFailureCount}</Text>
{lastErrorTimestamp && (
<>
- <strong>Last error at</strong>
+ <strong>Last Error At</strong>
<Text className="text-[14px] mt-[4px]">{lastErrorTimestamp}</Text>
</>
)}
{lastErrorMessage && (
<>
- <strong>Last error message</strong>
+ <strong>Last Error Message</strong>
<Text className="text-[14px] text-red-600 mt-[4px] break-all">{lastErrorMessage}</Text>
</>
)}