You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by as...@apache.org on 2026/04/22 11:57:23 UTC
(tooling-agents) branch main updated: ASVS L3 audit: 4.2.4 (ch04_general)
This is an automated email from the ASF dual-hosted git repository.
asf-tooling pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-agents.git
The following commit(s) were added to refs/heads/main by this push:
new 9b19c78 ASVS L3 audit: 4.2.4 (ch04_general)
9b19c78 is described below
commit 9b19c784c00f553e4601877a6a9447e3e5cc13a9
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Wed Apr 22 13:57:18 2026 +0200
ASVS L3 audit: 4.2.4 (ch04_general)
---
.../reports/steve/v3/d0aa7e9/ch04_general/4.2.4.md | 289 +++++++++++++++++++++
1 file changed, 289 insertions(+)
diff --git a/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch04_general/4.2.4.md b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch04_general/4.2.4.md
new file mode 100644
index 0000000..15f4aa3
--- /dev/null
+++ b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch04_general/4.2.4.md
@@ -0,0 +1,289 @@
+# ASVS 4.2.4 Security Audit Report
+
+## Executive Summary
+
+**Repository:** apache/steve
+**Audit Date:** Apr 22, 2026
+**Auditor:** Tooling Agents
+**ASVS Requirement:** 4.2.4 — Verify that the application only accepts HTTP/2 and HTTP/3 requests where the header fields and values do not contain any CR (\r), LF (\n), or CRLF (\r\n) sequences, to prevent header injection attacks.
+**Level:** 3
+**Section:** HTTP Message Structure Validation
+**Section Description:** This section explains how the structure and header fields of an HTTP message should be validated to prevent attacks such as request smuggling, response splitting, header injection, and denial of service via overly long HTTP messages.
+
+**Files Analyzed:** 3 relevant out of 49 total, 12 skipped
+
+### Finding Summary
+
+| Severity | Count |
+|----------|-------|
+| Critical | 0 |
+| High | 0 |
+| Medium | 2 |
+| Low | 0 |
+| **Total** | **2** |
+
+**Key Finding:** No application-level CRLF header validation control exists anywhere in the codebase. The application relies entirely on the underlying ASGI server (Hypercorn) and framework (Quart/Werkzeug) for protocol-level protection, with no defense-in-depth.
+
+---
+
+## Security Controls Inventory
+
+### CRLF / Header Injection Controls
+
+| Control | Defined? | Location | Applied At Entry Points? |
+|---------|----------|----------|-------------------------|
+| Request header CRLF validation middleware | ❌ No | N/A | N/A |
+| Response header CRLF sanitization | ❌ No | N/A | N/A |
+| Redirect URL CRLF validation | ❌ No | N/A | N/A |
+| File-serving header sanitization | ❌ No | N/A | N/A |
+| HTTP protocol version enforcement | ❌ No | N/A | N/A |
+
+### Coverage Analysis
+
+| Entry Points | Total | With CRLF Control | Coverage |
+|-------------|-------|-------------------|----------|
+| All HTTP endpoints (GET + POST) | 21 | 0 | **0%** |
+| Endpoints returning redirects | 10 | 0 | **0%** |
+| Endpoints serving files | 3 | 0 | **0%** |
+
+---
+
+## Critical File Review
+
+### `v3/server/pages.py`
+
+| Aspect | Status | Notes |
+|--------|--------|-------|
+| Request header CRLF validation | ❌ Missing | No `before_request` middleware |
+| Response header CRLF validation | ❌ Missing | No `after_request` middleware |
+| Redirect URL sanitization | ❌ Missing | Relies on framework behavior |
+| File serving header safety | ⚠️ Framework-dependent | `send_from_directory` handles Content-Disposition |
+| CRLF in flash messages → cookies | ✅ Safe | Session serialization encodes values |
+
+### `v3/server/main.py`
+
+| Aspect | Status | Notes |
+|--------|--------|-------|
+| HTTP/2 support configuration | ⚠️ Implicit | Hypercorn supports HTTP/2 by default |
+| HTTP/3 support configuration | ❌ Not configured | No H3 configuration visible |
+| Protocol-level header validation | ⚠️ Framework-dependent | No explicit Hypercorn config for strict validation |
+| Middleware registration | ❌ No security middleware | `create_app()` adds no header validation |
+
+---
+
+## Findings
+
+### Medium Severity
+
+#### ASVS-424-MED-001: No Application-Level CRLF Validation on HTTP Request Headers
+
+**Severity:** Medium
+**Gap Type:** Type A — Entry point with NO control
+**File:** `v3/server/pages.py` (all routes), `v3/server/main.py`
+**Lines:** All route definitions (lines 114–628 in `pages.py`)
+
+**Description:**
+
+The application has zero middleware, decorators, or configuration that validates incoming HTTP request headers for CR (`\r`), LF (`\n`), or CRLF (`\r\n`) sequences. ASVS 4.2.4 specifically requires this validation for HTTP/2 and HTTP/3 requests. The application supports HTTP/2 when deployed via Hypercorn (`main.py` lines 90–107) but does not add any application-layer header validation.
+
+**Vulnerable Pattern (absence of control):**
+
+`v3/server/main.py` — Application creation with no header validation middleware:
+```python
+def create_app():
+ # ...
+ app = asfquart.construct('steve', app_dir=THIS_DIR, static_folder=None)
+ import pages # noqa: F401
+ import api # noqa: F401
+ return app
+ # No @app.before_request or middleware to validate headers for CRLF
+```
+
+`v3/server/pages.py` — All 21 routes lack header validation:
+```python
+@APP.get('/')
+@APP.use_template(TEMPLATES / 'home.ezt')
+async def home_page():
+ # No request header validation
+ result = await basic_info()
+ ...
+```
+
+**Data Flow:**
+
+`HTTP/2 client` → `Hypercorn ASGI` → `Quart framework` → `route handler` → **No CRLF check at any layer the application controls**
+
+**Proof of Concept:**
+
+An attacker sending an HTTP/2 request with a crafted header value containing `\r\n` (e.g., via a malicious HTTP/2 client or intermediary proxy that doesn't strictly validate):
+
+```
+:method: GET
+:path: /voter
+x-custom: value\r\nInjected-Header: malicious
+```
+
+While a compliant HTTP/2 implementation at the transport layer should reject this, the application has no defense-in-depth and cannot verify this behavior. This becomes critical when HTTP version conversion occurs at a reverse proxy layer (as noted in the ASVS section description about converting between HTTP versions).
+
+**Impact:**
+
+- Header injection attacks if any intermediary or transport layer passes through CRLF characters
+- Response splitting potential when protocol downgrade occurs (HTTP/2 → HTTP/1.1 at reverse proxy)
+- No ability to detect or log header injection attempts for security monitoring
+
+**Remediation:**
+
+Add Quart `before_request` middleware to validate all incoming request headers:
+
+```python
+import re
+
+CRLF_PATTERN = re.compile(r'[\r\n]')
+
+@APP.before_request
+async def validate_headers_no_crlf():
+ """Reject requests with CR/LF/CRLF in header names or values (ASVS 4.2.4)."""
+ for header_name, header_value in quart.request.headers:
+ if CRLF_PATTERN.search(header_name) or CRLF_PATTERN.search(header_value):
+ _LOGGER.warning(
+ f'Rejected request with CRLF in header: {header_name!r}'
+ )
+ quart.abort(400, 'Invalid characters in request headers')
+```
+
+---
+
+#### ASVS-424-MED-002: Redirect Responses Constructed with URL Path Parameters Without CRLF Sanitization
+
+**Severity:** Medium
+**Gap Type:** Type A — No CRLF validation before header construction
+**File:** `v3/server/pages.py`
+**Lines:** 303, 363, 413, 416, 434, 455, 477, 496, 521, 547, 567
+
+**Description:**
+
+Multiple POST and GET endpoints construct redirect `Location` headers using URL path parameters (`eid`, or values derived from form input). While the `load_election` decorator provides database validation that would reject most injected values, not all redirect paths go through this validation, and the application places no explicit CRLF check on data flowing into response headers.
+
+**Vulnerable Code Paths:**
+
+`pages.py` line 455 — Redirect after election creation uses form-derived data:
+```python
+@APP.post('/do-create-election')
+@asfquart.auth.require({R.pmc_member})
+async def do_create_endpoint():
+ form = edict(await quart.request.form)
+ election = steve.election.Election.create(DB_FNAME, form.title, result.uid)
+ # election.eid is system-generated, but no CRLF validation exists
+ return quart.redirect(f'/manage/{election.eid}', code=303)
+```
+
+`pages.py` line 363 — Redirect with database-loaded EID:
+```python
+async def manage_stv_page(election, issue):
+ if issue.vtype != 'stv':
+ return quart.redirect(f'/manage/{election.eid}', code=303)
+```
+
+`pages.py` lines 413-434 — Multiple redirect paths in vote submission:
+```python
+async def do_vote_endpoint(election):
+ # ...
+ return quart.redirect(f'/vote-on/{election.eid}', code=303)
+ # ... (multiple exit points)
+ return quart.redirect('/voter', code=303)
+```
+
+**Data Flow:**
+
+`User request with eid` → `load_election (DB lookup)` → `election.eid in redirect Location header` → **No CRLF check**
+
+**Mitigating Factor:** The `load_election` decorator validates `eid` against the database, which would reject values containing CRLF (no matching election). Quart/Werkzeug also URL-encodes redirect locations in recent versions. However, this is implicit rather than explicit defense.
+
+**Impact:**
+
+- If a future code change introduces a redirect path without database validation, header injection becomes possible
+- The framework-level protection is version-dependent and not verified
+- No defense-in-depth against response splitting
+
+**Remediation:**
+
+Create a safe redirect helper that validates the URL:
+
+```python
+def safe_redirect(url, code=303):
+ """Redirect with CRLF validation to prevent header injection."""
+ if CRLF_PATTERN.search(url):
+ _LOGGER.warning(f'Blocked redirect with CRLF in URL: {url!r}')
+ quart.abort(400, 'Invalid redirect URL')
+ return quart.redirect(url, code=code)
+```
+
+Additionally, add an `after_request` hook to validate all outgoing headers:
+
+```python
+@APP.after_request
+async def validate_response_headers(response):
+ """Ensure no CRLF injection in response headers."""
+ for header_name, header_value in response.headers:
+ if CRLF_PATTERN.search(str(header_value)):
+ _LOGGER.error(
+ f'CRLF detected in response header: {header_name}'
+ )
+ quart.abort(500)
+ return response
+```
+
+---
+
+## Positive Security Patterns
+
+1. **Database validation as implicit CRLF barrier**: The `load_election` and `load_election_issue` decorators validate path parameters against the database, which would reject values containing CRLF characters (no matching records). This provides accidental but effective mitigation for redirect injection via EID/IID parameters.
+
+2. **Authentication layer before all sensitive endpoints**: All state-changing endpoints require authentication via `@asfquart.auth.require`, which means unauthenticated attackers cannot reach most header injection points.
+
+3. **Framework-level protections**: Quart (built on Werkzeug) URL-encodes redirect Location values and properly serializes session cookies, providing baseline protection against common header injection vectors.
+
+4. **No custom response header manipulation**: The application does not set custom response headers from user input anywhere in the codebase, significantly reducing the attack surface for response header injection.
+
+---
+
+## Architecture Observations
+
+1. **No HTTP message structure validation layer**: The application lacks any middleware or hook (`before_request` / `after_request`) for HTTP message structure validation. ASVS Section 4.2 ("HTTP Message Structure Validation") recommends multiple controls that should be implemented as middleware, but none exist.
+
+2. **HTTP version conversion risk**: The ASVS section description explicitly calls out risks when "converting HTTP messages between different HTTP versions." The application can be deployed behind a reverse proxy (common for ASGI/Hypercorn), where HTTP/2 from clients is converted to HTTP/1.1 for the application. Headers containing CRLF that pass HTTP/2 binary framing could become injection vectors after protocol downgrade.
+
+3. **Sole reliance on framework/transport**: All HTTP header safety depends entirely on Quart and Hypercorn's built-in behavior, which is version-dependent and not verified. A Hypercorn version upgrade or configuration change could alter this behavior.
+
+---
+
+## Recommendations Summary
+
+### Immediate Actions
+
+1. **Add `before_request` middleware to validate all incoming request headers for CRLF sequences** — Directly satisfies ASVS 4.2.4 (Low effort, High impact)
+
+2. **Add `after_request` middleware to validate all outgoing response headers for CRLF sequences** — Defense-in-depth against response splitting (Low effort, High impact)
+
+### Short-term Actions
+
+3. **Create a `safe_redirect()` helper function that validates URLs before issuing redirects** — Prevents future regression (Low effort, Medium impact)
+
+4. **Configure Hypercorn with explicit HTTP/2 settings and strict header validation if available** — Explicit protocol-level security (Low effort, Medium impact)
+
+### Long-term Actions
+
+5. **Add security-focused integration tests that send requests with CRLF in headers and verify rejection** — Validates the control works (Medium effort, High impact)
+
+---
+
+## Appendix: Files Analyzed
+
+<details>
+<summary>Click to expand file list</summary>
+
+- `v3/server/pages.py` (relevance: 8)
+- `v3/server/main.py` (relevance: 5)
+- `v3/ARCHITECTURE.md` (relevance: 2)
+
+</details>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org