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 21:00:52 UTC
(tooling-agents) branch main updated: ASVS audit: 2.3.4.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 d70a9b0 ASVS audit: 2.3.4.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
d70a9b0 is described below
commit d70a9b0f33c1a8e8acb2177b898eef4d6b8bd190
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Tue May 5 22:55:14 2026 +0200
ASVS audit: 2.3.4.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
---
ASVS/reports/steve/v3/d0aa7e9/all/2.3.4.md | 181 +++++++++++++++++++++++++++++
1 file changed, 181 insertions(+)
diff --git a/ASVS/reports/steve/v3/d0aa7e9/all/2.3.4.md b/ASVS/reports/steve/v3/d0aa7e9/all/2.3.4.md
new file mode 100644
index 0000000..0e3ab7a
--- /dev/null
+++ b/ASVS/reports/steve/v3/d0aa7e9/all/2.3.4.md
@@ -0,0 +1,181 @@
+# Security Audit Report: ASVS 2.3.4
+
+## Executive Summary
+
+| Field | Value |
+|-------|-------|
+| **Repository** | apache/steve/v3 |
+| **Audit Date** | May 05, 2026 |
+| **Auditor** | Tooling Agents (bundled-pass mode) |
+| **ASVS Requirement** | ASVS 2.3.4 |
+| **Files Analyzed** | 17 relevant / 49 total |
+| **Files Skipped** | 12 |
+
+**Requirement description:** Verify that business logic level locking mechanisms are used to ensure that limited quantity resources (such as theater seats or delivery slots) cannot be double-booked by manipulating the application's logic.
+
+### Findings Overview
+
+| Severity | Count |
+|----------|-------|
+| 🔴 Critical | 0 |
+| 🟠High | 1 |
+| 🟡 Medium | 1 |
+| 🟢 Low | 0 |
+
+---
+
+## ASVS-2.3.4: Business Logic Locking (Double-Booking Prevention)
+
+### Findings for 2.3.4
+
+### [HIGH]
+
+**Finding ID**: ASVS-234-HIGH-001
+**Title**: No Explicit Locking on Election State Transitions — Race Condition on Concurrent Open/Close
+
+**Location**: `v3/steve/election.py`, `open()` (line 70), `close()` (line 109)
+
+**Vulnerable code**:
+```python
+def open(self, pdb):
+ assert self.is_editable() # Check-then-act without lock
+ self.add_salts()
+ edata = self.gather_election_data(pdb)
+ salt = crypto.gen_salt()
+ opened_key = crypto.gen_opened_key(edata, salt)
+ self.c_open.perform(salt, opened_key, self.eid)
+```
+
+**Data flow**:
+- Request A: check `is_editable()` → True → begin `add_salts()`
+- Request B: check `is_editable()` → True (state not yet changed) → begin `add_salts()`
+- Both proceed to open the election with different salts/keys
+
+**Proof of Concept**: Two administrators (or the same attacker with two tabs) simultaneously click "Open" on the same election. Both pass the `is_editable()` check before either has updated the database. With SQLite's EXCLUSIVE locking this may serialize at the DB level, but the application logic performs a classic TOCTOU (Time-of-Check-to-Time-of-Use) pattern.
+
+**Impact**: While SQLite's implicit write serialization may prevent actual data corruption in single-writer scenarios, the application logic does not handle the concurrency case explicitly. In multi-process deployments or with WAL mode, race conditions could lead to:
+- Double salt generation (overwriting previous salts)
+- Multiple `opened_key` values being computed
+- Inconsistent anti-tamper state
+
+**Remediation**:
+```python
+def open(self, pdb):
+ # Use a single transaction with an immediate lock
+ self.db.conn.execute('BEGIN IMMEDIATE')
+ try:
+ # Re-check state inside the transaction (with lock held)
+ md = self._all_metadata()
+ if self._compute_state(md) != self.S_EDITABLE:
+ self.db.conn.execute('ROLLBACK')
+ raise ElectionBadState(self.eid, self._compute_state(md), self.S_EDITABLE)
+
+ # Perform all operations atomically
+ self._add_salts_no_transaction()
+ edata = self.gather_election_data(pdb)
+ salt = crypto.gen_salt()
+ opened_key = crypto.gen_opened_key(edata, salt)
+ self.c_open.perform(salt, opened_key, self.eid)
+
+ self.db.conn.execute('COMMIT')
+ except Exception:
+ self.db.conn.execute('ROLLBACK')
+ raise
+```
+
+---
+
+### [MEDIUM]
+
+**Finding ID**: ASVS-234-MED-001
+**Title**: Vote Table Allows Unlimited Re-Votes Without Locking or Rate Control
+
+**Location**: `v3/steve/election.py`, `add_vote()` (line 231); `v3/queries.yaml`, `c_add_vote` (line 44)
+
+**Vulnerable code**:
+```python
+def add_vote(self, pid: str, iid: str, votestring: str):
+ ...
+ self.c_add_vote.perform(vote_token, ciphertext)
+```
+
+```yaml
+c_add_vote: |
+ INSERT INTO vote (vote_token, ciphertext)
+ VALUES (?, ?)
+```
+
+**Data flow**: Each call to `add_vote()` performs a pure INSERT into the `vote` table. There's no UPDATE or UPSERT — every submission creates a new row. No limit on how many rows a single vote_token can accumulate.
+
+**Proof of Concept**: Repeatedly POST to `/do-vote/<eid>` with the same ballot. Each submission adds a new row for each issue. After 1000 submissions, there are 1000 rows per vote_token, consuming storage and making tally queries slower.
+
+**Impact**: Unbounded storage growth per voter per issue. While re-voting is an intended feature (only the latest vote counts), there's no limit on how many times a voter can re-vote, potentially exhausting storage or degrading tally performance.
+
+**Remediation**: Consider either an UPDATE pattern (replacing the existing vote) or limiting re-votes per voter per issue.
+
+### Security Controls Inventory for 2.3.4
+
+| Control | Location | Coverage Status |
+|---------|----------|-----------------|
+| SQLite implicit write locking | Database engine | INHERENT — provides basic serialization |
+| `BEGIN TRANSACTION` | `election.py` `delete()`, `add_salts()` | APPLIED — but only for specific operations |
+| `BEGIN IMMEDIATE` transaction | Not present | NOT APPLIED — needed for state transitions |
+| `PRIMARY KEY (pid, iid)` on mayvote | `schema.sql` | APPLIED — prevents duplicate eligibility |
+| `vote_token` index | `schema.sql` `idx_by_vote_token` | APPLIED — for efficient lookups |
+
+### Positive Patterns for 2.3.4
+
+- The `mayvote` table uses `PRIMARY KEY (pid, iid)` which prevents double-registering a voter for the same issue at the database level.
+- SQLite's inherent write serialization provides some protection against concurrent corruption, even though the application doesn't explicitly handle it.
+- The `vote` table design (append-only with `MAX(vid)` for latest) is inherently safe against concurrent vote submissions — both writes succeed, and the latest is always used.
+
+---
+
+
+
+## Cross-cutting Architecture Observations
+
+1. **Type B Gaps Dominate**: The most critical pattern is controls that EXIST in the codebase (owner_pid, authz, CSRF tokens, state validation) but are NOT APPLIED at the enforcement point. This creates false confidence — the schema and comments suggest security is in place, but enforcement is absent.
+
+2. **Assert vs. Exception Pattern Inconsistency**: The codebase uses `assert` for state checks in some methods (`open()`, `close()`, `add_issue()`) but proper exceptions in others (`add_vote()` via `_all_metadata(required_state)`). This inconsistency means security enforcement depends on which code path is taken.
+
+3. **GET for State Changes**: The use of GET requests for irreversible operations (`/do-open/<eid>`, `/do-close/<eid>`) combines with the CSRF gap to create a particularly dangerous attack surface.
+
+4. **Single-Layer Defense**: Security controls exist primarily at the model layer (`election.py`) with minimal web-layer enforcement. The web layer (pages.py) trusts that the model will enforce constraints, but the model uses bypassable assertions.
+
+5. **SQLite Concurrency Model**: The application relies on SQLite's implicit serialization for concurrency safety, but the check-then-act patterns in the application layer create TOCTOU windows that could be exploited in multi-process deployments.
+
+6. **Audit Trail Strength**: Logging of user actions is consistently implemented, providing after-the-fact accountability even where preventive controls are missing.
+
+## Cross-cutting Recommendations
+
+### Immediate (P0 — Address Before Production Use)
+
+1. **Replace all `assert` statements** with proper exception raising (`ElectionBadState`) in `election.py`. This is the most critical fix as it affects all state enforcement.
+
+2. **Implement authorization checks** in all management endpoints — compare `result.uid` against `election.owner_pid`/`election.authz`. This closes the most impactful Type B gap.
+
+3. **Implement CSRF protection** — generate real tokens per session and validate them in all POST endpoints. Change `/do-open/` and `/do-close/` to POST methods.
+
+4. **Add vote string validation** in `add_vote()` — validate against issue type before encryption.
+
+### Short-term (P1 — Within Next Sprint)
+
+5. **Wrap vote submission in a transaction** — ensure atomic ballot submission in `do_vote_endpoint()`.
+
+6. **Make election open operation atomic** — combine `add_salts()` and the state change in a single transaction.
+
+7. **Add rate limiting** on all mutating endpoints, prioritizing `/do-vote/<eid>` and `/do-create-election`.
+
+8. **Add prerequisite validation** before election opening (verify issues exist, voters are registered).
+
+### Long-term (P2 — Architecture Improvements)
+
+9. **Implement multi-user approval** for irreversible state changes (open/close elections), particularly for elections with many eligible voters.
+
+10. **Add explicit optimistic locking** (e.g., version column) on the election table to prevent concurrent state modifications.
+
+11. **Re-enable and complete transactions** in the `create-election.py` script.
+
+12. **Consider vote garbage collection** — periodically remove superseded vote rows to prevent unbounded table growth.
+
\ 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