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 12:56:04 UTC
(tooling-agents) branch main updated: ASVS L3 audit: 5.4.3 (ch05_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 7d4bc8f ASVS L3 audit: 5.4.3 (ch05_general)
7d4bc8f is described below
commit 7d4bc8f9048510b05c19fdfb7aeb639c9f81f632
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Wed Apr 22 14:56:00 2026 +0200
ASVS L3 audit: 5.4.3 (ch05_general)
---
.../reports/steve/v3/d0aa7e9/ch05_general/5.4.3.md | 272 +++++++++++++++++++++
1 file changed, 272 insertions(+)
diff --git a/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch05_general/5.4.3.md b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch05_general/5.4.3.md
new file mode 100644
index 0000000..df69bb9
--- /dev/null
+++ b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch05_general/5.4.3.md
@@ -0,0 +1,272 @@
+# ASVS 5.4.3 Security Audit Report
+
+## Executive Summary
+
+- **Repository:** apache/steve
+- **Audit Date:** Apr 22, 2026
+- **Auditor:** Tooling Agents
+- **ASVS Requirement:** 5.4.3 — Verify that files obtained from untrusted sources are scanned by antivirus scanners to prevent serving of known malicious content.
+ - **Level:** 2
+ - **Section:** File Download
+ - **Section Description:** This section contains requirements to mitigate risks when serving files to be downloaded, including path traversal and injection attacks. This also includes making sure they don't contain dangerous content.
+ - **Chapter:** File Handling
+ - **Control Objective:** The use of files can present a variety of risks to the application, including denial of service, unauthorized access, and storage exhaustion. This chapter includes requirements to address these risks.
+- **Files Analyzed:** 1 relevant out of 49 total, 12 skipped
+
+### Finding Summary
+
+| Severity | Count | Status |
+|----------|-------|--------|
+| Critical | 0 | ✅ None found |
+| High | 0 | ✅ None found |
+| Medium | 1 | ⚠️ Requires attention |
+| Low | 0 | ✅ None found |
+
+**Key Finding:** The codebase provides a document serving endpoint (`/docs/<iid>/<docname>`) that delivers files associated with election issues to authenticated voters. There is **no antivirus scanning or malicious content detection** implemented anywhere in the file serving pipeline. Files are served directly from the filesystem without any content inspection.
+
+---
+
+## Security Controls Inventory
+
+| Control | Defined | Location | Applied At | Coverage |
+|---------|---------|----------|------------|----------|
+| Antivirus/malware scanning | ❌ Not defined | N/A | N/A | **0% - No scanning exists** |
+| Content-Type validation | ❌ Not defined | N/A | N/A | 0% |
+| File content inspection | ❌ Not defined | N/A | N/A | 0% |
+| Authorization check for docs | ✅ Defined | `serve_doc` line ~643-646 | `/docs/<iid>/<docname>` | Partial |
+| Authentication for file access | ✅ Defined | `@asfquart.auth.require` | `/docs/<iid>/<docname>` | Applied |
+
+---
+
+## Critical File Review
+
+### Files Analyzed
+
+| File | Risk Level | File Serving? | AV Scanning? | Notes |
+|------|-----------|--------------|--------------|-------|
+| `v3/server/pages.py` | HIGH | Yes — `serve_doc`, `serve_static`, `serve_favicon` | None | Primary file serving module |
+
+### File Serving Endpoints
+
+| Endpoint | Serves User Content? | Auth Required? | AV Scan? | Risk |
+|----------|---------------------|----------------|----------|------|
+| `/docs/<iid>/<docname>` | Yes — election documents | Yes (session + mayvote check) | ❌ | **MEDIUM** — admin-placed files served to voters |
+| `/static/<path:filename>` | No — developer static assets | No | N/A | LOW — developer-controlled content |
+| `/favicon.ico` | No — static favicon | No | N/A | Negligible |
+
+---
+
+## Findings
+
+### Medium Severity
+
+#### Finding ASVS-543-MED-001
+
+**Title:** Files served to voters from `/docs/` endpoint undergo no antivirus or malicious content scanning
+
+**Severity:** MEDIUM
+
+**Location:**
+- **File:** `v3/server/pages.py`
+- **Function:** `serve_doc` (lines ~638-658)
+- **Endpoint:** `GET /docs/<iid>/<docname>`
+
+**Related Functions Checked:**
+- `rewrite_description` (line ~52) — Converts `doc:filename` references to download links
+- `vote_on_page` (line ~308) — Renders documents to voters
+
+**Description:**
+
+The document serving endpoint allows authenticated voters to download files associated with election issues. While the endpoint implements proper authentication and authorization checks, it completely bypasses any antivirus or malicious content scanning. Files are served directly from the filesystem without inspection, creating a potential vector for malware distribution to voters.
+
+**Gap Classification:** **Type A** — Entry point with NO control. No antivirus scanning control exists anywhere in the codebase.
+
+**Vulnerable Code:**
+
+```python
+# Serve supporting documents for an issue
+@APP.get('/docs/<iid>/<docname>')
+@asfquart.auth.require # fine-grained per-doc authz within the handler
+async def serve_doc(iid, docname):
+ result = await basic_info() # get PID ### grr: called uid
+
+ db = steve.election.Election.open_database(DB_FNAME)
+ row = db.q_get_mayvote.first_row(result.uid, iid)
+ if not row:
+ # Nothing fancy. Just pretend the file does not exist
+ quart.abort(404)
+ # NOTREACHED
+
+ ### verify the propriety of DOCNAME.
+
+ # Return per-issue document.
+ return await quart.send_from_directory(DOCSDIR / iid, docname)
+```
+
+**Supporting Context:**
+
+The `rewrite_description` function confirms documents are an intended feature:
+```python
+def rewrite_description(issue):
+ import re
+ desc = issue.description
+ def repl(match):
+ filename = match.group(1)
+ return f'<a href="/docs/{issue.iid}/{filename}">{filename}</a>'
+ desc = re.sub(r'doc:([^\s]+)', repl, desc)
+ issue.description = f'<pre>{desc}</pre>'
+```
+
+**Data Flow:**
+
+```
+File on disk (DOCSDIR/<iid>/<docname>)
+ → Authorization check (mayvote table) ✅
+ → Antivirus/malware scan ❌ MISSING
+ → quart.send_from_directory() serves file directly to voter's browser
+```
+
+**Attack Scenario:**
+
+1. An election administrator (any committer per current auth model) places a document in `DOCSDIR/<iid>/` — either through CLI tools, server access, or a file upload mechanism outside this codebase.
+2. The document contains known malware (e.g., a weaponized PDF, malicious Office document, or an executable disguised with a benign extension).
+3. The administrator references it in an issue description using `doc:malicious.pdf`.
+4. When voters access the election via `/vote-on/<eid>`, they see the document link rendered by `rewrite_description`.
+5. Clicking the link triggers `GET /docs/<iid>/malicious.pdf`, which passes authorization (voter has `mayvote` entry) and serves the malicious file directly.
+
+**Proof of Concept:**
+
+```http
+GET /docs/issue-abc123/report.pdf HTTP/1.1
+Host: voting.example.org
+Cookie: session=<valid_voter_session>
+```
+
+If `report.pdf` contains known malware signatures, it will be served without detection.
+
+**Impact:**
+
+- Malicious files served to voters could compromise voter workstations
+- In an election system context, compromised voter machines could lead to vote manipulation or credential theft
+- The trust relationship between the voting system and voters amplifies the risk — voters are more likely to open documents from the official voting platform
+
+**Remediation:**
+
+Integrate antivirus scanning at the point where files are placed into `DOCSDIR` (upload time) and optionally at serve time:
+
+```python
+import subprocess
+import shlex
+
+class AVScanError(Exception):
+ pass
+
+def scan_file(filepath: pathlib.Path) -> bool:
+ """Scan a file using ClamAV (clamdscan for daemon mode).
+ Returns True if clean, raises AVScanError if malicious or scan fails.
+ """
+ try:
+ result = subprocess.run(
+ ['clamdscan', '--no-summary', str(filepath)],
+ capture_output=True, text=True, timeout=30
+ )
+ if result.returncode == 1:
+ _LOGGER.warning(f'Malware detected in {filepath}: {result.stdout.strip()}')
+ raise AVScanError(f'Malicious content detected: {result.stdout.strip()}')
+ elif result.returncode != 0:
+ _LOGGER.error(f'AV scan error for {filepath}: {result.stderr.strip()}')
+ raise AVScanError('Antivirus scan failed')
+ return True
+ except subprocess.TimeoutExpired:
+ raise AVScanError('Antivirus scan timed out')
+
+
+@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 docname to prevent path traversal
+ safe_name = pathlib.Path(docname).name
+ if safe_name != docname or '..' in docname:
+ quart.abort(400)
+
+ filepath = DOCSDIR / iid / safe_name
+ if not filepath.is_file():
+ quart.abort(404)
+
+ # Scan file before serving (defense in depth)
+ try:
+ scan_file(filepath)
+ except AVScanError as e:
+ _LOGGER.error(f'Blocked serving {filepath} to {result.uid}: {e}')
+ quart.abort(403, 'File failed security scan')
+
+ return await quart.send_from_directory(DOCSDIR / iid, safe_name)
+```
+
+Additionally, implement scanning at the point of file ingestion (upload or placement):
+- Hook into file upload/placement workflow to scan before writing to `DOCSDIR`
+- Reject files that fail scanning before they reach the serving directory
+- Consider periodic background scans of `DOCSDIR` to catch newly-identified threats
+
+---
+
+## Positive Security Patterns
+
+1. **Authorization check before document serving:** The `serve_doc` handler verifies the requesting user has a `mayvote` entry for the issue before serving the document — this limits the blast radius of any malicious file to authorized voters only.
+
+2. **Use of `send_from_directory`:** Quart's `send_from_directory` provides built-in protection against basic path traversal by restricting file serving to the specified directory root.
+
+3. **Authentication on all sensitive endpoints:** All file-serving endpoints except static assets require authentication, preventing anonymous access to election documents.
+
+4. **Structured logging of security events:** User actions are consistently logged with user IDs and resource identifiers, which supports incident response.
+
+---
+
+## Architecture Observations
+
+1. **No file upload mechanism in this module:** The audited file contains no file upload endpoints. Documents in `DOCSDIR` are placed through external mechanisms (CLI tools, server access). This means the antivirus scanning integration point may need to be in a separate module or at the OS/infrastructure level.
+
+2. **Document feature is active but incomplete:** The `rewrite_description` function and `serve_doc` endpoint show that document serving is an implemented feature, yet the `### verify the propriety of DOCNAME` comment on line ~655 indicates the developer acknowledges missing validation. This incomplete state increases risk.
+
+3. **Trust boundary:** Election administrators (any committer) can reference documents that will be served to voters. The system implicitly trusts that administrators will not place malicious files, but provides no technical controls to enforce this.
+
+---
+
+## Recommendations Summary
+
+### Immediate Actions (0-30 days)
+
+| Priority | Recommendation | Effort | Impact |
+|----------|---------------|--------|--------|
+| 1 | Integrate ClamAV or similar scanner for files in `DOCSDIR` — at minimum, scan at ingestion time; optionally also at serve time for defense-in-depth | Medium | Directly satisfies ASVS 5.4.3 |
+| 2 | Complete the `### verify the propriety of DOCNAME` TODO with explicit path validation | Low | Defense-in-depth alongside `send_from_directory` |
+
+### Short-term Actions (1-3 months)
+
+| Priority | Recommendation | Effort | Impact |
+|----------|---------------|--------|--------|
+| 3 | Add file type allowlisting for `serve_doc` (e.g., only PDF, TXT, specific document types) | Low | Reduces attack surface by limiting servable file types |
+
+### Long-term Actions (3-12 months)
+
+| Priority | Recommendation | Effort | Impact |
+|----------|---------------|--------|--------|
+| 4 | Implement a controlled file upload endpoint with scanning, rather than relying on out-of-band file placement | Medium | Creates a single chokepoint for content validation |
+
+---
+
+## Appendix: Files Analyzed
+
+<details>
+<summary>Click to expand file list (1 file)</summary>
+
+- `v3/server/pages.py` (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