Summary
YesWiki's Bazar form field calculator passes user-controlled formulas through an insecure regex-based sanitizer and into PHP's eval() function.
An attacker who can supply crafted formulas may trigger regular expression denial of service or bypass filtering to execute arbitrary PHP code on the server.
Affected context
The vulnerability arises in YesWiki deployments that expose the Bazar form field calculator feature, where end users can define or submit mathematical formulas.
The server attempts to validate these formulas using recursive regular expressions before evaluating them with eval().
In environments where untrusted or semi-trusted users can influence calculator field content, this design creates a risky execution path that can be abused for both denial of service and arbitrary code execution, depending on the effectiveness of the filtering.
Exploit preconditions
- Attack surface: HTTP endpoints that accept or process Bazar calculator field formulas.
- Required access: Ability to create, edit, or submit forms containing calculator formulas (e.g., as an authenticated user with form-edit permissions or, in some setups, as any user with access to public forms).
- Trigger point: Submission or processing of a malicious formula string that is passed through the regex-based sanitizer and then into
eval(). - Why exploitation is possible:
- The use of complex, recursive regular expressions on attacker-controlled input allows crafted payloads to consume excessive CPU or stack, causing ReDoS or stack overflows (CWE-1333).
- The security model assumes that a regex filter can fully constrain what reaches
eval(), but any bypass or edge case in the pattern permits direct injection of arbitrary PHP code (CWE-94).
Why this happens
The core problem is a design pattern where user-controlled input is ultimately executed as code.
Instead of interpreting formulas with a constrained expression engine, the application relies on PHP's eval() and attempts to make this safe through input sanitization using complex recursive regular expressions.
This approach is inherently fragile: regular expressions are not a complete, verifiable parser for a programming language, and they can be prone to catastrophic backtracking under adversarial input.
The combination maps to:
- CWE-94 (Improper Control of Generation of Code): untrusted data influencing dynamically generated PHP code.
- CWE-1333 (Inefficient Regular Expression Complexity): regex patterns that can be driven into worst-case performance characteristics, enabling denial of service.
Potential impact
- Remote execution of arbitrary PHP code within the web server process.
- Full compromise of the YesWiki instance, including data theft, data modification, or backdoor installation.
- Abuse of the server to pivot into the broader infrastructure or run additional malicious workloads.
- Regular expression denial of service, leading to CPU exhaustion, request timeouts, or server crashes.
- Service instability and degraded performance under relatively low attack volume.
General mitigation guidance
Effective mitigation focuses on eliminating the risky pattern of feeding user input into eval() and on hardening input processing:
- Replace
eval()-based formula handling with a dedicated expression parser or a well-audited library that only supports a restricted set of operators and functions. - Treat all user-provided formulas as untrusted and interpret them within a constrained sandbox that never constructs or executes raw PHP code.
- Avoid complex recursive regular expressions for security-critical validation; prefer explicit tokenization and parsing with clear, bounded complexity.
- Narrow the feature's power by limiting allowed operators, functions, and expression length, and enforce these constraints in code rather than relying on regex alone.
- Apply the principle of least privilege: ensure the web server and application have only the minimal filesystem and system permissions needed, reducing blast radius if code execution occurs.
How teams detect issues like this
Organizations can look for this class of issue and signs of exploitation using several approaches:
- Static analysis and code review:
- Flag any use of
eval()or similar dynamic execution constructs that are reachable from HTTP request parameters or form fields. - Identify complex or nested regular expressions applied directly to user input, especially when used as a security boundary.
- Review calculator or formula-handling code paths to confirm that user input is never turned into executable PHP.
- Security testing:
- Use fuzzing or specialized tools to probe formula-processing endpoints for performance anomalies indicative of ReDoS.
- Conduct application-level penetration tests focusing on formula or script-like inputs to detect code injection risks.
- Runtime monitoring and logging:
- Monitor server CPU usage and request latency patterns for spikes tied to specific endpoints or parameters.
- Inspect logs for unusual formula inputs, errors originating from
eval(), or stack overflow / out-of-memory symptoms.
Automated SAST or security linting tools can be configured to flag dynamic code evaluation and high-complexity regexes as part of the CI pipeline.

