GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.contentstack.com — Regex Validate Plugin | V2.x.x | Contentstack Regex Validate Pluginsignal_cellular_altIntermediateschedule8 min readupdateLast updated August 21, 2026 OverviewThe cm:stacks:validate-regex command scans a Contentstack stack's content type and global field format properties (the regex pattern that validates a field's input) for regex patterns vulnerable to catastrophic backtracking, a condition where a regex engine's evaluation time grows exponentially for certain inputs and can bring a server to a halt. It checks each pattern using the safe-regex library and reports findings as a terminal table and a results.csv file. See How Regex Validation Works for detail. Run this command to:
This command only reads your stack's content types and global fields. It never modifies them. PrerequisitesBefore running the command, ensure:
InstallationThis command is not bundled with the core CLI and must be installed as a plugin: 1 csdx plugins:install @contentstack/cli-cm-regex-validate Verify the plugin is installed: 1 csdx plugins You should see @contentstack/cli-cm-regex-validate in the list. Command ReferenceCommand Syntax1 csdx cm:stacks:validate-regex [FLAGS] Flags
Flag Details--alias / -a --contentType --globalField --filePath Note: At least one of --contentType or --globalField must be selected. If neither is provided, the CLI enters interactive mode and prompts you to choose. Interactive ModeIf flags are not fully provided, the CLI fills in the gaps via prompts: Missing --alias: The CLI displays: 1 ? Enter management token alias: The alias is required and cannot be left blank. Neither --contentType nor --globalField provided: The CLI displays a checkbox prompt: 123 ? Select the module you need to check. ◉ Content Type ◯ Global Field Content Type is selected by default. You must select at least one option. You can skip all prompts by providing all required flags upfront. OutputTerminal TableAfter scanning, the CLI prints a summary table to the terminal: 12345678 The following table shows the invalid regexes present in your stack. ┌───────────────┬────────────────────┬─────────────────────┬──────────────────────┐ │ Module │ Title │ UID │ Invalid Regex Count │ ├───────────────┼────────────────────┼─────────────────────┼──────────────────────┤ │ Content Type │ Blog Post │ blog_post │ 2 │ │ Global Field │ Author Info │ author_info │ 1 │ └───────────────┴────────────────────┴─────────────────────┴──────────────────────┘ If no invalid regexes are found: 1 There are no invalid regexes in your stack. CSV OutputA results.csv file is generated only when invalid regexes are found. It is saved to the --filePath directory (or the default results/ folder relative to the plugin's install location) and contains one row per invalid regex with the following columns (in this order):
Example CSV content: 123 Field Path,Field Title,Field UID,Invalid Regex,Module,Title,UID author.email,Email,email,(a+)+@domain\.com,Content Type,Blog Post,blog_post phone,Phone Number,phone,(\d+)*,Global Field,Author Info,author_info After the table, the CLI also prints: 123 CSV output stored successfully at: /path/to/results/results.csv To know more, visit our documentation site on catastrophic-backtracking: https://www.contentstack.com/docs/developers/create-content-types/validation-regex/#prevent-catastrophic-backtracking ExamplesExample 1: Interactive Mode (No Flags)Run without flags and answer all prompts: 1 csdx cm:stacks:validate-regex The CLI will prompt for:
Example 2: Scan Content Types Only1 csdx cm:stacks:validate-regex -a my-stack-token --contentType Scans all content types in the stack associated with the my-stack-token alias. Example 3: Scan Global Fields Only1 csdx cm:stacks:validate-regex -a my-stack-token --globalField Scans all global fields in the stack. Example 4: Scan Both Content Types and Global Fields1 csdx cm:stacks:validate-regex -a my-stack-token --contentType --globalField Scans both modules in a single run. Example 5: Save CSV to a Custom Directory1 csdx cm:stacks:validate-regex -a my-stack-token --contentType --globalField --filePath /Users/name/Desktop/regex-audit Saves results.csv to /Users/name/Desktop/regex-audit/results.csv. The directory is created if it does not already exist. Example 6: Automation ScriptUse in a CI/CD or audit script with all flags provided to skip interactive prompts. Check the exit code before checking for results.csv, since a command failure and a clean scan both leave no CSV file behind: 12345678910111213141516 #!/bin/bash ALIAS="ci-management-token" OUTPUT_DIR="./regex-audit-$(date +%Y%m%d)" csdx cm:stacks:validate-regex -a "$ALIAS" --contentType --globalField --filePath "$OUTPUT_DIR" EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then echo "Command failed with exit code $EXIT_CODE." exit $EXIT_CODE elif [ -f "$OUTPUT_DIR/results.csv" ]; then echo "Invalid regexes found. Review: $OUTPUT_DIR/results.csv" exit 1 else echo "No invalid regexes found." fi How Regex Validation WorksCatastrophic BacktrackingThe cm:stacks:validate-regex command scans a Contentstack stack and identifies regex patterns in content type and global field format properties that are vulnerable to catastrophic backtracking: a condition where a regex engine enters exponential retry loops when evaluating certain inputs, which can bring a server to a halt. Common causes include nested quantifiers like (a+)+ or (.*)*. Regex Format Property: In Contentstack, certain field types (for example Single-line Text, Multi-line Text) allow you to configure a format property (a regex pattern that validates field input). If this regex is poorly written, it can cause catastrophic backtracking, as defined above. The safe-regex LibraryThe command uses the safe-regex library to test each regex pattern:
Results are displayed as a terminal table and saved to a CSV file for further review. Troubleshooting"Token not found. Add a token using csdx auth:tokens:add"Root Cause: The alias provided with -a does not match any stored management token. Resolution:
"Error in connecting to the stack. Please try again."Root Causes: This message covers a range of underlying issues, including:
Resolution:
No results printed (no table, no CSV)Root Cause: No invalid regexes were found in the scanned modules. Resolution: No action required. This is the expected outcome when all format fields in your stack contain safe regex patterns. Limitations
Next Steps
| |||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |