Skip to content

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

refine to avoid breaking chars at validation time

Thiago Araujo da Silva2b0a499e7a7f
diff --git a/backend/src/services/alert/alert-channel-types.ts b/backend/src/services/alert/alert-channel-types.ts
index ae4328e61c..f6273981a4 100644
--- a/backend/src/services/alert/alert-channel-types.ts
+++ b/backend/src/services/alert/alert-channel-types.ts
@@ -104,7 +104,7 @@ const WEBHOOK_RESERVED_HEADERS = [
];
const httpHeaderNameRegex = new RE2("^[A-Za-z0-9!#$%&'*+.^_`|~-]+$");
-const noLineBreaksRegex = new RE2("^[^\\r\\n]*$");
+const httpHeaderValueRegex = new RE2("^[\\t\\x20-\\x7e\\x80-\\xff]*$");
export const WebhookChannelHeaderSchema = z
.object({
@@ -125,8 +125,14 @@ export const WebhookChannelHeaderSchema = z
.string()
.min(1, "Header values cannot be empty")
.max(4096, "Header values cannot be longer than 4096 characters")
- .refine((value) => noLineBreaksRegex.test(value), "Header values cannot contain line breaks")
})
+ .refine(
+ (header) => httpHeaderValueRegex.test(header.value),
+ (header) => ({
+ message: `Header '${header.key}' has a character that can't be sent in an HTTP header, such as an emoji, a control character, or an invisible space. Re-enter the value`,
+ path: ["value"]
+ })
+ )
.refine(
(header) => header.value !== ALERT_CHANNEL_REDACTED_VALUE,
(header) => ({
diff --git a/backend/src/services/alert/channels/alert-channels.test.ts b/backend/src/services/alert/channels/alert-channels.test.ts
index dee866d384..08d0f9b821 100644
--- a/backend/src/services/alert/channels/alert-channels.test.ts
+++ b/backend/src/services/alert/channels/alert-channels.test.ts
@@ -1,3 +1,5 @@
+import { validateHeaderValue } from "node:http";
+
import { safeRequest } from "@app/lib/validator";
import {
@@ -248,9 +250,41 @@ describe("WebhookChannelConfigSchema headers", () => {
expect(result.error?.issues[0].message).toBe("Header names must be unique");
});
- test("rejects names that are not HTTP tokens and values with line breaks", () => {
+ test("rejects names that are not HTTP tokens", () => {
expect(withHeaders([{ key: "X Bad", value: "a" }]).success).toBe(false);
- expect(withHeaders([{ key: "X-Ok", value: "a\r\nX-Injected: b" }]).success).toBe(false);
+ });
+
+ test("accepts exactly the header values Node can send", () => {
+ const values = [
+ "Bearer abc123",
+ "a\tb",
+ "café",
+ "a\u00a0b",
+ "a\r\nX-Injected: b",
+ "a\u0000b",
+ "a\u001bb",
+ "a\u007fb",
+ "10€",
+ "привет",
+ "ok👍",
+ "abc\u200bdef"
+ ];
+ values.forEach((value) => {
+ let sendable = true;
+ try {
+ validateHeaderValue("X-Test", value);
+ } catch {
+ sendable = false;
+ }
+ expect(withHeaders([{ key: "X-Test", value }]).success).toBe(sendable);
+ });
+ });
+
+ test("names the header whose value can't be sent", () => {
+ const result = withHeaders([{ key: "Authorization", value: "Bearer abc\u200b123" }]);
+ expect(result.error?.issues[0].message).toBe(
+ "Header 'Authorization' has a character that can't be sent in an HTTP header, such as an emoji, a control character, or an invisible space. Re-enter the value"
+ );
});
test("rejects a redacted value that nothing restored", () => {