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:30 UTC

(tooling-agents) branch main updated: ASVS audit: 1.2.2.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 5938d4a  ASVS audit: 1.2.2.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
5938d4a is described below

commit 5938d4a4d555a5b42dc71bee486d88c95a368305
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Tue May 5 22:49:58 2026 +0200

    ASVS audit: 1.2.2.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
---
 ASVS/reports/steve/v3/d0aa7e9/all/1.2.2.md | 173 +++++++++++++++++++++++++++++
 1 file changed, 173 insertions(+)

diff --git a/ASVS/reports/steve/v3/d0aa7e9/all/1.2.2.md b/ASVS/reports/steve/v3/d0aa7e9/all/1.2.2.md
new file mode 100644
index 0000000..6fbb02e
--- /dev/null
+++ b/ASVS/reports/steve/v3/d0aa7e9/all/1.2.2.md
@@ -0,0 +1,173 @@
+# Security Audit Report: ASVS 1.2.2
+
+## Executive Summary
+
+| Field | Value |
+|-------|-------|
+| **Repository** | apache/steve/v3 |
+| **Audit Date** | May 05, 2026 |
+| **Auditor** | Tooling Agents (bundled-pass mode) |
+| **ASVS Requirement** | ASVS 1.2.2 |
+| **Files Analyzed** | 8 relevant / 49 total |
+| **Files Skipped** | 12 |
+
+**Requirement description:** Verify that when dynamically building URLs, untrusted data is encoded according to its context (e.g., URL encoding or base64url encoding for query or path parameters). Ensure that only safe URL protocols are permitted (e.g., disallow javascript: or data:).
+
+### Findings Overview
+
+| Severity | Count |
+|----------|-------|
+| 🔴 Critical | 0 |
+| 🟠 High | 0 |
+| 🟡 Medium | 1 |
+| 🟢 Low | 1 |
+
+---
+
+## ASVS-1.2.2: Injection Prevention - URL Encoding and Safe Protocols
+
+### Findings for 1.2.2
+
+#### [MEDIUM]
+**Finding ID:** ASVS-122-MED-001
+
+**File:** `v3/server/pages.py`, function `rewrite_description`, lines 54-56
+
+**Vulnerable Code:**
+```python
+def repl(match):
+    filename = match.group(1)
+    return f'<a href="/docs/{issue.iid}/{filename}">{filename}</a>'
+```
+
+**Data Flow:** `filename` extracted from description text via regex `doc:([^\s]+)` → inserted directly into URL href attribute → no URL encoding applied
+
+**Issue:** When constructing the URL for document links, the `filename` value is not URL-encoded. If a filename contains characters special in URLs (e.g., `#`, `?`, `&`, spaces via other means), the URL structure could be modified. While `[^\s]+` prevents spaces, characters like `#fragment` or `?param=val` would alter the URL semantics.
+
+**Proof of Concept:** Description containing: `doc:test.pdf#"></a><script>alert(1)</script><a href="`
+The regex matches `test.pdf#"></a><script>alert(1)</script><a` (until whitespace), producing a malformed href that breaks out of the attribute.
+
+Wait — actually since the filename is also not HTML-encoded, the `"` character in the filename would terminate the href attribute. This is actually an HTML injection via URL context.
+
+**Impact:** Attribute injection leading to XSS when descriptions are rendered with document links.
+
+**Remediation:**
+```python
+import html
+import urllib.parse
+
+def repl(match):
+    filename = match.group(1)
+    safe_url = f'/docs/{issue.iid}/{urllib.parse.quote(filename)}'
+    safe_display = html.escape(filename)
+    return f'<a href="{safe_url}">{safe_display}</a>'
+```
+
+#### [LOW]
+**Finding ID:** ASVS-122-LOW-001
+
+**File:** `v3/server/templates/manage.ezt`, JavaScript, lines ~339, 348, 357
+
+**Vulnerable Code:**
+```javascript
+form.action = `/do-edit-issue/[eid]/${issueId}`;
+form.action = `/do-delete-issue/[eid]/${issueId}`;
+```
+
+**Data Flow:** `issueId` (from onclick parameter, originally from `[issues.iid]` EZT variable) → string interpolation into URL → used as form action
+
+**Issue:** The `issueId` JavaScript variable (passed from server-rendered onclick attributes) is concatenated directly into a URL path without encoding. While IIDs are cryptographically generated and thus safe in practice, the pattern doesn't apply URL encoding to untrusted data used in URL construction.
+
+**Impact:** Low — IIDs are server-generated alphanumeric values with no user control over their format.
+
+**Remediation:**
+```javascript
+form.action = `/do-edit-issue/[eid]/${encodeURIComponent(issueId)}`;
+```
+
+### Security Controls Inventory for 1.2.2
+
+| Control | Location | Status |
+|---------|----------|--------|
+| URL encoding of path parameters | `rewrite_description` | ✗ NOT APPLIED |
+| `urllib.parse.quote` | Not used in codebase | ✗ Not imported |
+| `encodeURIComponent` | Not used in client JS | ✗ Not applied |
+| Protocol validation (javascript:/data:) | Not applicable (no user-controlled full URLs) | N/A |
+| `quart.redirect` with f-strings | Multiple endpoints | Safe (server-generated values only) ✓ |
+
+### Positive Patterns for 1.2.2
+
+1. **No user-controlled full URLs:** The application constructs all URLs from server-generated IDs (EID/IID from `crypto.create_id()`), eliminating the risk of `javascript:` or `data:` protocol injection in redirects.
+2. **Quart's redirect function:** All redirects use `quart.redirect()` with server-controlled paths, not user-supplied URLs.
+3. **Relative URLs in templates:** All form actions and links use relative paths, preventing open redirect issues.
+
+---
+
+
+
+## Cross-cutting Architecture Observations
+
+### 1. Inconsistent Encoding Strategy (Type B Pattern)
+The most critical cross-cutting observation is the **inconsistent application of encoding controls**:
+- `manage.ezt` and `manage-stv.ezt` correctly use `[format "js,html"]` for JavaScript-in-HTML contexts
+- `vote-on.ezt` (the voter-facing page) does NOT use any format directives for the same type of data
+
+This is a Type B gap (control exists but not applied) and represents false confidence — developers may believe the voter page is safe because they applied controls elsewhere.
+
+### 2. EZT Template Engine Default Behavior
+The application relies on an EZT template engine that does NOT HTML-encode output by default. This is evidenced by:
+- The `rewrite_description` function constructing raw HTML that must pass through without escaping
+- The selective use of `[format]` directives only in specific contexts
+- No visible `base_format` configuration
+
+This architectural choice means every template variable is a potential XSS vector unless explicitly wrapped in a `[format]` directive.
+
+### 3. Data Storage in Original Form (Positive)
+The application correctly stores data in its original form in the database — no pre-encoding. This prevents double-encoding issues but places the full burden of output encoding on the template layer, which currently has gaps.
+
+### 4. Mixed HTML Construction Patterns
+HTML is constructed in multiple locations:
+- Server-side in Python (`rewrite_description`)
+- Server-side in EZT templates (all templates)
+- Client-side in JavaScript (`makeItem()`)
+
+Each location needs its own encoding strategy, but only the client-side JavaScript consistently applies it.
+
+### 5. State-Changing GET Requests
+The `/do-open/<eid>` and `/do-close/<eid>` endpoints use GET methods for state-changing operations. Combined with the placeholder CSRF tokens, these are trivially exploitable via CSRF (e.g., `<img src="/do-open/KNOWN_EID">`).
+
+---
+
+## Cross-cutting Recommendations
+
+### Immediate (Critical — address before next deployment)
+
+1. **Add `[format "js"]` encoding to ALL JavaScript-embedded values in `vote-on.ezt`** (ASVS-123-CRIT-001, ASVS-121-CRIT-001). This is the highest-priority fix as it affects the voter-facing ballot page and could allow manipulation of election results.
+
+2. **Fix `rewrite_description` to HTML-encode description content** before wrapping in `<pre>` tags (ASVS-112-HIGH-001). Apply `html.escape()` to the description text and `urllib.parse.quote()` to filenames in constructed URLs.
+
+### Short-term (within current sprint)
+
+3. **Establish a template encoding standard:** Either:
+   - Configure EZT with `base_format = FORMAT_HTML` and use `[format "raw"]` only where intentional raw HTML is needed, OR
+   - Audit ALL templates and add explicit `[format "html"]` to every user-derived variable in HTML contexts
+
+4. **Add `[format "html"]` to all unencoded template outputs** including:
+   - `election.title`, `election.owner_name`, `election.authz` in all templates
+   - `issues.title`, `issues.description` in manage templates
+   - Flash message content in `flashes.ezt`
+
+5. **Fix flash messages** to either encode at creation or ensure template-level encoding (ASVS-112-MED-001).
+
+6. **Add explicit validation to `serve_doc`** for the `docname` parameter — restrict to alphanumeric plus safe punctuation (ASVS-111-MED-001).
+
+### Long-term (architectural)
+
+7. **Consider migrating to JSON embedding pattern** for complex JavaScript data: serialize server-side with `json.dumps()` and parse client-side with `JSON.parse()` from a `<script type="application/json">` tag. This is inherently safer than template-based JS construction.
+
+8. **Implement a Content Security Policy (CSP)** header to mitigate XSS impact. At minimum, restrict `script-src` to prevent inline script execution, which would require refactoring inline scripts to external files.
+
+9. **Implement real CSRF protection** — the placeholder tokens provide zero security. Use a proper CSRF library that generates per-session tokens and validates them on all state-changing requests.
+
+10. **Convert state-changing GET endpoints** (`/do-open/`, `/do-close/`) to POST methods with CSRF validation.
+        
\ 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