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 04:06:08 UTC
(tooling-agents) branch main updated: ASVS L3 audit: 14.2.5 (sensitive_data_handling)
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 0c600a6 ASVS L3 audit: 14.2.5 (sensitive_data_handling)
0c600a6 is described below
commit 0c600a68591654007fb7690a8974ef95d504b8c6
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Wed Apr 22 06:06:04 2026 +0200
ASVS L3 audit: 14.2.5 (sensitive_data_handling)
---
.../v3/d0aa7e9/sensitive_data_handling/14.2.5.md | 480 +++++++++++++++++++++
1 file changed, 480 insertions(+)
diff --git a/repos/apache/ASVS/reports/steve/v3/d0aa7e9/sensitive_data_handling/14.2.5.md b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/sensitive_data_handling/14.2.5.md
new file mode 100644
index 0000000..aa5a4cc
--- /dev/null
+++ b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/sensitive_data_handling/14.2.5.md
@@ -0,0 +1,480 @@
+# ASVS 14.2.5 Security Audit Report
+
+## Executive Summary
+
+**Repository:** apache/steve
+**Audit Date:** Apr 22, 2026
+**Auditor:** Tooling Agents
+**ASVS Requirement:** 14.2.5 — Verify that caching mechanisms are configured to only cache responses which have the expected content type for that resource and do not contain sensitive, dynamic content. The web server should return a 404 or 302 response when a non-existent file is accessed rather than returning a different, valid file. This should prevent Web Cache Deception attacks.
+**Level:** 3
+**Section:** General Data Protection
+**Section Description:** This section contains various practical requirements related to the protection of data. Most are specific to particular issues such as unintended data leakage, but there is also a general requirement to implement protection controls based on the protection level required for each data item.
+
+**Files Analyzed:** 20 relevant out of 20 total, 0 skipped
+
+### Finding Counts
+
+| Severity | Count |
+|----------|-------|
+| Critical | 0 |
+| High | 1 |
+| Medium | 2 |
+| Low | 0 |
+| **Total** | **3** |
+
+### Key Findings
+
+The application **completely lacks cache-control mechanisms** for all dynamic, authenticated responses containing sensitive election data. No `Cache-Control`, `Pragma`, or `Vary` headers are set on any response. This systemic gap means voter eligibility data, election configurations, voting forms, and administrative interfaces could all be cached by browsers, shared proxies, or CDNs. Additionally, state-changing operations use GET requests, making them susceptible to aggressive proxy caching.
+
+---
+
+## Security Controls Inventory
+
+| Control | Status | Location | Coverage |
+|---------|--------|----------|----------|
+| Cache-Control headers | **NOT IMPLEMENTED** | N/A | 0% of dynamic routes |
+| Pragma: no-cache | **NOT IMPLEMENTED** | N/A | 0% |
+| Vary header | **NOT IMPLEMENTED** | N/A | 0% |
+| X-Content-Type-Options | **NOT IMPLEMENTED** | N/A | 0% |
+| 404 for unknown elections/issues | ✅ Implemented | `pages.py` `raise_404()`, `load_election()`, `load_election_issue()` | All election/issue lookups |
+| Strict URL routing | ✅ Framework-provided | Quart routing | All routes |
+| Auth-gated document serving | ✅ Implemented | `pages.py:serve_doc()` | `/docs/<iid>/<docname>` |
+
+---
+
+## Critical File Review
+
+### `v3/server/pages.py` — All Dynamic Routes
+
+| Route | Auth | Cache-Control | Content-Type Set | Sensitive Data |
+|-------|------|---------------|------------------|----------------|
+| `GET /` | None | ❌ None | HTML (template) | User name if logged in |
+| `GET /voter` | committer | ❌ None | HTML (template) | Election eligibility |
+| `GET /vote-on/<eid>` | committer | ❌ None | HTML (template) | Issues, candidates, CSRF |
+| `GET /admin` | committer | ❌ None | HTML (template) | Owned elections |
+| `GET /manage/<eid>` | committer | ❌ None | HTML (template) | Election config |
+| `GET /manage-stv/<eid>/<iid>` | committer | ❌ None | HTML (template) | STV candidates |
+| `POST /do-vote/<eid>` | committer | ❌ None | 303 redirect | N/A (redirect) |
+| `GET /do-open/<eid>` | committer | ❌ None | 303 redirect | State change via GET |
+| `GET /do-close/<eid>` | committer | ❌ None | 303 redirect | State change via GET |
+| `POST /do-set-*/<eid>` | committer | ❌ None | 204 No Content | Date info |
+| `GET /docs/<iid>/<docname>` | session | ❌ None | Auto-detected | Election documents |
+| `GET /profile` | session | ❌ None | HTML (template) | User identity |
+| `GET /static/<path>` | None | ❌ None (framework default) | Auto-detected | Static assets |
+
+### Templates — Cache-Relevant Content
+
+| Template | Sensitive Content Rendered |
+|----------|----------------------------|
+| `voter.ezt` | Election lists, eligibility, owner names, eids |
+| `vote-on.ezt` | Full ballot: issues, candidates, STV data embedded in JS |
+| `admin.ezt` | Owned elections, configs |
+| `manage.ezt` | Election state, issues, dates, CSRF token in hidden field |
+
+---
+
+## Findings
+
+### High Severity
+
+#### ASVS-1425-HIGH-001 — No Cache-Control Headers on Sensitive Authenticated Pages
+
+**Severity:** HIGH
+
+**Finding:** Every authenticated route handler that returns sensitive election data produces responses without any `Cache-Control`, `Pragma`, or `Vary` headers. The control does not exist anywhere in the codebase — there is no global middleware, no per-route header setting, and no response hook that adds cache-prevention headers.
+
+**Gap Type:** Type A — Entry points with NO control whatsoever.
+
+**Affected Entry Points (all in `v3/server/pages.py`):**
+
+| Route | Function | Line | Sensitive Data Exposed |
+|-------|----------|------|------------------------|
+| `GET /voter` | `voter_page()` | ~156 | Voter eligibility, election listings |
+| `GET /vote-on/<eid>` | `vote_on_page()` | ~240 | Voting form, issues, candidates, CSRF token |
+| `GET /admin` | `admin_page()` | ~299 | Owned elections, admin data |
+| `GET /manage/<eid>` | `manage_page()` | ~333 | Election config, issues, state |
+| `GET /manage-stv/<eid>/<iid>` | `manage_stv_page()` | ~353 | STV issue config, candidates |
+| `GET /profile` | `profile_page()` | ~537 | User identity |
+| `GET /settings` | `settings_page()` | ~545 | User settings |
+
+**Vulnerable Code (representative — `basic_info()` at line ~60):**
+
+```python
+async def basic_info():
+ """Return base-level EZT template data."""
+ basic = edict()
+ # ... populates uid, name, email from session ...
+ basic.csrf_token = 'placeholder'
+ return basic
+ # NOTE: No cache-control headers set here or in any caller
+```
+
+**Every template-rendered page follows this pattern:**
+
+```python
+@APP.get('/voter')
+@asfquart.auth.require({R.committer})
+@APP.use_template(TEMPLATES / 'voter.ezt')
+async def voter_page():
+ result = await basic_info()
+ # ... builds response with election data ...
+ return result
+ # NOTE: response has no Cache-Control header
+```
+
+**Data Flow:**
+```
+Session (voter identity) → Database query (voter eligibility, elections) →
+Template rendering → HTTP Response (NO Cache-Control) →
+Browser/Proxy Cache (stores sensitive content)
+```
+
+**Proof of Concept:**
+
+1. Voter authenticates and visits `/vote-on/abcdef1234`
+2. Response contains election issues, candidates, and voting form
+3. Browser caches the response (default caching behavior for GET with 200)
+4. Another user on the same shared computer navigates back to see cached page
+5. On a corporate proxy: response cached and served to a different authenticated user hitting the same URL
+
+Alternatively with a caching reverse proxy:
+```
+GET /voter HTTP/1.1
+Host: steve.example.org
+Cookie: session=VOTER_A_SESSION
+
+HTTP/1.1 200 OK
+Content-Type: text/html
+# NO Cache-Control header
+# Proxy caches this response
+
+# Later, attacker requests:
+GET /voter HTTP/1.1
+Host: steve.example.org
+# Gets Voter A's cached eligibility page
+```
+
+**Impact:**
+- Voter eligibility information (which elections a person can vote in) leaked through cached pages
+- Election configuration and issue details cached and accessible after session ends
+- Per the domain context, voter-to-issue mappings from the `mayvote` table (with salts) are used to build the voting page — caching this undermines the system's goal of preventing correlation between voter identity and voting patterns
+- CSRF tokens cached in pages could enable token reuse attacks
+
+**Remediation:**
+
+Add a global `after_request` hook to set cache-control headers on all responses:
+
+```python
+@APP.after_request
+async def set_cache_headers(response):
+ # For authenticated/dynamic pages, prevent all caching
+ if response.content_type and 'text/html' in response.content_type:
+ response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'
+ response.headers['Pragma'] = 'no-cache'
+ response.headers['Expires'] = '0'
+ # For API responses (JSON, 204, etc.)
+ if response.status_code in (200, 204) and '/static/' not in request.path:
+ response.headers.setdefault('Cache-Control', 'no-store')
+ # Vary on Cookie to prevent shared cache cross-user leakage
+ response.headers.setdefault('Vary', 'Cookie')
+ return response
+```
+
+Or per-route for maximum control:
+
+```python
+@APP.get('/voter')
+@asfquart.auth.require({R.committer})
+@APP.use_template(TEMPLATES / 'voter.ezt')
+async def voter_page():
+ result = await basic_info()
+ # ... existing code ...
+ response = await make_response(result)
+ response.headers['Cache-Control'] = 'no-store'
+ return response
+```
+
+---
+
+### Medium Severity
+
+#### ASVS-1425-MEDIUM-002 — State-Changing GET Endpoints Cacheable by Proxies
+
+**Severity:** MEDIUM
+
+**Finding:** Election open and close operations are implemented as GET endpoints. GET responses are aggressively cached by default in HTTP caching semantics (RFC 7234). Combined with the complete absence of cache-control headers (HIGH-001), these state-changing responses could be cached by intermediary proxies, and the URLs could be prefetched by browsers or crawlers.
+
+**Gap Type:** Type A — No cache control on cacheable GET state-changes.
+
+**Affected Endpoints (in `v3/server/pages.py`):**
+
+```python
+# Line ~435
+@APP.get('/do-open/<eid>')
+@asfquart.auth.require({R.committer})
+@load_election
+async def do_open_endpoint(election):
+ result = await basic_info()
+ ### check authz
+ pdb = steve.persondb.PersonDB.open(DB_FNAME)
+ election.open(pdb) # STATE CHANGE
+ _LOGGER.info(f'User[U:{result.uid}] opened election[E:{election.eid}]')
+ title = election.get_metadata().title
+ await flash_success(f'Opened election: {title}')
+ return quart.redirect(f'/manage/{election.eid}', code=303)
+ # Returns 303 redirect with NO Cache-Control header
+```
+
+```python
+# Line ~453
+@APP.get('/do-close/<eid>')
+@asfquart.auth.require({R.committer})
+@load_election
+async def do_close_endpoint(election):
+ result = await basic_info()
+ ### check authz
+ election.close() # STATE CHANGE - IRREVERSIBLE
+ _LOGGER.info(f'User[U:{result.uid}] closed election[E:{election.eid}]')
+ title = election.get_metadata().title
+ await flash_success(f'Closed election: {title}')
+ return quart.redirect(f'/manage/{election.eid}', code=303)
+```
+
+**Client-side reference confirming GET usage (`manage.ezt` and `manage-stv.ezt`):**
+
+```javascript
+// manage.ezt line ~266
+confirmOpen.addEventListener('click', () => {
+ openModal.hide();
+ window.location.href = '/do-open/[eid]'; // GET request
+});
+
+// manage.ezt line ~274
+confirmClose.addEventListener('click', () => {
+ closeModal.hide();
+ window.location.href = '/do-close/[eid]'; // GET request
+});
+```
+
+**Proof of Concept:**
+
+1. A caching proxy sits between the admin and the server
+2. Admin visits `/do-open/abcdef1234` — election opens, proxy caches the 303 redirect
+3. A browser prefetch or `<link rel="prefetch">` tag fetches `/do-close/abcdef1234`
+4. The election is unintentionally closed because the GET request triggers the state change
+
+**Impact:**
+- Election open/close URLs could be prefetched by browsers, crawlers, or proxy prefetching
+- Cached redirect responses leak that an election state-change occurred at a specific URL
+- Election closing is irreversible per the application design — accidental execution via cache/prefetch causes permanent damage
+
+**Remediation:**
+
+Convert to POST endpoints and add cache-control:
+
+```python
+@APP.post('/do-open/<eid>')
+@asfquart.auth.require({R.committer})
+@load_election
+async def do_open_endpoint(election):
+ # POST endpoints are not cached by default
+ result = await basic_info()
+ # TODO: validate CSRF token
+ pdb = steve.persondb.PersonDB.open(DB_FNAME)
+ election.open(pdb)
+ _LOGGER.info(f'User[U:{result.uid}] opened election[E:{election.eid}]')
+ title = election.get_metadata().title
+ await flash_success(f'Opened election: {title}')
+ response = quart.redirect(f'/manage/{election.eid}', code=303)
+ response.headers['Cache-Control'] = 'no-store'
+ return response
+```
+
+Update templates to submit via POST form:
+
+```javascript
+confirmOpen.addEventListener('click', () => {
+ openModal.hide();
+ const form = document.createElement('form');
+ form.method = 'POST';
+ form.action = '/do-open/[eid]';
+ // Add CSRF token
+ const csrf = document.createElement('input');
+ csrf.type = 'hidden';
+ csrf.name = 'csrf_token';
+ csrf.value = document.getElementById('csrf-token').value;
+ form.appendChild(csrf);
+ document.body.appendChild(form);
+ form.submit();
+});
+```
+
+---
+
+#### ASVS-1425-MEDIUM-003 — Document Serving Lacks Cache-Control and Content-Type Enforcement
+
+**Severity:** MEDIUM
+
+**Finding:** The `/docs/<iid>/<docname>` endpoint serves election-related documents without cache-control headers and without enforcing that the served content matches an expected content type. While authorization is checked via `mayvote`, once a document is served, it can be cached by intermediary proxies. The `docname` validation is explicitly marked as not yet implemented.
+
+**File:** `v3/server/pages.py`, lines ~557-572
+
+**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) # Good: returns 404 for unauthorized
+ # NOTREACHED
+
+ ### verify the propriety of DOCNAME. # <-- NOT IMPLEMENTED
+
+ # Return per-issue document — no Cache-Control set
+ return await quart.send_from_directory(DOCSDIR / iid, docname)
+```
+
+**Data Flow:**
+```
+Authenticated request → mayvote authorization check ✓ →
+send_from_directory (auto-detects Content-Type from extension) →
+HTTP Response (NO Cache-Control) → Proxy/Browser Cache (stores authorized document)
+```
+
+**Proof of Concept:**
+
+1. Authorized voter accesses `/docs/abcdef1234/ballot_details.pdf`
+2. Response served with auto-detected `Content-Type: application/pdf`, no `Cache-Control`
+3. Corporate proxy caches the response
+4. Unauthorized person on same network accesses the cached URL and obtains the document
+5. Additionally, lack of `docname` validation means unexpected files could be served if placed in the directory
+
+**Impact:**
+- Election documents containing ballot details, candidate information, or procedural details are cacheable after authorized access
+- Missing content-type enforcement means the cache could store documents with incorrect MIME types, enabling content-type confusion attacks
+- Lack of `docname` validation (noted but not implemented) could allow serving unexpected file types
+
+**Remediation:**
+
+```python
+import mimetypes
+
+ALLOWED_DOC_TYPES = {'.pdf', '.txt', '.html', '.md'}
+
+@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: alphanumeric, hyphens, underscores, single dot
+ import re
+ if not re.match(r'^[a-zA-Z0-9_-]+\.[a-zA-Z0-9]+$', docname):
+ quart.abort(404)
+
+ # Enforce allowed content types
+ ext = pathlib.Path(docname).suffix.lower()
+ if ext not in ALLOWED_DOC_TYPES:
+ quart.abort(404)
+
+ response = await quart.send_from_directory(DOCSDIR / iid, docname)
+ response.headers['Cache-Control'] = 'no-store'
+ response.headers['X-Content-Type-Options'] = 'nosniff'
+ return response
+```
+
+---
+
+## Positive Security Patterns
+
+1. **Strict Route Matching:** Quart's routing prevents Web Cache Deception via URL path manipulation. A request like `/voter/style.css` returns 404 because no route matches, not the voter page.
+
+2. **Proper 404 for Unknown Resources:** The `raise_404()` function and `load_election()`/`load_election_issue()` decorators correctly return HTTP 404 when elections or issues are not found, rather than returning a different valid page.
+
+3. **Authorization Before Document Serving:** The `serve_doc()` endpoint checks `mayvote` authorization before serving documents, returning 404 for unauthorized users (preventing information leakage about document existence).
+
+4. **EID/IID Format Validation:** The schema's `CHECK` constraints on election IDs (10 hex characters) prevent URL confusion where a crafted EID with a file extension could bypass route matching for cache deception.
+
+---
+
+## Architecture Observations
+
+1. **No Caching Layer Configuration Visible:** The application has no reverse proxy configuration (nginx, Apache, Varnish) in the provided code. If deployed behind such a proxy without explicit cache-control headers, the proxy's default caching behavior would apply — which for GET 200 responses is typically to cache them.
+
+2. **Template Engine (EZT) Output Not Wrapped:** The `@APP.use_template` decorator apparently renders templates and returns them as responses, but there's no evidence of a hook that adds security headers to template-rendered responses.
+
+3. **Mixed GET/POST for State Changes:** The inconsistency between POST for vote submission and GET for election open/close creates an uneven security posture where some state changes are naturally un-cacheable (POST) while others are cacheable by default (GET).
+
+---
+
+## Recommendations Summary
+
+### Immediate Actions (High Priority)
+
+1. **Implement Global Cache-Control Headers** (addresses ASVS-1425-HIGH-001)
+ - Add `after_request` hook to set `Cache-Control: no-store` on all non-static responses
+ - Include `Pragma: no-cache` and `Expires: 0` for backwards compatibility
+ - Add `Vary: Cookie` to prevent shared cache cross-user leakage
+
+### Short-term Actions (Medium Priority)
+
+2. **Convert State-Changing GET to POST** (addresses ASVS-1425-MEDIUM-002)
+ - Refactor `/do-open/<eid>` and `/do-close/<eid>` to POST endpoints
+ - Update client-side JavaScript to submit forms instead of navigation
+ - Add CSRF token validation to these endpoints
+
+3. **Secure Document Serving** (addresses ASVS-1425-MEDIUM-003)
+ - Implement `docname` validation with allowlist of characters
+ - Add content-type allowlist for served documents
+ - Set `Cache-Control: no-store` and `X-Content-Type-Options: nosniff` headers
+
+### Long-term Actions (Enhancement)
+
+4. **Add Comprehensive Security Headers**
+ - Implement `X-Content-Type-Options: nosniff` globally
+ - Consider adding `Content-Security-Policy` headers
+ - Add `X-Frame-Options` or `frame-ancestors` CSP directive
+
+5. **Review Deployment Configuration**
+ - Document required reverse proxy cache settings
+ - Provide reference configurations for nginx/Apache
+ - Implement monitoring for responses missing cache-control headers
+
+---
+
+## Appendix: Files Analyzed
+
+<details>
+<summary>Click to expand list of 20 analyzed files</summary>
+
+- `v3/schema.sql` (relevance: 10)
+- `v3/server/pages.py` (relevance: 10)
+- `v3/server/templates/about.ezt` (relevance: 10)
+- `v3/server/templates/admin.ezt` (relevance: 10)
+- `v3/server/templates/e_bad_eid.ezt` (relevance: 10)
+- `v3/server/templates/e_bad_iid.ezt` (relevance: 10)
+- `v3/server/templates/e_bad_pid.ezt` (relevance: 10)
+- `v3/server/templates/flashes.ezt` (relevance: 10)
+- `v3/server/templates/footer.ezt` (relevance: 10)
+- `v3/server/templates/header.ezt` (relevance: 10)
+- `v3/server/templates/home.ezt` (relevance: 10)
+- `v3/server/templates/manage-stv.ezt` (relevance: 10)
+- `v3/server/templates/manage.ezt` (relevance: 10)
+- `v3/server/templates/privacy.ezt` (relevance: 10)
+- `v3/server/templates/profile.ezt` (relevance: 10)
+- `v3/server/templates/settings.ezt` (relevance: 10)
+- `v3/server/templates/vote-on.ezt` (relevance: 10)
+- `v3/server/templates/voter.ezt` (relevance: 10)
+- `v3/steve/election.py` (relevance: 10)
+- `v3/steve/persondb.py` (relevance: 10)
+
+</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