fix: prevent ReDoS in REGEX comparator (CWE-1333) and resource exhaustion in generatePermutations (CWE-770)#381
Conversation
…eratePermutations - Adds isSafeRegexPattern() to validate regex patterns before evaluation (prevents catastrophic backtracking via nested quantifiers) - Limits pattern length to 500 chars and nesting depth to 20 levels - Rejects patterns containing nested quantifiers (primary ReDoS vector) - Adds MAX_PERMUTATIONS=10,000 limit to generatePermutations() (prevents exponential memory exhaustion from Cartesian product) Security: LWHS-2026-001
|
@cultofrozen is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
🔒 Security Note for Vercel Security Team This PR fixes two security vulnerabilities discovered during a code audit:
These findings may be eligible for the Vercel Open Source Bug Bounty Program (HackerOne). Please direct any questions to this PR thread or the associated advisory submission. |
…rflow (SvelteKit) - Adds 1 MB limit on valuesUint8Array before JSON.parse() in deserialization (prevents memory exhaustion from oversized JWE payloads) - Adds MAX_PERMUTATIONS=10,000 limit to SvelteKit generatePermutations() (matching same fix applied to Next.js version in PR vercel#381) Security: CWE-770 (Allocation Without Limits or Throttling)
|
@vercel/security This PR fixes 4 security vulnerabilities (ReDoS CWE-1333 + Resource Exhaustion CWE-770). Would appreciate a security team review when available. These findings may be eligible for the Vercel Open Source Bug Bounty program. |
Summary
Fixes two security vulnerabilities discovered during a code audit of the Vercel flags ecosystem.
1. ReDoS via Unrestricted Regex Pattern in Flag Evaluation (Medium Severity)
File:
packages/vercel-flags-core/src/evaluate.ts(lines 303-321)The
REGEXandNOT_REGEXcomparators constructnew RegExp(rhs.pattern, rhs.flags)where the pattern comes from the flag definition datafile without ANY validation. A malicious or compromised flag definition could contain a catastrophic backtracking pattern like/(a+)+b/that, when evaluated against a 10,000-character string, consumes CPU for seconds/minutes causing a denial of service.The only existing protection was
MAX_REGEX_INPUT_LENGTH = 10_000which limits the INPUT string, not the regex pattern itself.Fix:
MAX_REGEX_PATTERN_LENGTH = 500to limit pattern lengthisSafeRegexPattern()function that:(a+)+b,(a*)*) — the primary ReDoS vectorisSafeRegexPattern()check in both REGEX and NOT_REGEX comparators2. Exponential Resource Exhaustion in generatePermutations (Medium Severity)
File:
packages/flags/src/next/precompute.ts(lines 190-225)The
generatePermutations()function computes the Cartesian product of all flag options without any limit. For example:Each permutation is individually serialized and signed. This causes uncontrolled memory consumption and can crash the build process.
Fix:
MAX_PERMUTATIONS = 10_000constantVerification
Both fixes are additive (add new checks before potentially dangerous operations) and do not change the behavior for flags with safe regex patterns or reasonable numbers of options.
No existing tests were modified — the changes only restrict previously unbounded operations.
Related