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 09:46:54 UTC
(tooling-agents) branch main updated: ASVS L3 audit: 3.3.2 (ch03_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 80d1048 ASVS L3 audit: 3.3.2 (ch03_general)
80d1048 is described below
commit 80d1048603ca60a07141ab4325ff19b8539b4a8c
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Wed Apr 22 11:46:49 2026 +0200
ASVS L3 audit: 3.3.2 (ch03_general)
---
.../reports/steve/v3/d0aa7e9/ch03_general/3.3.2.md | 386 +++++++++++++++++++++
1 file changed, 386 insertions(+)
diff --git a/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch03_general/3.3.2.md b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch03_general/3.3.2.md
new file mode 100644
index 0000000..85e030b
--- /dev/null
+++ b/repos/apache/ASVS/reports/steve/v3/d0aa7e9/ch03_general/3.3.2.md
@@ -0,0 +1,386 @@
+# Security Audit Report: ASVS 3.3.2 - Cookie SameSite Attribute
+
+## Executive Summary
+
+- **Repository:** apache/steve
+- **Audit Date:** Apr 22, 2026
+- **Auditor:** Tooling Agents
+- **ASVS Requirement:** 3.3.2 — Verify that each cookie's 'SameSite' attribute value is set according to the purpose of the cookie, to limit exposure to user interface redress attacks and browser-based request forgery attacks, commonly known as cross-site request forgery (CSRF).
+ - **Level:** 2
+ - **Section:** Cookie Setup
+ - **Section Description:** This section outlines requirements for securely configuring sensitive cookies to provide a higher level of assurance that they were created by the application itself and to prevent their contents from leaking or being inappropriately modified.
+ - **Chapter:** Web Frontend Security
+ - **Control Objective:** This category focuses on requirements designed to protect against attacks executed via a web frontend. These requirements do not apply to machine-to-machine solutions.
+- **Files Analyzed:** 5 relevant out of 49 total, 12 skipped
+- **Finding Counts:**
+
+| Severity | Count |
+|----------|-------|
+| Critical | 0 |
+| High | 2 |
+| Medium | 0 |
+| Low | 0 |
+| **Total** | **2** |
+
+---
+
+## Security Controls Inventory
+
+### Cookie-Related Controls Found
+
+| Control | Location | Status | Coverage |
+|---------|----------|--------|----------|
+| Session cookie creation | `asfquart.session` (external framework) | Not visible in codebase | Unknown |
+| Session cookie SameSite configuration | `main.py:create_app()` | **NOT CONFIGURED** | 0% |
+| Quart app cookie configuration | `main.py:33-49` | **NO COOKIE CONFIG** | 0% |
+| CSRF token (related defense) | `pages.py:75` | **PLACEHOLDER ONLY** | 0% |
+| Flash messages via session | `pages.py:107-115` | Uses session cookie | Inherits session config |
+| Session read | `pages.py:66` via `asfquart.session.read()` | Functional | N/A |
+
+### Entry Points Requiring Cookie Protection
+
+| Endpoint | Method | Auth Required | State-Changing | SameSite Needed |
+|----------|--------|---------------|----------------|-----------------|
+| `/do-vote/<eid>` | POST | Yes | Yes (critical) | Lax minimum |
+| `/do-create-election` | POST | Yes | Yes | Lax minimum |
+| `/do-add-issue/<eid>` | POST | Yes | Yes | Lax minimum |
+| `/do-edit-issue/<eid>/<iid>` | POST | Yes | Yes | Lax minimum |
+| `/do-delete-issue/<eid>/<iid>` | POST | Yes | Yes | Lax minimum |
+| `/do-set-open_at/<eid>` | POST | Yes | Yes | Lax minimum |
+| `/do-set-close_at/<eid>` | POST | Yes | Yes | Lax minimum |
+| `/do-open/<eid>` | **GET** | Yes | **Yes (critical)** | **Strict required** |
+| `/do-close/<eid>` | **GET** | Yes | **Yes (critical)** | **Strict required** |
+
+---
+
+## Critical File Review
+
+### `v3/server/main.py` — Application Configuration
+
+| Line(s) | Pattern | Status | Notes |
+|----------|---------|--------|-------|
+| 44 | `asfquart.construct(...)` | ❌ MISSING | No cookie configuration parameters |
+| 33-49 | `create_app()` | ❌ MISSING | No `SESSION_COOKIE_SAMESITE` |
+| 33-49 | `create_app()` | ❌ MISSING | No `SESSION_COOKIE_SECURE` |
+| 33-49 | `create_app()` | ❌ MISSING | No `SESSION_COOKIE_HTTPONLY` |
+
+### `v3/server/pages.py` — Cookie Usage Points
+
+| Line(s) | Function | Cookie Dependency | SameSite Relevant |
+|----------|----------|-------------------|-------------------|
+| 66 | `basic_info()` | Reads session (uid, name, email) | Yes — auth state |
+| 75 | `basic_info()` | `csrf_token = 'placeholder'` | Yes — CSRF defense gap |
+| 400-439 | `do_vote_endpoint()` | POST + session auth | Yes — vote submission |
+| 442-461 | `do_create_endpoint()` | POST + session auth | Yes — election creation |
+| 464-481 | `do_open_endpoint()` | **GET** + session auth | **CRITICAL** — Lax bypass |
+| 484-499 | `do_close_endpoint()` | **GET** + session auth | **CRITICAL** — Lax bypass |
+
+---
+
+## Findings
+
+### High Severity
+
+#### Finding ASVS-332-HIGH-001
+
+| Field | Value |
+|-------|-------|
+| **Severity** | **HIGH** |
+| **Finding ID** | ASVS-332-HIGH-001 |
+| **Gap Type** | Type A — Entry point with NO control |
+| **Title** | Session cookie missing explicit SameSite attribute configuration |
+| **File** | `v3/server/main.py` |
+| **Function** | `create_app()` |
+| **Lines** | 33–49 |
+
+**Description:**
+
+The application does not explicitly configure the `SameSite` attribute for session cookies. Session cookies are the sole authentication mechanism for the election voting system, yet no explicit security configuration is present in the application initialization code.
+
+**Vulnerable Code:**
+
+```python
+def create_app():
+ "Create the asfquart app and its endpoints."
+
+ ### is this really needed right now?
+ # Avoid OIDC
+ import asfquart.generics
+
+ asfquart.generics.OAUTH_URL_INIT = (
+ 'https://oauth.apache.org/auth?state=%s&redirect_uri=%s'
+ )
+ asfquart.generics.OAUTH_URL_CALLBACK = 'https://oauth.apache.org/token?code=%s'
+
+ app = asfquart.construct('steve', app_dir=THIS_DIR, static_folder=None)
+
+ # Now that we have an APP, import modules that will add page
+ # and API endpoints into the APP.
+ import pages # noqa: F401
+ import api # noqa: F401
+
+ return app # also available as asfquart.APP now
+```
+
+**Data Flow:**
+
+1. `create_app()` constructs the Quart application via `asfquart.construct()` — **no cookie configuration provided**
+2. Session cookies are created by `asfquart.session` when users authenticate
+3. Session is read on every authenticated request via `basic_info()` → `asfquart.session.read()` (pages.py:66)
+4. The session cookie carries authentication state (`uid`, `fullname`, `email`) used for authorization decisions across all 9+ state-changing endpoints
+5. **No `SESSION_COOKIE_SAMESITE` (or equivalent) is set anywhere in the visible codebase**
+
+**Related Functions Checked:**
+- `basic_info()` (pages.py:66) — reads session cookie
+- All state-changing endpoints (pages.py:400-499) — depend on session authentication
+
+**Proof of Concept:**
+
+An attacker hosts a malicious page that targets the POST-based vote submission endpoint:
+
+```html
+<!-- Attacker's page at evil.example.com -->
+<html>
+<body>
+ <form id="voteForm" method="POST" action="https://steve.apache.org/do-vote/TARGET_EID">
+ <input type="hidden" name="vote-ISSUE_ID" value="y" />
+ </form>
+ <script>document.getElementById('voteForm').submit();</script>
+</body>
+</html>
+```
+
+Without an explicit `SameSite` attribute on the session cookie:
+- **Older browsers** (pre-Chrome 80) default to `SameSite=None`, sending cookies with all cross-site requests
+- **Modern browsers** default to `SameSite=Lax`, which blocks this POST-based attack but still allows GET-based attacks (see Finding ASVS-332-HIGH-002)
+- The application has **no CSRF token validation** as a fallback (`basic.csrf_token = 'placeholder'` at pages.py:75, never verified)
+
+**Impact:**
+
+- The session cookie is the sole authentication mechanism for an election voting system
+- Without explicit SameSite configuration, protection depends entirely on browser version and defaults
+- Combined with the placeholder CSRF token (acknowledged in TODO.md), the SameSite attribute is the **only remaining browser-side defense** against cross-site request forgery
+- Successful exploitation could allow an attacker to cast votes, create elections, open/close elections, or add/delete issues on behalf of an authenticated user
+
+**Remediation:**
+
+```python
+def create_app():
+ "Create the asfquart app and its endpoints."
+
+ import asfquart.generics
+ asfquart.generics.OAUTH_URL_INIT = (
+ 'https://oauth.apache.org/auth?state=%s&redirect_uri=%s'
+ )
+ asfquart.generics.OAUTH_URL_CALLBACK = 'https://oauth.apache.org/token?code=%s'
+
+ app = asfquart.construct('steve', app_dir=THIS_DIR, static_folder=None)
+
+ # Explicitly configure session cookie security attributes
+ app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' # Minimum; 'Strict' if OAuth flow allows
+ app.config['SESSION_COOKIE_SECURE'] = True # Require HTTPS
+ app.config['SESSION_COOKIE_HTTPONLY'] = True # Prevent JS access
+
+ import pages # noqa: F401
+ import api # noqa: F401
+
+ return app
+```
+
+---
+
+#### Finding ASVS-332-HIGH-002
+
+| Field | Value |
+|-------|-------|
+| **Severity** | **HIGH** |
+| **Finding ID** | ASVS-332-HIGH-002 |
+| **Gap Type** | Type A — Entry point with NO control |
+| **Title** | State-changing GET endpoints bypass SameSite=Lax protection |
+| **File** | `v3/server/pages.py` |
+| **Function** | `do_open_endpoint()`, `do_close_endpoint()` |
+| **Lines** | 464, 484 |
+
+**Description:**
+
+Two critical election state-changing operations (open and close) are implemented as GET endpoints. This design bypasses the protection offered by `SameSite=Lax` cookies, as Lax explicitly permits cookies to be sent with top-level GET navigations, even cross-site.
+
+**Vulnerable Code:**
+
+```python
+@APP.get('/do-open/<eid>') # <-- GET method for state change
+@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) # <-- Critical state change: opens election, generates crypto keys
+ _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)
+
+
+@APP.get('/do-close/<eid>') # <-- GET method for state change
+@asfquart.auth.require({R.committer})
+@load_election
+async def do_close_endpoint(election):
+ result = await basic_info()
+ ### check authz
+ election.close() # <-- Critical state change: closes election permanently
+ _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)
+```
+
+**Data Flow:**
+
+1. Browser receives cross-site navigation (link, redirect, `<img>` tag with redirect chain) to `https://steve.apache.org/do-open/TARGET_EID`
+2. `SameSite=Lax` cookies are sent with top-level GET navigations (by design)
+3. `@asfquart.auth.require({R.committer})` passes because the session cookie is present
+4. `election.open(pdb)` executes, generating cryptographic salts and the `opened_key` — **this is irreversible** (election can't return to editable state)
+5. `election.close()` similarly permanently closes the election
+
+**Related Functions Checked:**
+- `basic_info()` (pages.py:66) — session authentication
+- `election.open()` (steve/election.py) — state machine enforcement
+- `election.close()` (steve/election.py) — state machine enforcement
+
+**Proof of Concept:**
+
+```html
+<!-- Attacker targets an election administrator -->
+<!-- Option 1: Simple link in email or chat -->
+<a href="https://steve.apache.org/do-close/TARGET_EID">Click to see election results</a>
+
+<!-- Option 2: Invisible image tag with redirect chain -->
+<img src="https://steve.apache.org/do-open/TARGET_EID" style="display:none" />
+
+<!-- Option 3: Top-level redirect (bypasses SameSite=Lax) -->
+<script>window.location = 'https://steve.apache.org/do-close/TARGET_EID';</script>
+```
+
+**Impact:**
+
+- An attacker can **prematurely open an election** before issues and voters are finalized, which generates the anti-tamper key and locks the election from editing
+- An attacker can **prematurely close an election**, cutting off legitimate voters
+- Both operations are **irreversible** (enforced by state machine assertions in `election.py`)
+- Even if `SameSite=Lax` were properly configured per Finding ASVS-332-HIGH-001, these endpoints would remain vulnerable because Lax explicitly permits cookies on top-level GET navigations
+- The `### check authz` placeholder (no ownership verification) means any authenticated committer can target any election
+
+**Remediation:**
+
+Change these endpoints to POST methods and implement SameSite=Lax (or Strict) on session cookies:
+
+```python
+@APP.post('/do-open/<eid>') # Changed from GET to POST
+@asfquart.auth.require({R.committer})
+@load_election
+async def do_open_endpoint(election):
+ result = await basic_info()
+
+ # TODO: Verify user owns this election
+ # if election.get_metadata().owner_pid != result.uid:
+ # quart.abort(403)
+
+ 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}')
+ return quart.redirect(f'/manage/{election.eid}', code=303)
+
+
+@APP.post('/do-close/<eid>') # Changed from GET to POST
+@asfquart.auth.require({R.committer})
+@load_election
+async def do_close_endpoint(election):
+ result = await basic_info()
+
+ # TODO: Verify user owns this election
+
+ election.close()
+ _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)
+```
+
+Update the corresponding templates to use form submission instead of links:
+```html
+<form method="POST" action="/do-open/[eid]">
+ <!-- Include CSRF token when implemented -->
+ <button type="submit" class="btn btn-success">Open Election</button>
+</form>
+```
+
+---
+
+## Positive Security Patterns
+
+1. **Authentication decorators consistently applied**: All state-changing endpoints use `@asfquart.auth.require({R.committer})` or `@asfquart.auth.require({R.pmc_member})`, ensuring no unauthenticated access.
+
+2. **POST methods for most state-changing operations**: Vote submission, election creation, issue management all use POST — only open/close are GET.
+
+3. **Parameterized queries**: All database operations use prepared statements via `asfpy.db`, preventing SQL injection.
+
+4. **303 redirects after POST**: All POST handlers redirect with `code=303`, which is correct Post/Redirect/Get pattern and prevents resubmission.
+
+5. **Comprehensive security logging**: All state-changing operations log `User[U:{uid}]` with election/issue context, providing audit trail.
+
+6. **Election state machine assertions**: `election.py` enforces state transitions (`assert self.is_editable()`, `assert self.is_open()`) preventing invalid operations even if cookie/CSRF controls fail.
+
+---
+
+## Architecture Observations
+
+1. **Single defense layer for CSRF**: With CSRF tokens as placeholders (`'placeholder'` on line 75 of pages.py) and no SameSite attribute configuration, the application currently has **zero explicit CSRF defenses**. Modern browser defaults (Lax) provide incidental protection for POST endpoints only.
+
+2. **OAuth flow constrains SameSite choice**: The application uses ASF OAuth (`OAUTH_URL_INIT` redirects to `oauth.apache.org`), which requires cookies to be available after the OAuth callback redirect. `SameSite=Strict` would break this flow; `SameSite=Lax` is the appropriate value.
+
+3. **Framework abstraction obscures cookie configuration**: The `asfquart.construct()` wrapper abstracts Quart app creation, making it unclear whether any cookie defaults are set by the framework. This should be explicitly verified and documented.
+
+---
+
+## Recommendations Summary
+
+### Immediate Actions (Priority 1)
+
+| Priority | Action | Finding | Effort |
+|----------|--------|---------|--------|
+| **1** | Set `SESSION_COOKIE_SAMESITE = 'Lax'` explicitly in `create_app()` | ASVS-332-HIGH-001 | Low |
+| **2** | Change `/do-open/<eid>` and `/do-close/<eid>` from GET to POST | ASVS-332-HIGH-002 | Medium |
+
+### Short-term Actions (Priority 2)
+
+| Priority | Action | Finding | Effort |
+|----------|--------|---------|--------|
+| **3** | Set `SESSION_COOKIE_SECURE = True` and `SESSION_COOKIE_HTTPONLY = True` | Defense-in-depth | Low |
+| **4** | Verify `asfquart` framework cookie defaults and document them | Transparency | Low |
+
+### Long-term Actions (Priority 3)
+
+| Priority | Action | Finding | Effort |
+|----------|--------|---------|--------|
+| **5** | Implement real CSRF tokens (replacing placeholder) for all POST endpoints | Complement SameSite | High |
+
+---
+
+## Appendix: Files Analyzed
+
+<details>
+<summary>Click to expand file list (5 files)</summary>
+
+- `v3/server/pages.py` (relevance: 10)
+- `v3/server/main.py` (relevance: 8)
+- `v3/ARCHITECTURE.md` (relevance: 3)
+- `v3/TODO.md` (relevance: 2)
+- `v3/steve/election.py` (relevance: 2)
+
+</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