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.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
docs(ast-vuln): check-vs-use IDOR detector — finds the shape, core defends it
Xerj Squad Aa540321ecace
diff --git a/docs/examples/ast-vuln-graph/wp_checkuse_idor.py b/docs/examples/ast-vuln-graph/wp_checkuse_idor.pynew file mode 100644index 000000000..aad8d3c17--- /dev/null+++ b/docs/examples/ast-vuln-graph/wp_checkuse_idor.py@@ -0,0 +1,65 @@+#!/usr/bin/env python3+"""Check-vs-use IDOR detector. The cap-presence sweep proves a capability is+CHECKED; this proves it is checked against the SAME object the operation ACTS on.+The bug: permission_check resolves object from request key X, but the operation+reads/acts on request key Y (X != Y) -> the check validated a different object+than the one touched (the WP 4.7.0 id-type-juggle class)."""+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"]]++# object-identifying request keys (things that name WHICH object to act on)+ID_KEYS = {"id","parent","user_id","comment","comment_id","post","post_id","uuid",+ "attachment_id","term","term_id","menu","sidebar","stylesheet","slug",+ "force","autosave"} # force/autosave excluded below; kept minimal+ID_KEYS -= {"force","autosave","slug"}++REQKEY = re.compile(r"""\$request\s*\[\s*['"](\w+)['"]\s*\]|get_param\(\s*['"](\w+)['"]|\$_(?:GET|POST|REQUEST)\s*\[\s*['"](\w+)['"]""")+def req_keys(code):+ ks=set()+ for m in REQKEY.finditer(code):+ ks.add(next(g for g in m.groups() if g))+ return ks+def obj_keys(code): return req_keys(code) & ID_KEYS++# all REST endpoint methods+R=q({"query":{"prefix":{"file":"wp-includes/rest-api/endpoints"}},"size":2000,+ "_source":["func","file","code"]})+byfile={}+for d in R: byfile[(d["file"],d["func"])]=d+files=sorted({d["file"] for d in R})+print(f"REST controllers: {len(files)}")++PAIRS=[("get_item","get_item_permissions_check"),+ ("update_item","update_item_permissions_check"),+ ("delete_item","delete_item_permissions_check"),+ ("create_item","create_item_permissions_check")]+flags=[]+for f in files:+ for op,chk in PAIRS:+ do=byfile.get((f,op)); dc=byfile.get((f,chk))+ if not do or not dc: continue+ ck=obj_keys(dc["code"]); uk=obj_keys(do["code"])+ # object-id keys the OPERATION reads that the CHECK never bound to+ gap = uk - ck+ if gap:+ flags.append((f.split('/')[-1],op,sorted(ck),sorted(uk),sorted(gap)))++print(f"\ncheck-vs-use candidates (operation reads an object-id key the check didn't): {len(flags)}")+for fn,op,ck,uk,gap in flags:+ print(f" {fn}::{op}")+ print(f" check binds keys: {ck} op uses keys: {uk} GAP: {gap}")++# also: AJAX handlers that check_ajax_referer on one id but act on another+print("\n--- also scanning self-contained AJAX handlers for id mismatch ---")+A=q({"query":{"prefix":{"func":"wp_ajax_"}},"size":300,"_source":["func","file","code"]})+for d in A:+ c=d["code"]+ # nonce action bound to an id vs a state/get on a different id+ nonce_ids=set(re.findall(r"check_ajax_referer\(\s*[\"']?[^\"',]*\$(\w+)",c))+ used_ids=set(re.findall(r"\$_(?:POST|GET|REQUEST)\[\s*['\"](\w+)['\"]",c)) & ID_KEYS+ if nonce_ids and used_ids and not (nonce_ids & used_ids):+ print(f" {d['func']}: nonce bound to {nonce_ids} but acts on {used_ids}")diff --git a/docs/research/wordpress-authz-agentic-audit.md b/docs/research/wordpress-authz-agentic-audit.mdindex 9fa18ccff..6c6be164a 100644--- a/docs/research/wordpress-authz-agentic-audit.md+++ b/docs/research/wordpress-authz-agentic-audit.md@@ -250,10 +250,55 @@ type-juggle routed the checked-object and the mutated-object apart. That is adifferent class (parameter/type confusion, not a missing check) and needstaint/type reasoning on the object-resolution step, not a cap-presence sweep.+## The check-vs-use IDOR detector (the class cap-presence can't see)++Cap-presence proves a capability is *checked*; it cannot prove it is checked+against the **same object the operation acts on**. The real core-IDOR mechanism+(e.g. WP 4.7.0's `id` type-juggle) is exactly that mismatch: `permission_check`+resolves the object from request key **X**, the operation reads/acts on key **Y**,+and X ≠ Y — so a validated object and a touched object diverge.++`wp_checkuse_idor.py` detects the shape: for each controller, diff the+object-identifying request keys the `*_permissions_check` binds against the keys+the matching operation reads. On core it flags **12 candidates**; reading them+sorts into three buckets:++- **global resources** (templates, widgets, sidebars) — gated by a site cap+ (`edit_theme_options`), so no per-object binding is expected. Not a gap.+- **helper/delegated resolution** — the check binds the object one hop away+ (`get_items_permissions_check`, `parent_controller`), which the key-diff misses.+- **one genuinely risky shape — and core defends it explicitly.**++That last one is the find. `WP_REST_Revisions_Controller`: the permission check+binds the cap to `$request['parent']`+(`current_user_can('edit_post', $parent->ID)`), but `get_item` returns the+revision `$request['id']`. Pair a `parent` you can edit with an `id` belonging to+a post you can't, and you'd read its draft revisions — **unless the operation+re-verifies the relationship.** It does:++```php+$parent = $this->get_parent( $request['parent'] ); // cap checked against this+$revision = $this->get_revision( $request['id'] ); // this is returned+if ( (int) $parent->ID !== (int) $revision->post_parent ) {+ return new WP_Error( 'rest_revision_parent_id_mismatch', …, array( 'status' => 404 ) );+}+```++Core is safe **only because of that explicit `parent_id_mismatch` guard**. The+detector found the exact structural shape; the read decided it. And the corollary+is the whole point:++> A plugin controller or AJAX handler that checks permission on one id but acts+> on another **without re-verifying the relationship** is a live IDOR. This+> detector flags that shape directly. Core survives by adding the consistency+> guard; plugins routinely omit it.+## What's next-To honestly claim "all flows": sweep `admin_post_*` and the **object-resolution /-id-type-juggling** auth-bypass class (where the cap is present but evaded), the-**`map_meta_cap` edge cases**, and the **plugin ecosystem**, where the-placeholder-escape and object-scoped-cap defenses are routinely absent — that is-where the reasoning loop will actually fire on real bugs.+The reasoning loop and its detectors (object-scoped cap-presence, check-vs-use+mismatch, double-prepare de-escape) are now built and validated against a core+that is — verifiably — hardened on all of them. The place they will actually+fire is the **plugin ecosystem**, where object-scoped caps, relationship+re-verification, and placeholder-escape are the exact defenses most often missing.+Remaining core surfaces for completeness: `admin_post_*`, direct `wp-admin` page+handlers, and `map_meta_cap` edge cases.