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:23:46 UTC
(tooling-agents) branch main updated: ASVS L3 audit: 4.1.1 (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 83cfbda ASVS L3 audit: 4.1.1 (ch04_general)
83cfbda is described below
commit 83cfbdac0e2ae9c26ac20d34732bb194728723ae
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Wed Apr 22 13:23:42 2026 +0200
ASVS L3 audit: 4.1.1 (ch04_general)
---
.../reports/steve/v3/d0aa7e9/ch04_general/4.1.1.md | 293 +++++++++++++++++++++
1 file changed, 293 insertions(+)
diff --git a/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch04_general/4.1.1.md b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch04_general/4.1.1.md
new file mode 100644
index 0000000..1641740
--- /dev/null
+++ b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch04_general/4.1.1.md
@@ -0,0 +1,293 @@
+# ASVS 4.1.1 Security Audit Report
+
+## Executive Summary
+
+**Audit Metadata:**
+- **Repository:** apache/steve
+- **Audit Date:** Apr 22, 2026
+- **Auditor:** Tooling Agents
+- **ASVS Requirement:** 4.1.1 — Verify that every HTTP response with a message body contains a Content-Type header field that matches the actual content of the response, including the charset parameter to specify safe character encoding (e.g., UTF-8, ISO-8859-1) according to IANA Media Types, such as "text/", "/+xml" and "/xml".
+- **ASVS Level:** 1
+- **Section:** Generic Web Service Security
+- **Chapter:** API and Web Service
+
+**Scope:**
+- **Files analyzed:** 3 relevant out of 49 total, 12 skipped
+- **Files reviewed:** `v3/server/pages.py`, `v3/server/api.py`, `v3/server/main.py`
+
+**Finding Summary:**
+
+| Severity | Count | IDs |
+|----------|-------|-----|
+| Critical | 0 | — |
+| High | 0 | — |
+| Medium | 2 | ASVS-411-SEV-001, ASVS-411-SEV-002 |
+| Low | 0 | — |
+| **Total** | **2** | |
+
+**Key Findings:**
+- Explicit HTML responses constructed without charset parameter in Content-Type header
+- No application-wide enforcement mechanism for Content-Type header compliance
+- Heavy reliance on framework defaults without verification layer
+
+---
+
+## Security Controls Inventory
+
+### Content-Type Header Controls
+
+| Control | Location | Defined? | Applied Consistently? | Coverage |
+|---------|----------|----------|----------------------|----------|
+| Explicit `mimetype` on Response | `raise_404` (pages.py:764-766) | Yes | **Missing charset** | 4+ call sites |
+| `@APP.use_template` decorator | 9 template endpoints | Framework-managed | Unverifiable from source | All HTML pages |
+| `send_from_directory` | `serve_doc`, `serve_static`, `serve_favicon` | Framework-managed | Unverifiable from source | Static/doc serving |
+| `quart.abort()` error pages | `_set_election_date`, `serve_doc` | Framework-managed | Unverifiable from source | Error responses |
+| `quart.redirect()` responses | 8+ redirect endpoints | Framework-managed | N/A (302/303) | Redirects |
+| Application-wide `after_request` hook | **Not present** | **No** | **N/A** | **None** |
+
+---
+
+## Critical File Review
+
+### `v3/server/pages.py` - Response Generation Analysis
+
+| Function/Route | Response Type | Content-Type Handling | Status |
+|----------------|---------------|----------------------|--------|
+| `home_page` (GET /) | Template HTML | `@APP.use_template` | Framework-dependent |
+| `voter_page` (GET /voter) | Template HTML | `@APP.use_template` | Framework-dependent |
+| `vote_on_page` (GET /vote-on/<eid>) | Template HTML | `@APP.use_template` | Framework-dependent |
+| `admin_page` (GET /admin) | Template HTML | `@APP.use_template` | Framework-dependent |
+| `manage_page` (GET /manage/<eid>) | Template HTML | `@APP.use_template` | Framework-dependent |
+| `manage_stv_page` (GET /manage-stv/<eid>/<iid>) | Template HTML / Redirect | `@APP.use_template` | Framework-dependent |
+| `profile_page` (GET /profile) | Template HTML | `@APP.use_template` | Framework-dependent |
+| `settings_page` (GET /settings) | Template HTML | `@APP.use_template` | Framework-dependent |
+| `about_page` (GET /about) | Template HTML | `@APP.use_template` | Framework-dependent |
+| `raise_404` | Explicit HTML Response | `mimetype='text/html'` | **⚠ MISSING CHARSET** |
+| `_set_election_date` | Empty 204 / abort(400) | No body / framework | OK (no body) / framework-dependent |
+| `serve_doc` (GET /docs/<iid>/<docname>) | File serving | `send_from_directory` | Framework-dependent |
+| `serve_static` (GET /static/<path:filename>) | File serving | `send_from_directory` | Framework-dependent |
+| `serve_favicon` (GET /favicon.ico) | File serving | `send_from_directory` | Framework-dependent |
+
+---
+
+## Findings
+
+### Medium Severity
+
+#### ASVS-411-SEV-001: HTML Responses Created Without Explicit Charset in Content-Type
+
+**Severity:** MEDIUM
+**Gap Type:** Type A — Entry point with no control (no charset specified)
+
+**Location:**
+- **File:** `v3/server/pages.py`
+- **Function:** `raise_404`
+- **Lines:** 764–766
+
+**Related Functions Checked:**
+- `load_election` decorator (~183)
+- `load_election_issue` decorator (~211, ~222)
+- `vote_on_page` (~318)
+- `admin_page` (~390)
+
+**Vulnerable Code:**
+```python
+def raise_404(template, data):
+ content = asfquart.utils.render(template, data)
+ quart.abort(quart.Response(content, status=404, mimetype='text/html'))
+```
+
+**Call Sites (where `raise_404` is invoked):**
+
+| Caller | Line | User-Controlled Data in Template |
+|--------|------|----------------------------------|
+| `load_election` decorator | ~183 | `eid` from URL path |
+| `load_election_issue` decorator | ~211 | `eid` from URL path |
+| `load_election_issue` decorator | ~222 | `eid`, `iid` from URL path |
+| `vote_on_page` | ~318 | `eid` from URL path |
+| `admin_page` | ~390 | `uid` from session |
+
+**Data Flow:**
+1. **Source:** User-controlled URL path parameters (`eid`, `iid`) and session-derived `uid` (passed as `pid`)
+2. **Processing:** Template rendering via `asfquart.utils.render(template, data)`
+3. **Sink:** `quart.Response(content, status=404, mimetype='text/html')` — HTML body rendered with template data
+4. **Missing Control:** `charset` parameter not specified on Content-Type header
+
+**Technical Explanation:**
+
+In Werkzeug 3.0+ (used by modern Quart), the `Response` class no longer automatically appends a `charset` to the Content-Type when only `mimetype` is supplied. Setting `mimetype='text/html'` produces a `Content-Type: text/html` header **without** `; charset=utf-8`. This violates ASVS 4.1.1 which requires text content types to include a safe character encoding specification.
+
+Without an explicit charset declaration, browsers must guess the character encoding. While modern browsers typically default to UTF-8, the absence of the charset parameter creates a window for character-encoding-based attacks (e.g., UTF-7 XSS in legacy or misconfigured clients, or multi-byte encoding attacks).
+
+**Proof of Concept:**
+```http
+GET /vote-on/nonexistent-election-id HTTP/1.1
+Host: voting.example.org
+Cookie: [valid session cookie]
+
+# Response will be:
+# HTTP/1.1 404 NOT FOUND
+# Content-Type: text/html <-- Missing "; charset=utf-8"
+#
+# <html>... rendered T_BAD_EID template with eid value ...</html>
+```
+
+**Impact:**
+
+Browsers may apply incorrect character encoding to response content. In edge cases with legacy clients or proxies that strip encoding hints, this can enable encoding-confusion XSS attacks. The rendered templates contain URL-derived values (`eid`, `iid`) making this a plausible vector.
+
+**Remediation:**
+```python
+def raise_404(template, data):
+ content = asfquart.utils.render(template, data)
+ quart.abort(quart.Response(
+ content,
+ status=404,
+ content_type='text/html; charset=utf-8'
+ ))
+```
+
+---
+
+#### ASVS-411-SEV-002: No Application-Wide Content-Type Enforcement Mechanism
+
+**Severity:** MEDIUM
+**Gap Type:** Type A — No control exists at the application level
+
+**Location:**
+- **Files:** `v3/server/pages.py` and `v3/server/main.py`
+- **Function:** Application-level — no `after_request` handler found
+
+**Related Functions Checked:**
+- All 22+ response-generating endpoints in `pages.py`
+- Application initialization in `main.py`
+
+**Observation:**
+
+The application defines 22+ response-generating endpoints but has no centralized mechanism to ensure all HTTP responses include a `Content-Type` header with an appropriate charset parameter. Content-Type correctness is entirely delegated to:
+
+1. Individual handler implementations (e.g., `raise_404` — which gets it wrong, see ASVS-411-SEV-001)
+2. Framework defaults from `@APP.use_template`, `send_from_directory`, `quart.redirect`, and `quart.abort`
+
+There is no `@APP.after_request` hook that validates or enforces Content-Type headers with charset across all response types. This means:
+
+- If the framework's default behavior changes across versions (as happened with Werkzeug 3.0's charset removal), all responses silently lose charset declarations.
+- New endpoints added by developers may omit Content-Type charset without any safety net.
+- Error responses generated by `quart.abort()` (called in `_set_election_date` at 3 places, and `serve_doc`) inherit framework defaults with no override.
+
+**Endpoints relying entirely on framework defaults (unverifiable):**
+
+| Category | Count | Examples |
+|----------|-------|----------|
+| Template pages | 9 | `home_page`, `voter_page`, `admin_page`, etc. |
+| File serving | 3 | `serve_doc`, `serve_static`, `serve_favicon` |
+| Error abort responses | 4+ | `quart.abort(400, ...)`, `quart.abort(404)` |
+
+**Data Flow:**
+
+1. **Request received** → Framework routing
+2. **Handler execution** → Response generation (template/file/redirect/error)
+3. **Response returned** → **No validation layer** → Client
+4. **Missing control:** No `after_request` hook to verify/enforce Content-Type charset
+
+**Impact:**
+
+Systemic gap — no defense-in-depth for Content-Type enforcement. If framework behavior changes or new endpoints are added without explicit Content-Type handling, responses may lack charset specification, potentially enabling encoding-based attacks.
+
+**Remediation:**
+```python
+# Add to main.py create_app() or pages.py module level:
+
+@APP.after_request
+async def set_content_type_charset(response):
+ """Ensure all text-based responses include charset=utf-8."""
+ content_type = response.content_type or ''
+ if content_type:
+ # For text/* and *+xml types, ensure charset is present
+ mime = content_type.split(';')[0].strip().lower()
+ needs_charset = (
+ mime.startswith('text/')
+ or mime.endswith('+xml')
+ or mime == 'application/xml'
+ or mime == 'application/json'
+ )
+ if needs_charset and 'charset' not in content_type.lower():
+ response.content_type = f'{mime}; charset=utf-8'
+ return response
+```
+
+---
+
+## Positive Security Patterns
+
+| Pattern | Location | Notes |
+|---------|----------|-------|
+| Authentication on all sensitive endpoints | Throughout `pages.py` | `@asfquart.auth.require({R.committer})` applied to all voter/admin/management endpoints |
+| Separate authorization for document access | `serve_doc` (line 679) | Checks `mayvote` before serving documents |
+| Template engine for HTML rendering | `@APP.use_template`, `asfquart.utils.render` | EZT templates likely handle HTML escaping, reducing XSS risk in response bodies |
+| 204 No Content for empty responses | `_set_election_date` (line 93) | Correctly returns no-body response for state-changing operations |
+| Static file isolation | `STATICDIR`, `DOCSDIR` | Separate directories for static and document content |
+
+---
+
+## Architecture Observations
+
+1. **Framework Dependency for Content-Type:** The application delegates Content-Type management to Quart/asfquart framework primitives (`use_template`, `send_from_directory`, `redirect`, `abort`) without any verification layer. This creates an implicit dependency on framework version behavior.
+
+2. **Single Explicit Response Constructor:** Only `raise_404` explicitly constructs a `quart.Response` object. This is the one place where the developer has direct control over Content-Type — and it's the one place where charset is missing.
+
+3. **`api.py` Is Empty:** The API module imports `asfquart` but defines no endpoints. If JSON API endpoints are added in the future, they will need `application/json; charset=utf-8` Content-Type handling, which the current architecture does not enforce.
+
+4. **`serve_doc` Serves Arbitrary File Types:** This endpoint serves documents from a directory based on user-provided `docname`. The MIME type is guessed by the framework. For text-based documents (`.txt`, `.html`, `.xml`, `.csv`), the guessed type may not include charset, violating ASVS 4.1.1 for those content types.
+
+---
+
+## Recommendations Summary
+
+### Immediate Actions (Priority 1)
+
+| Priority | Finding ID | Action | Effort |
+|----------|-----------|--------|--------|
+| 1 | ASVS-411-SEV-002 | Add `after_request` hook to enforce Content-Type charset on all text-based responses | Low |
+| 2 | ASVS-411-SEV-001 | Fix `raise_404` to use `content_type='text/html; charset=utf-8'` | Minimal |
+
+### Short-term Actions (Priority 2)
+
+| Priority | Finding ID | Action | Effort |
+|----------|-----------|--------|--------|
+| 3 | — | Audit `@APP.use_template` implementation to verify it includes charset in rendered HTML responses | Low |
+| 4 | — | Pin Quart/Werkzeug version in dependencies and verify Content-Type behavior in integration tests | Low |
+
+### Long-term Actions (Priority 3)
+
+- Implement automated testing for Content-Type headers across all endpoints
+- Add security linting rules to catch Response objects created without explicit charset
+- Document Content-Type requirements in developer guidelines
+
+---
+
+## Appendix: Files Analyzed
+
+<details>
+<summary>Click to expand file list (3 files)</summary>
+
+### Relevant Files Analyzed
+
+1. **`v3/server/pages.py`** (relevance: 10)
+ - Primary response generation file
+ - Contains 22+ endpoint handlers
+ - Location of ASVS-411-SEV-001 vulnerability
+
+2. **`v3/server/api.py`** (relevance: 8)
+ - API endpoint definitions (currently empty)
+ - Future JSON response handling location
+
+3. **`v3/server/main.py`** (relevance: 7)
+ - Application initialization
+ - Location for application-wide hooks (ASVS-411-SEV-002)
+
+</details>
+
+---
+
+**End of Report**
\ 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