docs/documentation/platform/secret-validation-rules.mdx
Secret Validation Rules let you define constraints that secrets must satisfy before they can be created or updated. This helps teams enforce consistent naming conventions, prevent weak or malformed values, and maintain compliance standards across environments — all automatically at write time.
For example, you can require that all secret keys in production follow UPPER_SNAKE_CASE, that values meet a minimum length, or that database connection strings always start with a specific prefix.
When a secret is created or updated, Infisical checks it against all active validation rules whose scope (environment and folder path) matches the secret's location. If any constraint is violated, the secret is rejected and an error is thrown. When a secret is rejected, the actor will see an error describing which rule and constraint was violated.
<Note> Validation rules are enforced on mutations only (such as create or update events). Existing secrets that were created before a rule was added are not retroactively validated. </Note>Each rule contains one or more constraints. A constraint specifies what to check (the secret key or value) and how to check it.
| Constraint | Description | Example |
|---|---|---|
| Min Length | The target must be at least N characters long | Value must be at least 8 characters |
| Max Length | The target must be at most N characters long | Key must be at most 64 characters |
| Regex Pattern | The target must match a regular expression | Key must match ^[A-Z][A-Z0-9_]*$ |
| Required Prefix | The target must start with specific text | Value must start with https:// |
| Required Suffix | The target must end with specific text | Key must end with _SECRET |
| Prevent Value Reuse | The new value must not match any of the last N versions | Value must not match the last 10 versions |
Each constraint (except Prevent Value Reuse) can be applied to either the secret key or the secret value. Prevent Value Reuse applies only to the secret value.
Every rule is scoped to control where it applies:
production), or apply it to all environments./** for all paths, /services/* for immediate subfolders of /services).This means you can have different validation standards for different parts of your project. For instance, you might enforce stricter naming in production while keeping development more flexible.


- **Name** — A descriptive name (e.g., "Production key naming convention").
- **Description** (optional) — A brief explanation of what the rule enforces and why.
- **Rule Type** — Currently supports **Static Secrets**.
- **Environment** — Choose a specific environment or "All Environments".
- **Folder Path** — The path scope, supporting glob patterns (e.g., `/**`).
**Constraints**
Click **Add Constraint** and choose from the available constraint types. For each constraint, select whether it applies to the secret **key** or **value**, then provide the constraint parameter (length, pattern, prefix, suffix, or number of previous versions).
You can add multiple constraints to a single rule. All constraints must pass for a secret to be accepted.

Infisical prevents you from creating rules that would conflict with each other. If two rules apply to the same scope (overlapping environment and folder path) and share a constraint of the same type targeting the same field (key or value), the second rule will be rejected.
For example, you cannot have two separate "Regex Pattern on key" constraints in overlapping scopes, as they could contradict each other. Instead, combine the patterns into a single rule.
- Pattern: `^[A-Z][A-Z0-9_]*$`
This ensures all secret keys follow the `UPPER_SNAKE_CASE` convention (e.g., `DATABASE_URL`, `API_KEY`), rejecting names like `mySecret` or `api-key`.
- Minimum: `8`
This prevents secrets with very short or empty-like values from being saved, helping catch accidental pastes or placeholder values.
- Prefix: `postgresql://`
This ensures all secrets in the database folder contain valid PostgreSQL connection strings.
- Suffix: `_PROD`
This helps distinguish production secrets from those in other environments.
- Previous versions: `10`
When a secret is updated, its new value is validated against the specified number of prior versions. This is useful for enforcing rotation policies and ensuring that secrets are not recycled.