Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

docs(case-study): per-file zero-day sweep finds authz gap the structural pass missed

Xerj Squad A844ec089b679
diff --git a/docs/case-studies/wordpress-security-audit/FINDINGS.md b/docs/case-studies/wordpress-security-audit/FINDINGS.md
index 3b60970ec..fd117de69 100644
--- a/docs/case-studies/wordpress-security-audit/FINDINGS.md
+++ b/docs/case-studies/wordpress-security-audit/FINDINGS.md
@@ -7,6 +7,7 @@
| 1 | `wp_http_validate_url` allows `169.254.0.0/16` (cloud metadata) | SSRF (incomplete deny-list) | Medium (known-class) | **Real, verified, reachable** |
| 2 | `class-snoopy.php` curl build: `escapeshellarg($URI)` after flags, no `--` | option injection (escaper ≠ injection defense) | Informational (core) | **NOT reachable in core — bundled dead code**; valid pattern for plugins |
| 3 | `class-wp-image-editor-imagick.php` parses uploaded image content | ImageTragick (image-rce-ssrf) | Medium (deploy-dependent) | **Real surface** |
+| 4 | `user-new.php:100` stores `$_REQUEST['role']` with NO `wp_ensure_editable_role()` (2 of 3 sibling role-sinks guard it) | role injection / privilege-escalation (inconsistent authz) | Medium (multisite + filtered `editable_roles`) | **Real gap — found by the per-file sweep I missed** |
| — | AJAX / REST / admin authorization | IDOR / privesc | — | Verified **clean** (object-scoped) |
| — | SQL double-`prepare` de-escape | SQLi | — | Verified **safe** (placeholder_escape) |
| — | sanitizer composition (escape→de-escape) | XSS/SQLi | — | Verified **safe** (escaper-last) |
@@ -111,6 +112,43 @@ a restrictive `policy.xml`, which WP relies on the host to provide; WP checks fi
type first but the content is still parsed. **Fix (deploy):** patched ImageMagick;
`policy.xml` disabling `MVG/MSL/URL/EPHEMERAL/HTTPS` coders.
+## Finding 4 — inconsistent `wp_ensure_editable_role()` -> role injection (`user-new.php`)
+
+**Found by the multi-agent per-file zero-day sweep — the structural authz graph
+missed it** (it saw a `promote_user` cap check and passed; it did not check that
+the *role-editability* guard was applied consistently).
+
+`wp-admin/user-new.php` has **three** sinks that assign a request-supplied role.
+Two are guarded, one is not:
+```php
+// line 73 (adduser, noconfirmation branch) -> GUARDED
+wp_ensure_editable_role( $_REQUEST['role'] ); add_existing_user_to_blog([... 'role'=>$_REQUEST['role']]);
+// line 231 (createuser branch) -> GUARDED
+wp_ensure_editable_role( $_REQUEST['role'] );
+// line 95-102 (adduser, email-invitation else branch) -> NOT GUARDED
+add_option( 'new_user_'.$key, [ 'user_id'=>$user_id, 'email'=>..., 'role'=>$_REQUEST['role'] ] );
+$roles = get_editable_roles(); $role = $roles[ $_REQUEST['role'] ]; // AFTER the store; email only; warning not wp_die
+```
+The stored role is later applied on confirmation: `/newbloguser/{key}/` ->
+`maybe_add_existing_user_to_blog()` -> `add_existing_user_to_blog()` ->
+`add_user_to_blog()` -> `$user->set_role($role)` — **with no re-check** (only the
+default-true `can_add_user_to_blog` filter). So a role the inviter is not
+authorized to assign is persisted and applied.
+
+**Reachability:** authenticated multisite user with `promote_user` on the target
+but **not** `manage_network_users` POSTs `action=adduser` (valid `add-user` nonce),
+an existing user's email, `role=administrator`, no `noconfirmation` -> stored ->
+invitee visits the link -> becomes administrator.
+
+**Honest severity — conditional, defense-in-depth in stock.** In a *stock* install
+`get_editable_roles()` returns all roles, so `wp_ensure_editable_role` is a no-op
+and the inviter could assign that role anyway — **no boundary is crossed**. The gap
+bites where **`editable_roles` is filtered** to restrict an admin below the injected
+role (common in membership / role-manager plugins and multisite delegation), and
+only on **multisite**. It is a genuine, unconditional *inconsistency* (2 of 3 sinks
+guarded) matching upstream 7.0.2 — worth reporting to WordPress as a hardening fix,
+not a stock-install RCE. Verified by reading the real code + adversarial agent.
+
## Verified-clean negatives (the honest majority)
### Authorization / IDOR — clean
diff --git a/docs/case-studies/wordpress-security-audit/README.md b/docs/case-studies/wordpress-security-audit/README.md
index d9598eee0..3b6447e20 100644
--- a/docs/case-studies/wordpress-security-audit/README.md
+++ b/docs/case-studies/wordpress-security-audit/README.md
@@ -116,6 +116,9 @@ read; scale and durability come from XERJ.
second-order, TOCTOU, timing, …) with attack + detection + safe recipe.
- **Copyable Claude Code skill**: [`skill/SKILL.md`](skill/SKILL.md)
— install it and run this whole workflow on your own codebase.
+- [`ZERODAY-SWEEP.md`](ZERODAY-SWEEP.md) — **the multi-agent per-file zero-day
+ sweep** (222 agents, adversarial verify): found a role-injection authz gap the
+ structural graph missed. See FINDINGS.md #4.
- [`AUTHENTICATION.md`](AUTHENTICATION.md) — **the WordPress auth story across all
4 entry surfaces** (AJAX/REST/XML-RPC/admin-post): missing / insufficient /
broken-`==` / race checked; ~51× fewer tokens than reading the handlers.
diff --git a/docs/case-studies/wordpress-security-audit/ZERODAY-SWEEP.md b/docs/case-studies/wordpress-security-audit/ZERODAY-SWEEP.md
new file mode 100644
index 000000000..0d325a737
--- /dev/null
+++ b/docs/case-studies/wordpress-security-audit/ZERODAY-SWEEP.md
@@ -0,0 +1,55 @@
+# Per-file zero-day sweep (multi-agent workflow)
+
+After the structural passes reported core "clean," a **per-file** review was run —
+a multi-agent workflow over the 883 security-relevant files, each reviewer primed
+to *assume bugs were missed and look harder*, with **adversarial verification** of
+every candidate. This is the honest test of whether the structural approach had
+blind spots. **It did — it found a real authz gap the graph missed.**
+
+## The workflow
+- **Scout** → the 883-file work-list (from the XERJ indices).
+- **Review** → 177 agents (5 files each), reading real code + XERJ facts, hunting
+ logic bugs / missing-insufficient-broken(`==`)-authz / second-order / TOCTOU /
+ deser / type-confusion — reporting only concrete source→sink or broken-check
+ candidates.
+- **Verify** → an independent agent per candidate, tasked to **refute** it
+ (reachable? guarded? dead code? receiver-type FP? deploy-only?).
+- **Synthesize** → only survivors.
+
+Scale: **222 agents, ~10.8M tokens, ~31 min**, 44 candidates → **5 confirmed**
+after adversarial verification. (8 verify agents hit a usage limit near the end;
+those candidates are unverified, not counted.)
+
+## Confirmed findings
+
+| # | file:line | class | severity | note |
+|---|---|---|---|---|
+| 1 | `wp-admin/user-new.php:100` | role injection (inconsistent `wp_ensure_editable_role`) | Medium (multisite + filtered roles) | **NEW — the structural graph missed it.** See FINDINGS.md #4 |
+| 2 | `wp-includes/http.php:598` | SSRF `169.254` gap | Medium | independent re-discovery of FINDINGS.md #1 (validates the sweep) |
+| 3 | `akismet/class.akismet-admin.php:1212` | CSRF (missing nonce on a GET view action) | Low | plugin, needs a logged-in admin + forged GET |
+| 4 | `ID3/module.audio-video.flv.php:716` | resource-exhaustion DoS | Low | author+ uploads a crafted `.flv`; loop over attacker-set count |
+| 5 | `build/pages/font-library/page.php:308` | missing capability check | Low | low-priv access to the font-library admin page |
+
+Findings 3–5 are **at the workflow's adversarial-verifier confidence**; only #1
+(and #2, already known) were re-read by the lead. #3–#5 are low-severity and
+plugin/edge — reported honestly as candidates pending a lead read, not asserted.
+
+## The honest takeaway — why the structural pass missed #1
+My authz graph asked *"is there a capability check?"* — `user-new.php` has one
+(`promote_user`), so it passed. The real bug is **inconsistency**: a second,
+role-specific guard (`wp_ensure_editable_role`, added 6.8.0) is applied to 2 of 3
+sibling role-sinks and **omitted on the third**. A "presence of a check" model
+cannot see a *missing sibling guard*; a per-file read that compares the three
+branches can. **Lesson: structural coverage and per-file reading are complementary
+— the graph narrows and proves coverage; the read catches inconsistency and logic
+gaps the facts don't encode.** This sweep is now part of the method.
+
+## Cost
+~10.8M tokens for the exhaustive per-file pass is the *thorough* end of the dial —
+appropriate when you suspect misses. The cheap structural passes (~26k tokens for
+the whole earlier audit) are the daily driver; this deep sweep is the periodic
+"did we miss anything" backstop. Both belong in the workflow.
+
+## Reproduce
+The workflow script is under the session's `workflows/scripts/`; re-run points the
+same reviewer/verifier prompts at any file list (`review_files.json`).