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:33:13 UTC

(tooling-agents) branch main updated: ASVS L3 audit: 14.3.3 (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 e1be7c0  ASVS L3 audit: 14.3.3 (sensitive_data_handling)
e1be7c0 is described below

commit e1be7c0e69ffcd9c230e6c0e63ba1ce8b591045c
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Wed Apr 22 06:33:09 2026 +0200

    ASVS L3 audit: 14.3.3 (sensitive_data_handling)
---
 .../v3/d0aa7e9/sensitive_data_handling/14.3.3.md   | 428 +++++++++++++++++++++
 1 file changed, 428 insertions(+)

diff --git a/repos/apache/ASVS/reports/steve/v3/d0aa7e9/sensitive_data_handling/14.3.3.md b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/sensitive_data_handling/14.3.3.md
new file mode 100644
index 0000000..4f998d3
--- /dev/null
+++ b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/sensitive_data_handling/14.3.3.md
@@ -0,0 +1,428 @@
+# ASVS 14.3.3 Security Audit Report
+## Apache Steve — Client-side Data Protection: Browser Storage of Sensitive Data
+
+---
+
+## Executive Summary
+
+- **Repository:** apache/steve
+- **Audit Date:** Apr 22, 2026
+- **Auditor:** Tooling Agents
+- **ASVS Requirement:** 14.3.3 — Verify that data stored in browser storage (such as localStorage, sessionStorage, IndexedDB, or cookies) does not contain sensitive data, with the exception of session tokens.
+  - **Level:** 2
+  - **Section:** Client-side Data Protection
+  - **Chapter:** Data Protection
+  - **Control Objective:** Applications cannot account for all usage patterns and user behaviors, and should therefore implement controls to limit unauthorized access to sensitive data on client devices.
+- **Files Analyzed:** 20 relevant out of 20 total, 0 skipped
+
+### Finding Counts
+
+| Severity | Count |
+|----------|-------|
+| Critical | 0 |
+| High | 0 |
+| Medium | 1 |
+| Low | 0 |
+| **Total** | **1** |
+
+---
+
+## Security Controls Inventory
+
+| Control | Location | Purpose | Coverage Status |
+|---------|----------|---------|-----------------|
+| Session management via `asfquart.session` | `pages.py:basic_info()` (line ~62) | Authentication and user context management across all authenticated endpoints | ⚠️ Session stores user PII; cookie-backend status unconfirmed |
+| No localStorage/sessionStorage/IndexedDB usage | All `.ezt` templates, embedded JS | Prevention of persistent client-side data storage across all client-side code | ✅ Not used |
+| Vote data via POST form submission | `vote-on.ezt` form → `/do-vote/<eid>` | Secure transmission of vote data without client-side persistence | ✅ Votes never stored in browser storage |
+| In-memory-only JavaScript variables | `vote-on.ezt` `STV_CANDIDATES` | Temporary storage of candidate data during STV voting pages | ✅ Not persisted to storage |
+| Hidden form inputs for CSRF & vote data | All form templates | CSRF protection and vote data handling in all POST forms | ✅ DOM-only, not browser storage |
+
+---
+
+## Critical File Review
+
+### Client-Side Template Files
+
+| File | Security Functions Reviewed | Browser Storage Use | Assessment |
+|------|----------------------------|---------------------|------------|
+| `vote-on.ezt` | Vote form rendering, STV ranking JavaScript, candidate data embedding, vote submission | Form inputs (DOM); JS variables (memory) | ✅ No browser storage APIs used |
+| `manage.ezt` | Election management interface, CSRF token handling | Hidden input, JS variable | ✅ No browser storage APIs used |
+| `admin.ezt` | Administrative election metadata display | Form inputs | ✅ No browser storage APIs used |
+| `voter.ezt` | Voter interface rendering | Template rendering only | ✅ No browser storage APIs used |
+| `settings.ezt` | User settings interface | Form inputs | ✅ No browser storage APIs used |
+| `profile.ezt` | User profile display | Template rendering only | ✅ No browser storage APIs used |
+
+### Server-Side Files
+
+| File | Security Functions Reviewed | Relevance to 14.3.3 | Assessment |
+|------|----------------------------|---------------------|------------|
+| `pages.py` | `basic_info()` (lines ~62–80), session management, flash message handling (lines ~107–113) | HIGH — Session data, flash messages | ⚠️ Session stores PII |
+| `election.py` | Election data management, vote processing | MEDIUM — Data structures | ✅ Server-side only |
+| `persondb.py` | Voter identity management | MEDIUM — PII handling | ✅ Server-side only |
+
+### Audit Gaps
+
+| File | Status | Impact |
+|------|--------|--------|
+| `steve.js` (referenced in `footer.ezt`) | Not provided for audit | **HIGH** — Used on all pages; cannot verify browser storage API usage |
+
+---
+
+## Findings
+
+### Medium Severity
+
+#### ASVS-1433-MED-001: Sensitive Voter Identity Data Stored in Session (Likely Cookie-Backed)
+
+**Severity:** MEDIUM
+
+**Location:**
+- **File:** `v3/server/pages.py`
+- **Function:** `basic_info()`
+- **Lines:** ~62–80
+
+**Related Functions Checked:**
+- `basic_info()` — Session data reading
+- Flash message functions (lines ~107–113) — `flash_danger()`, `flash_success()`
+- Template rendering in all `.ezt` files — Session data consumption
+
+**Description:**
+
+The application stores sensitive voter identity data (PII) directly in the session object, which in Quart's default configuration is implemented as a client-side signed cookie. The session contains:
+- `uid` — voter identifier (PII)
+- `fullname` — voter full name (PII)
+- `email` — voter email address (PII)
+
+Additionally, flash messages stored in the session may contain election-specific data such as issue IDs and election titles, potentially revealing voter-to-issue mappings.
+
+**Vulnerable Code:**
+
+```python
+# v3/server/pages.py, lines ~62–80
+async def basic_info():
+    basic = edict()
+    # ...
+    s = await asfquart.session.read()
+    if s:
+        basic.update(
+            uid=s['uid'],          # voter identifier (PII)
+            name=s['fullname'],    # voter full name (PII)
+            email=s['email'],      # voter email address (PII)
+        )
+    # ...
+    return basic
+```
+
+```python
+# v3/server/pages.py, lines ~107–113
+await flash_danger(f'Error submitting vote for issue {iid}.')  # issue ID in session
+await flash_success(f'Opened election: {title}')               # election title in session
+```
+
+**Data Flow:**
+
+1. **Source:** Authentication framework writes `uid`, `fullname`, `email` into the session during login
+2. **Storage:** Quart session storage (default: signed cookie `session` in browser)
+3. **Sink:** Session cookie stored in browser; base64-encoded and signed but **not encrypted**
+4. **Exposure:** Cookie is readable by anyone with access to browser DevTools, file system, or via XSS if `HttpOnly` flag is not set
+
+**Missing Control:**
+
+No server-side session backend is configured. Quart defaults to cookie-based sessions where all session data (including PII) is base64-encoded, signed with `itsdangerous`, and stored in the browser cookie. The data is **readable** (not encrypted) by anyone with access to the cookie.
+
+**Proof of Concept:**
+
+```javascript
+// In browser console after authentication:
+document.cookie.split(';').find(c => c.includes('session'));
+// Returns: "session=eyJ1aWQiOiAidXNlcjEyMyIsICJmdWxsbmFtZSI6ICJKb2huIERvZSIsICJlbWFpbCI6ICJqb2huQGV4YW1wbGUuY29tIn0.XYZ..."
+
+// Decode the base64 portion (before the signature):
+atob('eyJ1aWQiOiAidXNlcjEyMyIsICJmdWxsbmFtZSI6ICJKb2huIERvZSIsICJlbWFpbCI6ICJqb2huQGV4YW1wbGUuY29tIn0');
+// Returns: '{"uid": "user123", "fullname": "John Doe", "email": "john@example.com"}'
+```
+
+**Impact:**
+
+Per the domain context, "voter identities (persondb)" is classified as sensitive data, and the system's core security goal is ballot secrecy. Storing voter identity in a browser cookie:
+
+1. **XSS Vulnerability Amplification:** Exposes PII to XSS attacks if cookie is readable by JavaScript (unless `HttpOnly` flag is set)
+2. **Physical Access Risk:** Reveals voter identity to anyone with physical access to the browser or file system
+3. **Forensic Evidence:** Creates client-side forensic evidence linking a specific voter to the voting system, compromising voter privacy
+4. **Voter-Issue Mapping:** Flash messages containing issue IDs could reveal voter-to-issue mappings (classified as sensitive data in domain context)
+5. **ASVS 14.3.3 Non-Compliance:** ASVS 14.3.3 allows "session tokens" in cookies but not sensitive data. A session token should be an opaque identifier, not a container for user PII.
+
+**Remediation:**
+
+**Option 1: Server-Side Session Store (Recommended)**
+
+Configure a server-side session backend so only an opaque session ID is stored in the browser cookie:
+
+```python
+# In application configuration (e.g., config.py or app initialization):
+from quart_session import Session
+
+APP.config['SESSION_TYPE'] = 'redis'  # or 'filesystem', 'sqlalchemy', 'memcached'
+APP.config['SESSION_REDIS'] = redis.from_url('redis://localhost:6379')
+APP.config['SESSION_COOKIE_HTTPONLY'] = True
+APP.config['SESSION_COOKIE_SECURE'] = True  # Ensure HTTPS-only
+APP.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
+
+Session(APP)
+```
+
+**Option 2: Minimize Cookie-Based Session Data**
+
+If server-side sessions cannot be implemented immediately, store only the session identifier in the cookie and look up user details server-side:
+
+```python
+# v3/server/pages.py
+async def basic_info():
+    basic = edict()
+    s = await asfquart.session.read()
+    if s:
+        # Only store a session identifier in the cookie;
+        # look up user details server-side on each request
+        uid = s.get('uid')  # Only store UID
+        if uid:
+            pdb = steve.persondb.PersonDB.open(DB_FNAME)
+            try:
+                name, email = pdb.get_person(uid)
+            except steve.persondb.PersonNotFound:
+                name, email = None, None
+            basic.update(uid=uid, name=name, email=email)
+    return basic
+
+# During login, only store UID in session:
+async def login_handler():
+    # After authentication...
+    session['uid'] = authenticated_uid  # Only store UID
+    # Do NOT store: session['fullname'], session['email']
+```
+
+**Option 3: Encrypt Session Cookie Data**
+
+If cookie-based sessions must be used with full data, encrypt the cookie contents:
+
+```python
+from quart_session import Session
+from itsdangerous import URLSafeTimedSerializer
+
+APP.config['SESSION_TYPE'] = 'cookie'
+APP.config['SESSION_COOKIE_HTTPONLY'] = True
+APP.config['SESSION_COOKIE_SECURE'] = True
+APP.secret_key = 'your-secret-key-here'  # Use strong random key
+
+# Use encrypted serializer
+APP.session_interface.serializer = URLSafeTimedSerializer(
+    APP.secret_key,
+    salt='session-cookie',
+    serializer=EncryptedSerializer()  # Custom encrypted serializer
+)
+```
+
+---
+
+## Positive Security Patterns
+
+### 1. No localStorage/sessionStorage/IndexedDB Usage
+
+**Implementation:** All client-side JavaScript across all 20 template files was reviewed.
+
+**Evidence:** No calls to the following APIs were found in any template:
+- `localStorage.setItem()` / `localStorage.getItem()`
+- `sessionStorage.setItem()` / `sessionStorage.getItem()`
+- `indexedDB.open()` / `indexedDB` API calls
+- Direct `document.cookie` manipulation for storage
+
+**Security Benefit:** Vote data, candidate rankings, and election metadata are handled exclusively through:
+- DOM form elements (hidden inputs, radio buttons)
+- In-memory JavaScript variables (`STV_CANDIDATES`, `currentIID`)
+- Standard form POST submission
+
+This architecture prevents sensitive data from persisting in the browser beyond the current page session.
+
+### 2. Vote Data Handled Exclusively in Memory and via POST
+
+**Implementation:** In `vote-on.ezt`, the complete vote lifecycle maintains data only in volatile memory:
+
+```javascript
+// STV rankings stored only in hidden form input (DOM, not persistent storage)
+hidden.value = labels.join(',');
+
+// YNA votes stored only in radio button state (DOM)
+// All submitted via form POST, never persisted client-side
+submitFormWithLoading('voteForm', 'submitVoteBtn', 'Submitting Votes…');
+```
+
+**Security Benefit:** Vote data exists only:
+1. In the DOM during the voting session
+2. In the POST request body during transmission
+3. Never in persistent browser storage (localStorage, cookies, etc.)
+
+This ensures votes cannot be recovered from browser storage after submission or page navigation.
+
+### 3. Candidate Data Not Persisted
+
+**Implementation:** STV candidate data is embedded as a JavaScript constant on the voting page:
+
+```javascript
+// vote-on.ezt
+const STV_CANDIDATES = [/* candidate data */];
+```
+
+**Security Benefit:** This data exists only in the page's JavaScript execution context and is automatically discarded when the user navigates away. No mechanism persists it to browser storage, preventing long-term exposure of candidate lists.
+
+### 4. CSRF Token in DOM Only
+
+**Implementation:** CSRF tokens are placed in hidden form inputs and read into JavaScript variables for AJAX calls:
+
+```html
+<input type="hidden" id="csrf-token" value="[csrf_token]">
+```
+
+```javascript
+const csrfToken = document.getElementById('csrf-token').value;
+```
+
+**Security Benefit:** Neither mechanism stores the token in persistent browser storage. The token is:
+- Generated server-side per session
+- Embedded in the page HTML
+- Exists only in the DOM during the page session
+- Never persisted to localStorage, sessionStorage, or cookies (beyond the session cookie)
+
+### 5. Votes Never Appear in URLs
+
+**Implementation:** All vote submission uses POST requests:
+
+```javascript
+// vote-on.ezt
+<form id="voteForm" method="POST" action="/do-vote/[eid]">
+```
+
+**Security Benefit:** Vote data is transmitted in the request body, not in URL query parameters. This prevents:
+- Vote content from appearing in browser history
+- Vote data in server access logs (URLs are logged, bodies typically are not)
+- Vote exposure via URL-based storage mechanisms (bookmarks, shared links)
+- Referrer header leakage of vote data
+
+---
+
+## Architecture Observations
+
+### 1. Unaudited Client-Side Code (`steve.js`)
+
+**Observation:** The file `v3/server/static/js/steve.js` is loaded on every page via `footer.ezt`:
+
+```html
+<script src="/static/js/steve.js"></script>
+```
+
+This file provides critical functions used throughout the application:
+- `submitFormWithLoading()` — Used during vote submission
+- `showModal()` — Used for user notifications
+- `validateRequiredField()` — Used for form validation
+
+**Risk:** If `steve.js` uses browser storage APIs (e.g., saving form state to localStorage for retry logic or caching candidate data), it could store sensitive vote data in violation of ASVS 14.3.3.
+
+**Recommendation:** Include `steve.js` in the audit scope to verify no browser storage APIs are used.
+
+### 2. Session Backend Configuration
+
+**Observation:** The session mechanism (`asfquart.session`) is a critical control point for ASVS 14.3.3 compliance. Its implementation was not provided in the audit materials.
+
+**Assumption:** The finding ASVS-1433-MED-001 assumes Quart's default cookie-based session. If a server-side backend (Redis, database, filesystem) is already configured, the finding may not apply.
+
+**Recommendation:** Document the session configuration and verify whether server-side session storage is enabled. If server-side sessions are configured, add a comment in `basic_info()` noting that these values are stored server-side only.
+
+### 3. No Cache-Control Headers Observed
+
+**Observation:** While outside the direct scope of ASVS 14.3.3 (more relevant to ASVS 14.3.2), no explicit `Cache-Control: no-store` headers are set on pages containing sensitive election data.
+
+**Risk:** Browser disk caching could persist sensitive page content including:
+- Voter identity information
+- Election details
+- Candidate lists
+- Vote forms
+
+**Recommendation:** Add `Cache-Control: no-store, no-cache, must-revalidate, private` headers to authenticated responses containing election/voter data as a defense-in-depth measure.
+
+### 4. Template-Based Architecture Strength
+
+**Observation:** The application uses server-side template rendering (`.ezt` files) rather than a client-side JavaScript framework (React, Vue, Angular).
+
+**Security Benefit:** This architecture naturally limits client-side data storage needs:
+- No client-side state management requiring localStorage
+- No client-side routing requiring sessionStorage for state preservation
+- No offline-first PWA patterns requiring IndexedDB
+- Minimal JavaScript reduces attack surface for client-side storage vulnerabilities
+
+---
+
+## Recommendations Summary
+
+### Immediate Actions (Within 1 Sprint)
+
+| Priority | Recommendation | Addresses Finding | Effort |
+|----------|---------------|-------------------|--------|
+| 1 | Verify session backend configuration and document whether server-side storage is enabled | ASVS-1433-MED-001 | Low |
+| 2 | If cookie-based sessions are confirmed, implement server-side session storage (Redis/database/filesystem) | ASVS-1433-MED-001 | Medium |
+| 3 | Add session cookie security flags: `HttpOnly=True`, `Secure=True`, `SameSite=Lax` | ASVS-1433-MED-001 | Low |
+
+### Short-Term Actions (1-2 Sprints)
+
+| Priority | Recommendation | Addresses Finding | Effort |
+|----------|---------------|-------------------|--------|
+| 4 | Include `steve.js` in security audit scope to verify no browser storage APIs are used | Architecture gap | Low |
+| 5 | Implement `Cache-Control: no-store` headers on authenticated responses containing election/voter data | Defense in depth (ASVS 14.3.2) | Low |
+| 6 | Add automated testing to verify no sensitive data in session cookies (if cookie-based sessions must be used) | ASVS-1433-MED-001 | Medium |
+
+### Long-Term Actions (Strategic)
+
+| Priority | Recommendation | Addresses Finding | Effort |
+|----------|---------------|-------------------|--------|
+| 7 | Implement Content Security Policy (CSP) to prevent unauthorized script execution that could access session data | Defense in depth | Medium |
+| 8 | Add security headers monitoring to CI/CD pipeline to prevent regression | Continuous compliance | Medium |
+| 9 | Conduct periodic client-side security audits including all JavaScript dependencies | Ongoing security | High |
+
+---
+
+## Appendix: Files Analyzed
+
+<details>
+<summary>Click to expand full file list (20 files)</summary>
+
+### Database Schema
+- `v3/schema.sql` (relevance: 10)
+
+### Server-Side Python
+- `v3/server/pages.py` (relevance: 10)
+- `v3/steve/election.py` (relevance: 10)
+- `v3/steve/persondb.py` (relevance: 10)
+
+### Client-Side Templates
+- `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)
+
+### Files Referenced But Not Provided
+- `v3/server/static/js/steve.js` — **Audit gap:** Used on all pages; cannot verify browser storage API usage
+
+</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