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 10:09:24 UTC
(tooling-agents) branch main updated: ASVS L3 audit: 3.4.4 (ch03_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 52fea27 ASVS L3 audit: 3.4.4 (ch03_general)
52fea27 is described below
commit 52fea27854de18b831aeb80a9b19522a6abdbde8
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Wed Apr 22 12:09:19 2026 +0200
ASVS L3 audit: 3.4.4 (ch03_general)
---
.../reports/steve/v3/d0aa7e9/ch03_general/3.4.4.md | 344 +++++++++++++++++++++
1 file changed, 344 insertions(+)
diff --git a/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch03_general/3.4.4.md b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch03_general/3.4.4.md
new file mode 100644
index 0000000..6c044df
--- /dev/null
+++ b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch03_general/3.4.4.md
@@ -0,0 +1,344 @@
+# ASVS 3.4.4 Security Audit Report
+
+## Executive Summary
+
+**Audit Metadata:**
+- **Repository:** apache/steve
+- **Audit Date:** Apr 22, 2026
+- **Auditor:** Tooling Agents
+- **ASVS Requirement:** 3.4.4 — Verify that all HTTP responses contain an 'X-Content-Type-Options: nosniff' header field. This instructs browsers not to use content sniffing and MIME type guessing for the given response, and to require the response's Content-Type header field value to match the destination resource. For example, the response to a request for a style is only accepted if the response's Content-Type is 'text/css'. This also enables the use of the Cross-Origin Read Blocking [...]
+- **ASVS Level:** 2
+- **Section:** Browser Security Mechanism Headers
+- **Chapter:** Web Frontend Security
+
+**Scope:**
+- Files analyzed: 2 relevant out of 49 total, 12 skipped
+- Total endpoints reviewed: 21+
+
+**Finding Summary:**
+
+| Severity | Count | Description |
+|----------|-------|-------------|
+| Critical | 0 | - |
+| High | 0 | - |
+| Medium | 1 | Complete absence of X-Content-Type-Options header across all endpoints |
+| Low | 0 | - |
+| **Total** | **1** | **Type A gap — security control entirely absent** |
+
+**Key Finding:** The application completely lacks the `X-Content-Type-Options: nosniff` response header across all 21+ HTTP endpoints. There is no middleware, after-request hook, or per-response header configuration anywhere in the audited codebase.
+
+---
+
+## Security Controls Inventory
+
+### X-Content-Type-Options Header Control
+
+| Control Aspect | Status | Evidence |
+|----------------|--------|----------|
+| Global middleware/after_request hook | **❌ ABSENT** | No `@app.after_request` or middleware in `main.py` or `pages.py` |
+| Framework-level configuration | **❌ ABSENT** | `asfquart.construct()` call in `main.py:40` sets no security header config |
+| Per-response header setting | **❌ ABSENT** | No individual response sets `X-Content-Type-Options` |
+| Static file responses | **❌ ABSENT** | `send_from_directory` calls in `pages.py:565-570` use defaults |
+| Error responses | **❌ ABSENT** | `raise_404()` at `pages.py:653` creates `quart.Response()` without header |
+
+**Coverage Assessment:** 0% — No HTTP responses include the required security header.
+
+---
+
+## Critical File Review
+
+### `v3/server/main.py`
+
+| Line(s) | Function/Code | Security Relevance | Status |
+|---------|---------------|-------------------|--------|
+| 28-43 | `create_app()` | Application factory — sole location for global middleware | ❌ No security headers configured |
+| 40 | `asfquart.construct(...)` | Framework initialization | ❌ No header policy passed |
+
+**Summary:** Application factory provides no security header middleware. This is the critical control point where global response headers should be configured.
+
+### `v3/server/pages.py`
+
+| Line(s) | Function/Code | Security Relevance | Status |
+|---------|---------------|-------------------|--------|
+| 134 | `home_page()` | HTML template response | ❌ No `nosniff` header |
+| 144 | `voter_page()` | HTML template response | ❌ No `nosniff` header |
+| 180 | `vote_on_page()` | HTML template response | ❌ No `nosniff` header |
+| 259 | `admin_page()` | HTML template response | ❌ No `nosniff` header |
+| 299 | `manage_page()` | HTML template response | ❌ No `nosniff` header |
+| 323 | `manage_stv_page()` | HTML template / redirect | ❌ No `nosniff` header |
+| 353 | `do_set_open_at_endpoint()` | `('', 204)` response | ❌ No `nosniff` header |
+| 359 | `do_set_close_at_endpoint()` | `('', 204)` response | ❌ No `nosniff` header |
+| 365 | `do_vote_endpoint()` | Redirect response | ❌ No `nosniff` header |
+| 400 | `do_create_endpoint()` | Redirect response | ❌ No `nosniff` header |
+| 423 | `do_open_endpoint()` | Redirect response | ❌ No `nosniff` header |
+| 445 | `do_close_endpoint()` | Redirect response | ❌ No `nosniff` header |
+| 463 | `do_add_issue_endpoint()` | Redirect response | ❌ No `nosniff` header |
+| 486 | `do_edit_issue_endpoint()` | Redirect response | ❌ No `nosniff` header |
+| 511 | `do_delete_issue_endpoint()` | Redirect response | ❌ No `nosniff` header |
+| 531 | `profile_page()` | HTML template response | ❌ No `nosniff` header |
+| 540 | `settings_page()` | HTML template response | ❌ No `nosniff` header |
+| 548 | `about_page()` | HTML template response | ❌ No `nosniff` header |
+| 553-562 | `serve_doc()` | **File download — HIGH RISK** | ❌ No `nosniff` — highest risk endpoint |
+| 565-566 | `serve_static()` | **CSS/JS serving — affects CORB** | ❌ No `nosniff` |
+| 570-571 | `serve_favicon()` | Static file serving | ❌ No `nosniff` |
+| 653-654 | `raise_404()` | **Manual Response construction** | ❌ No `nosniff` — bypasses any future middleware |
+| 92-112 | `_set_election_date()` | `('', 204)` response | ❌ No `nosniff` header |
+
+**Summary:** All 21+ endpoints lack the required security header. File-serving endpoints (`serve_doc`, `serve_static`) present the highest risk for MIME-sniffing attacks.
+
+---
+
+## Findings
+
+### MEDIUM SEVERITY
+
+#### Finding ASVS-344-MED-001: Complete Absence of X-Content-Type-Options Header
+
+**Severity:** MEDIUM
+**Gap Type:** Type A — Entry points with NO control
+**CWE:** CWE-693 (Protection Mechanism Failure)
+
+**Location:**
+- **Primary:** `v3/server/main.py`, function `create_app()`, lines 28–43
+- **Affected:** Every route in `v3/server/pages.py` (lines 134–570)
+
+**Related Functions Checked:**
+- `create_app()` — `main.py:28-43`
+- `home_page()` — `pages.py:134`
+- `voter_page()` — `pages.py:144`
+- `vote_on_page()` — `pages.py:180`
+- `admin_page()` — `pages.py:259`
+- `manage_page()` — `pages.py:299`
+- `serve_doc()` — `pages.py:553-562`
+- `serve_static()` — `pages.py:565-566`
+- `serve_favicon()` — `pages.py:570-571`
+- `raise_404()` — `pages.py:653-654`
+- All other endpoints listed in Critical File Review
+
+**Description:**
+
+The application does not set the `X-Content-Type-Options: nosniff` header on any HTTP response. No global middleware, after-request handler, or framework configuration was found that would inject this header. All 21+ routes return responses without this protection.
+
+**Vulnerable Code:**
+
+*Application Factory (`main.py:28-43`):*
+```python
+def create_app():
+ "Create the asfquart app and its endpoints."
+
+ # ... OAuth config ...
+
+ app = asfquart.construct('steve', app_dir=THIS_DIR, static_folder=None)
+
+ # Now that we have an APP, import modules that will add page
+ # and API endpoints into the APP.
+ import pages # noqa: F401
+ import api # noqa: F401
+
+ return app # also available as asfquart.APP now
+ # ^^^ No after_request hook, no middleware, no security headers configured
+```
+
+*Error Response Handler (`pages.py:653-654`):*
+```python
+def raise_404(template, data):
+ content = asfquart.utils.render(template, data)
+ quart.abort(quart.Response(content, status=404, mimetype='text/html'))
+ # ^^^ Manually constructed Response object with no security headers
+```
+
+**Affected Endpoints:**
+
+| Route | Handler | Response Type | Line |
+|-------|---------|---------------|------|
+| `GET /` | `home_page()` | HTML template | 134 |
+| `GET /voter` | `voter_page()` | HTML template | 144 |
+| `GET /vote-on/<eid>` | `vote_on_page()` | HTML template | 180 |
+| `GET /admin` | `admin_page()` | HTML template | 259 |
+| `GET /manage/<eid>` | `manage_page()` | HTML template | 299 |
+| `GET /manage-stv/<eid>/<iid>` | `manage_stv_page()` | HTML template / redirect | 323 |
+| `POST /do-set-open_at/<eid>` | `do_set_open_at_endpoint()` | `('', 204)` | 353 |
+| `POST /do-set-close_at/<eid>` | `do_set_close_at_endpoint()` | `('', 204)` | 359 |
+| `POST /do-vote/<eid>` | `do_vote_endpoint()` | redirect | 365 |
+| `POST /do-create-election` | `do_create_endpoint()` | redirect | 400 |
+| `GET /do-open/<eid>` | `do_open_endpoint()` | redirect | 423 |
+| `GET /do-close/<eid>` | `do_close_endpoint()` | redirect | 445 |
+| `POST /do-add-issue/<eid>` | `do_add_issue_endpoint()` | redirect | 463 |
+| `POST /do-edit-issue/<eid>/<iid>` | `do_edit_issue_endpoint()` | redirect | 486 |
+| `POST /do-delete-issue/<eid>/<iid>` | `do_delete_issue_endpoint()` | redirect | 511 |
+| `GET /profile` | `profile_page()` | HTML template | 531 |
+| `GET /settings` | `settings_page()` | HTML template | 540 |
+| `GET /about` | `about_page()` | HTML template | 548 |
+| `GET /docs/<iid>/<docname>` | `serve_doc()` | **file download** | 553 |
+| `GET /static/<path:filename>` | `serve_static()` | **static file** | 565 |
+| `GET /favicon.ico` | `serve_favicon()` | static file | 570 |
+| Error paths | `raise_404()` | `quart.Response(...)` | 653 |
+
+**Data Flow:**
+```
+Client Request → Quart Router → Handler Function → Response Object → Client
+ ↑
+ NO X-Content-Type-Options header injected
+ at any point in this chain
+```
+
+**Proof of Concept:**
+
+```bash
+# Test any endpoint - header will be absent
+curl -v https://steve.example.org/about 2>&1 | grep -i "x-content-type"
+# (empty — header is absent)
+
+# Critical: Static/document serving is unprotected
+curl -v https://steve.example.org/static/style.css 2>&1 | grep -i "x-content-type"
+# (empty — browser may MIME-sniff the response)
+
+curl -v https://steve.example.org/docs/some-iid/document.pdf 2>&1 | grep -i "x-content-type"
+# (empty — uploaded documents could be reinterpreted by browser)
+```
+
+**Impact:**
+
+1. **MIME-Sniffing Attacks:** Browsers may MIME-sniff responses and interpret content differently than the declared `Content-Type`, potentially executing attacker-controlled content as active scripts
+
+2. **Document Serving Vulnerability:** The `/docs/<iid>/<docname>` endpoint (line 553) serves user-associated documents — without `nosniff`, a document served as `text/plain` could be sniffed and executed as `text/html` containing JavaScript
+
+3. **Weakened CORB Protection:** The `/static/<path:filename>` endpoint (line 565) serves CSS/JS — without `nosniff`, Cross-Origin Read Blocking (CORB) protection in browsers is weakened
+
+4. **Voting System Context:** In the context of a voting system, MIME-sniffing XSS could lead to session hijacking or vote manipulation
+
+**Remediation:**
+
+**Primary Fix — Add Global After-Request Hook:**
+
+Add a global `after_request` hook in the application factory that sets the header on every response:
+
+```python
+# In main.py, within create_app():
+
+def create_app():
+ "Create the asfquart app and its endpoints."
+
+ # ... existing code ...
+
+ app = asfquart.construct('steve', app_dir=THIS_DIR, static_folder=None)
+
+ # Add security headers to ALL responses
+ @app.after_request
+ async def set_security_headers(response):
+ response.headers['X-Content-Type-Options'] = 'nosniff'
+ # Consider also adding other security headers per ASVS:
+ # response.headers['X-Frame-Options'] = 'DENY'
+ # response.headers['Referrer-Policy'] = 'strict-origin-when-cross-origin'
+ return response
+
+ import pages # noqa: F401
+ import api # noqa: F401
+
+ return app
+```
+
+**Secondary Fix — Defense-in-Depth for Manual Responses:**
+
+Additionally, fix the manually constructed 404 response in `pages.py`:
+
+```python
+def raise_404(template, data):
+ content = asfquart.utils.render(template, data)
+ response = quart.Response(content, status=404, mimetype='text/html')
+ response.headers['X-Content-Type-Options'] = 'nosniff'
+ quart.abort(response)
+```
+
+> **Note:** The `after_request` hook approach is preferred because it provides **single point of enforcement** and cannot be forgotten when new routes are added. The `raise_404` fix is defense-in-depth since `quart.abort()` with a Response object may bypass the `after_request` hook depending on the Quart version.
+
+---
+
+## Positive Security Patterns
+
+The following security controls are properly implemented:
+
+| Pattern | Location | Assessment |
+|---------|----------|------------|
+| **Authentication decorators on sensitive routes** | `pages.py` throughout | ✅ Consistently applied across all administrative and voting endpoints |
+| **Path traversal prevention** | `pages.py:562, 566, 571` | ✅ Uses `send_from_directory()` for file serving (framework-level protection) |
+| **Session-based access control** | `pages.py:555-559` | ✅ Checks `mayvote` before serving documents from `/docs/` endpoint |
+| **Comprehensive audit logging** | `pages.py` throughout | ✅ Security-relevant operations are logged for audit trail |
+
+---
+
+## Architecture Observations
+
+1. **No Security Header Middleware Architecture:**
+ The `create_app()` factory in `main.py` creates the application and imports endpoint modules but adds zero response middleware. This suggests security headers were not part of the initial architecture design.
+
+2. **Framework Security Capabilities Unclear:**
+ The `asfquart` framework (ASF's Quart wrapper) may or may not add security headers by default. Based on the visible code, there is no evidence it does. The application should not rely on implicit framework behavior for security controls — explicit configuration is required.
+
+3. **Manual Response Construction Risk:**
+ The `raise_404()` function constructs a `quart.Response` directly and passes it to `quart.abort()`. Depending on the Quart version, this may bypass `after_request` hooks, requiring explicit header setting as defense-in-depth.
+
+4. **File-Serving Endpoints Present Highest Risk:**
+ The `/docs/<iid>/<docname>` endpoint serves election-related documents that could contain attacker-influenced content. Without `nosniff`, MIME-type confusion attacks are possible. This endpoint should be prioritized in remediation verification.
+
+5. **API Module Not Reviewed:**
+ The `api` module is imported in `main.py` but was not provided for review. It likely contains additional endpoints that also lack the required header.
+
+---
+
+## Recommendations Summary
+
+### Immediate Actions (Priority 1)
+
+| Action | Location | Effort | Impact |
+|--------|----------|--------|--------|
+| **Add `@app.after_request` hook setting `X-Content-Type-Options: nosniff`** | `main.py:create_app()` | Low (5 lines) | ✅ Fixes all 21+ endpoints at once |
+| **Explicitly set header on manually constructed Response objects** | `pages.py:raise_404()` | Low (1 line) | ✅ Ensures error pages are protected (defense-in-depth) |
+
+### Short-Term Actions (Priority 2)
+
+| Action | Location | Effort | Impact |
+|--------|----------|--------|--------|
+| **Audit the `api` module for the same gap** | `api` module (not provided) | Low | ✅ Ensures complete coverage across all endpoints |
+| **Add verification tests** | Test suite | Medium | ✅ Prevents regression |
+
+### Long-Term Actions (Priority 3)
+
+| Action | Location | Effort | Impact |
+|--------|----------|--------|--------|
+| **Implement comprehensive security header policy** | `main.py:create_app()` | Medium | ✅ Add `X-Frame-Options`, `Referrer-Policy`, `Content-Security-Policy` per ASVS requirements |
+| **Security header documentation** | Developer documentation | Low | ✅ Ensure future maintainers understand the security architecture |
+
+---
+
+## Appendix: Files Analyzed
+
+<details>
+<summary>Click to expand file list (2 files)</summary>
+
+### Files with Security Relevance
+
+1. **`v3/server/main.py`** (relevance: 10/10)
+ - Application factory
+ - Framework initialization
+ - Global middleware configuration point
+
+2. **`v3/server/pages.py`** (relevance: 10/10)
+ - All HTTP endpoint handlers
+ - File serving endpoints
+ - Error response handlers
+ - 21+ routes reviewed
+
+### Analysis Coverage
+
+- **Total files in repository:** 49
+- **Files analyzed:** 2
+- **Files skipped:** 12
+- **Relevant files:** 2
+- **Coverage:** All HTTP response-generating code in provided files
+
+</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