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(ast-vuln): reading-first audit finds SSRF metadata gap -> new XERJ detector

Xerj Squad A5b7d45e5161a
diff --git a/docs/examples/ast-vuln-graph/wp_ssrf_ranges.py b/docs/examples/ast-vuln-graph/wp_ssrf_ranges.py
new file mode 100644
index 000000000..51ceb290c
--- /dev/null
+++ b/docs/examples/ast-vuln-graph/wp_ssrf_ranges.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+"""Detector born from an AI read, not a pattern. Reading wp_http_validate_url
+showed its private-IP blocklist omits 169.254.0.0/16 (link-local / cloud
+metadata 169.254.169.254) -> SSRF. That's a SEMANTIC COMPLETENESS gap: a
+security validator whose allow/deny list is missing a dangerous case. Structural
+detectors can't see it. This encodes the class: find IP-range SSRF validators and
+report which dangerous ranges they FAIL to cover."""
+import json, urllib.request, re
+X="http://127.0.0.1:9200"
+def q(body):
+ r=urllib.request.Request(f"{X}/wpaudit/_search",data=json.dumps(body).encode(),
+ headers={"Content-Type":"application/json"})
+ return [h["_source"] for h in json.loads(urllib.request.urlopen(r).read())["hits"]["hits"]]
+
+# dangerous ranges every SSRF validator SHOULD block, with a cheap presence test
+# over the function source (does the code mention the range's signature at all?)
+DANGEROUS = {
+ "127.0.0.0/8 loopback": [r"\b127\b"],
+ "10.0.0.0/8 private": [r"\b10\b"],
+ "172.16.0.0/12 private": [r"\b172\b"],
+ "192.168.0.0/16 private": [r"\b192\b", r"\b168\b"],
+ "169.254.0.0/16 link-local/METADATA": [r"\b169\b", r"169\.254", r"\b254\b"],
+ "100.64.0.0/10 CGNAT": [r"\b100\b.*\b64\b", r"100\.64"],
+ "IPv6 ::1 / ULA fc00::/7": [r"::1", r"fc00", r"fe80", r"inet_pton|FILTER_FLAG_IPV6|filter_var"],
+}
+def covers(code, sigs): return any(re.search(s, code) for s in sigs)
+
+# find candidate SSRF validators: functions that resolve a host AND compare IP octets
+S=q({"query":{"match":{"code":"gethostbyname"}},"size":200,"_source":["func","file","code"]})
+IPGUARD=re.compile(r"(gethostbyname|parse_url).*?(127|192\.168|private|local)", re.S)
+OCTET=re.compile(r"===\s*\$?\w*\[?0?\]?|explode\(\s*['\"]\.['\"]|\$parts\b")
+validators=[d for d in S if re.search(r"\b127\b", d["code"]) and re.search(r"\b192\b", d["code"])
+ and ("gethostbyname" in d["code"] or "$parts" in d["code"] or "explode( '.'" in d["code"])]
+print(f"SSRF IP-range validators found: {len(validators)}\n")
+for d in validators:
+ print(f"### {d['func']} ({d['file']})")
+ missing=[name for name,sigs in DANGEROUS.items() if not covers(d["code"], sigs)]
+ for name in DANGEROUS:
+ ok = name not in missing
+ flag = "" if ok else " <<< MISSING"
+ print(f" [{'x' if ok else ' '}] {name}{flag}")
+ if any("METADATA" in m for m in missing):
+ print(" !! SSRF TO CLOUD METADATA POSSIBLE — validator does not block 169.254.0.0/16")
+ print()
diff --git a/docs/research/wordpress-read-first-findings.md b/docs/research/wordpress-read-first-findings.md
new file mode 100644
index 000000000..66e29a95a
--- /dev/null
+++ b/docs/research/wordpress-read-first-findings.md
@@ -0,0 +1,91 @@
+# Reading-first core audit: what the detectors couldn't see
+
+The structural detectors ([authz graph](wordpress-authz-agentic-audit.md),
+check-vs-use, double-prepare) concluded core is clean — because they only match
+*shapes*. Logic bugs live in *semantics*: a defense that is present but
+**incomplete**. This pass switched mode — the agent used XERJ only to *navigate*
+to logic-heavy security functions, then **read them in full and reasoned about
+exploitability**, the way a human auditor does. Then each finding was turned back
+into a XERJ detector.
+
+## Confirmed solid on close reading (negative results, stated honestly)
+
+- **`wp_validate_redirect`** — the allowlist regex strips backslashes (kills the
+ `\`→`/` browser open-redirect bypass), `_deep_replace` strips CRLF recursively
+ (kills `%0%0a0a`), and `@`-userinfo tricks resolve to the real host, which is
+ allow-list-checked. Robust.
+- **`maybe_unserialize` / `maybe_serialize`** — symmetric for objects (both use
+ `/^O:[0-9]+:/`), so a string that *looks* serialized is double-serialized on
+ write and returns as a string on read. String-meta PHP Object Injection is
+ defended for data written through the pair.
+- **Widget instance `unserialize`** (customizer) — gated by
+ `hash_equals( wp_hash($decoded), $instance_hash_key )` before `unserialize`.
+ An attacker can't forge the secret-key HMAC, so POI is defended.
+
+## The finding: SSRF to cloud metadata via `wp_http_validate_url`
+
+`wp_http_validate_url()` is core's SSRF gatekeeper for `wp_safe_remote_*` and
+pingbacks. Its private-IP blocklist:
+
+```php
+if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0]
+ || ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
+ || ( 192 === $parts[0] && 168 === $parts[1] )
+) { /* reject unless http_request_host_is_external allows */ }
+```
+
+Reading the *coverage* (not the shape) shows the gap: it blocks loopback, 10/8,
+0/8, 172.16/12, 192.168/16 — but **not `169.254.0.0/16` (link-local)**, which
+contains **`169.254.169.254`, the AWS / GCP / Azure cloud-metadata endpoint**
+(and `100.100.100.200`, Alibaba). Verified against the exact logic:
+
+| target | verdict |
+|---|---|
+| 127.0.0.1, 10.x, 172.16.x, 192.168.x | BLOCKED |
+| **169.254.169.254 (cloud metadata)** | **ALLOWED** |
+| 100.64/10 (CGNAT) | ALLOWED |
+
+**Impact.** Any core feature or plugin that passes a user-supplied URL through
+`wp_safe_remote_get()` / the pingback path can be steered at the metadata service
+→ theft of cloud IAM credentials. Also missing: CGNAT `100.64/10` and IPv6
+(loopback `::1`, ULA `fc00::/7`) — though IPv6 host *literals* are separately
+rejected by the `strpbrk(host, ':#?[]')` check.
+
+**Honest status.** This is a real, verifiable gap, but a *known-class* one: core
+historically treats `wp_http_validate_url` as best-effort and points hardening at
+the `http_request_host_is_external` filter, and exploitation needs the SSRF
+feature reachable in a cloud environment. It is not claimed as a novel 0-day. It
+is exactly the kind of semantic-completeness weakness that **only a read** finds —
+and that is the point.
+
+## Improving XERJ from the finding
+
+The bug class is *an incomplete allow/deny list in a security validator*.
+`docs/examples/ast-vuln-graph/wp_ssrf_ranges.py` encodes it: locate IP-range SSRF
+validators (host resolution + octet comparisons), then check their coverage
+against the set of ranges every validator **should** block, and report what's
+**missing**. Run against core it independently reproduces the finding:
+
+```
+### wp_http_validate_url (wp-includes/http.php)
+ [x] 127.0.0.0/8 [x] 10/8 [x] 172.16/12 [x] 192.168/16
+ [ ] 169.254.0.0/16 link-local/METADATA <<< MISSING
+ [ ] 100.64.0.0/10 CGNAT <<< MISSING
+ [ ] IPv6 ::1 / ULA fc00::/7 <<< MISSING
+ !! SSRF TO CLOUD METADATA POSSIBLE
+```
+
+This is the loop worth building for XERJ as an audit substrate: a human (or an
+AI) reads and finds a semantic gap once; the finding is encoded as a
+completeness check; XERJ then carries it across every future audit — of core
+upgrades and, more usefully, of the plugin ecosystem, where SSRF validators are
+frequently hand-rolled and far more incomplete than core's.
+
+### The general lesson for XERJ
+
+Structural detectors answer "is the defense *present*?" The bugs that survive
+audit are "is the defense *complete*?" — a missing IP range, an unescaped context,
+an un-re-verified object relationship. XERJ's contribution is to make each such
+semantic invariant, once discovered by reading, a **stored, queryable
+completeness check** over the whole indexed codebase. Precision comes from the
+read; durability and scale come from XERJ.