Skip to content

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

cleanup

Daniel Hougaardf5f8eff7acfe
diff --git a/backend/src/lib/validator/validate-string.ts b/backend/src/lib/validator/validate-string.ts
index 2f81a43e74..4e89d313fb 100644
--- a/backend/src/lib/validator/validate-string.ts
+++ b/backend/src/lib/validator/validate-string.ts
@@ -1,8 +1,6 @@
import RE2 from "re2";
import { z } from "zod";
-export const SPECIAL_CHARACTERS = "!@#$%^&*()_+\\-=\\[\\]{}|;:'\",.<>/?\\\\";
-
export enum CharacterType {
Alphabets = "alphabets",
Numbers = "numbers",
@@ -55,7 +53,7 @@ export const characterValidator = (allowedCharacters: CharacterType[]) => {
[CharacterType.Numbers]: "0-9",
[CharacterType.AlphaNumeric]: "a-zA-Z0-9",
[CharacterType.Spaces]: "\\s",
- [CharacterType.SpecialCharacters]: SPECIAL_CHARACTERS,
+ [CharacterType.SpecialCharacters]: "!@#$%^&*()_+\\-=\\[\\]{}|;:'\",.<>/?\\\\",
[CharacterType.Punctuation]: "\\.\\,\\;\\:\\!\\?",
[CharacterType.Colon]: "\\:",
[CharacterType.ForwardSlash]: "\\/",
diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
index 47c081f9f9..f30b1e0467 100644
--- a/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-fns.ts
@@ -183,6 +183,11 @@ const evaluateConstraint = (constraint: TConstraint, secret: TSecretToValidate):
switch (constraint.type) {
case ConstraintType.MinLength: {
const min = Number(constraint.value);
+
+ if (Number.isNaN(min)) {
+ return `${targetLabel} must be at least ${min} characters (got ${targetValue.length})`;
+ }
+
if (targetValue.length < min) {
return `${targetLabel} must be at least ${min} characters (got ${targetValue.length})`;
}
@@ -190,17 +195,27 @@ const evaluateConstraint = (constraint: TConstraint, secret: TSecretToValidate):
}
case ConstraintType.MaxLength: {
const max = Number(constraint.value);
+
+ if (Number.isNaN(max)) {
+ return `${targetLabel} must be at most ${max} characters (got ${targetValue.length})`;
+ }
+
if (targetValue.length > max) {
return `${targetLabel} must be at most ${max} characters (got ${targetValue.length})`;
}
return null;
}
case ConstraintType.RegexPattern: {
- const regex = new RE2(constraint.value);
- if (!regex.test(targetValue)) {
+ try {
+ const regex = new RE2(constraint.value);
+ if (!regex.test(targetValue)) {
+ return `${targetLabel} must match pattern ${constraint.value}`;
+ }
+ return null;
+ } catch {
+ // re2 throws an error if the pattern is invalid
return `${targetLabel} must match pattern ${constraint.value}`;
}
- return null;
}
case ConstraintType.RequiredPrefix: {
if (!targetValue.startsWith(constraint.value)) {
diff --git a/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts b/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts
index 7a2248faba..3209e9606e 100644
--- a/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts
+++ b/backend/src/services/secret-validation-rule/secret-validation-rule-service.ts
@@ -156,7 +156,7 @@ export const secretValidationRuleServiceFactory = ({
});
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.Settings);
- const existingRule = await secretValidationRuleDAL.findById(ruleId);
+ const existingRule = await secretValidationRuleDAL.findOne({ id: ruleId, projectId });
if (!existingRule) {
throw new NotFoundError({ message: `Secret validation rule with ID ${ruleId} not found` });
}
@@ -248,7 +248,7 @@ export const secretValidationRuleServiceFactory = ({
});
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Delete, ProjectPermissionSub.Settings);
- const existingRule = await secretValidationRuleDAL.findById(ruleId);
+ const existingRule = await secretValidationRuleDAL.findOne({ id: ruleId, projectId });
if (!existingRule) {
throw new NotFoundError({ message: `Secret validation rule with ID ${ruleId} not found` });
}