Skip to content

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

Fix validateTemplateRegexField to accept all valid characters

Carlos Monastyrskia6fdd5a166d8
diff --git a/backend/src/lib/validator/validate-string.test.ts b/backend/src/lib/validator/validate-string.test.ts
index 73e1728966..778fcbdc32 100644
--- a/backend/src/lib/validator/validate-string.test.ts
+++ b/backend/src/lib/validator/validate-string.test.ts
@@ -20,4 +20,37 @@ describe("validate-string", () => {
expect(characterValidator([CharacterType.AlphaNumeric, CharacterType.Colon])("Hello:World")).toBeTruthy();
expect(characterValidator([CharacterType.AlphaNumeric, CharacterType.Underscore])("Hello World")).toBeFalsy();
});
+
+ test("Check unicode letters and digits", () => {
+ const validator = characterValidator([CharacterType.UnicodeLettersAndDigits]);
+ // Unicode letters
+ expect(validator("hello")).toBeTruthy();
+ expect(validator("你好世界")).toBeTruthy();
+ expect(validator("Компания")).toBeTruthy();
+ expect(validator("テスト")).toBeTruthy();
+ expect(validator("شركة")).toBeTruthy();
+ expect(validator("café")).toBeTruthy();
+ expect(validator("München")).toBeTruthy();
+ // Digits
+ expect(validator("abc123")).toBeTruthy();
+ // Should reject special characters
+ expect(validator("hello world")).toBeFalsy();
+ expect(validator("test<script>")).toBeFalsy();
+ expect(validator("test()")).toBeFalsy();
+ });
+
+ test("Check unicode with additional character types", () => {
+ const validator = characterValidator([
+ CharacterType.UnicodeLettersAndDigits,
+ CharacterType.Spaces,
+ CharacterType.Period,
+ CharacterType.Hyphen
+ ]);
+ expect(validator("My Company 公司")).toBeTruthy();
+ expect(validator("Москва-Сити")).toBeTruthy();
+ expect(validator("example.com")).toBeTruthy();
+ expect(validator("日本語 テスト")).toBeTruthy();
+ // Should still reject dangerous characters
+ expect(validator("test<script>alert(1)</script>")).toBeFalsy();
+ });
});
diff --git a/backend/src/lib/validator/validate-string.ts b/backend/src/lib/validator/validate-string.ts
index 4e89d313fb..d88c2207a0 100644
--- a/backend/src/lib/validator/validate-string.ts
+++ b/backend/src/lib/validator/validate-string.ts
@@ -40,7 +40,8 @@ export enum CharacterType {
Comma = "comma", // ,
Semicolon = "semicolon", // ;
Exclamation = "exclamation", // !
- Fullstop = "fullStop" // .
+ Fullstop = "fullStop", // .
+ UnicodeLettersAndDigits = "unicodeLettersAndDigits" // Unicode letters (\p{L}) and digits (\p{N})
}
/**
@@ -86,7 +87,8 @@ export const characterValidator = (allowedCharacters: CharacterType[]) => {
[CharacterType.Comma]: ",",
[CharacterType.Semicolon]: ";",
[CharacterType.Exclamation]: "!",
- [CharacterType.Fullstop]: "."
+ [CharacterType.Fullstop]: ".",
+ [CharacterType.UnicodeLettersAndDigits]: "\\p{L}\\p{N}"
};
// Combine patterns from allowed characters
diff --git a/backend/src/services/certificate-template/certificate-template-validators.ts b/backend/src/services/certificate-template/certificate-template-validators.ts
index e33ddb0478..2f1ed03202 100644
--- a/backend/src/services/certificate-template/certificate-template-validators.ts
+++ b/backend/src/services/certificate-template/certificate-template-validators.ts
@@ -13,7 +13,7 @@ export const createTemplateFieldValidator = (options?: {
minLength = 1,
maxLength = 100,
allowedCharacters = [
- CharacterType.AlphaNumeric,
+ CharacterType.UnicodeLettersAndDigits,
CharacterType.Spaces, // (space)
CharacterType.Asterisk, // *
CharacterType.At, // @