feat(cpg): give the files a frontend refuses a CPG of their own

A dropped file is dropped from the ONLY graph there is, so every question
about it has no answer -- which is how a 637-file plugin became a scan of
nothing. But those files build perfectly well alone: the failure is
per-invocation, not per-file. So a file the main build refuses is excluded
from it, given a second CPG, and both are queried with rows concatenated per
request id.

    pmpro two-file slice   before: cpg_empty, 0 findings
                           after:  18 entailed incl. CVE-2023-23488 at :936,
                                   reported with cpg_sharded

What this does NOT buy is a flow that crosses the shard boundary: a source in
the excluded file whose sink is in the rest of the tree is invisible to every
question asked, and no merging of results recovers it. That is why the split
is REPORTED rather than quietly served as if it were whole.

The excluded-file tree is symlinks at the original relative paths. A region
asks about `classes/class.memberorder.php` and the queries match a filename by
suffix, so a flattened copy would cheerfully answer about a file nobody asked
about.

Reports gain "What could not be analysed", rendering cpg_sharded, cpg_empty,
files_unparsed, query_failed and budget_exhausted in the reader's terms. A
degradation is a fact about coverage, not a warning to file away: silence in
the coverage table means "no fact table covered this", and silence about an
empty or split graph means something else entirely.

Also removes the WordPress vocabulary from the query, which was the other half
of this request. `apply_filters` was a hardcoded Set in taint.sc and
`add_action|add_filter|add_shortcode` a hardcoded alternation in mapping.py.
Both are now a `[[dispatch]]` fact:

    [[dispatch]]
    id = "wordpress_hooks"
    register = ["add_action", "add_filter", "add_shortcode"]
    apply = ["apply_filters", ..., "do_action", ...]

The shape is general -- a registry keyed by a string literal at both ends, as
Django signals, jQuery events and Symfony's dispatcher all are -- so a second
framework is a row in a TOML rather than an edit to a query. `dispatch_apply`
is empty for every language that declares none, and the hook half then does
nothing at all rather than looking for names that mean nothing there.

848 tests pass; gates byte-identical. wpstatistics 3/2 with the CVE at :225 on
the vulnerable side only, mwwpform 1/0, pmpro 18/1, VAmPI 4 unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01T7XD7x5KonMdmGRkp63EQG
This commit is contained in:
Marius Ciepluch
2026-09-10 07:32:20 +02:00
co-authored by Claude Opus 5
parent 1ce7e9db9b
commit 9cce5a3181
13 changed files with 411 additions and 25 deletions
+19 -2
View File
@@ -117,7 +117,7 @@ def analyze_entry_points(root: Path, targets: list[FileTarget]) -> list[EntryPoi
return sorted(records, key=lambda item: (item.path, item.line is None, item.line or 0, item.name))
def php_hook_callbacks(root: Path, targets: list[FileTarget]) -> dict[str, tuple[str, ...]]:
def php_hook_callbacks(root: Path, targets: list[FileTarget], register_calls: Sequence[str] | None = None) -> dict[str, tuple[str, ...]]:
"""WordPress's hook registry, read out of the source text because the graph does not carry it.
`php2cpg` 4.0.623 drops the callback argument of a registration entirely. What the CPG holds is
@@ -131,7 +131,24 @@ def php_hook_callbacks(root: Path, targets: list[FileTarget]) -> dict[str, tuple
This is the link table for the hook half of the two-stage join (task 5.11). It is deliberately a plain
name-to-names mapping with no inference in it: a hook whose name is computed (`"save_post_" . $type`)
simply does not appear, rather than being guessed at.
``register_calls`` comes from the semantic fact tables and defaults to whatever they declare for PHP.
Nothing here knows what WordPress is: the registry shape is general -- Django signals, jQuery events, a
plugin system's event bus -- and a second framework is a row in a TOML, not a change to this function.
"""
if register_calls is None:
from .semantic.facts import load_facts
register_calls = tuple(sorted({call for fact in load_facts().for_language("php").dispatches for call in fact.register}))
if not register_calls:
return {}
pattern = re.compile(
r"""\b(?P<call>"""
+ "|".join(re.escape(name) for name in register_calls)
+ r""")\s*\(\s*['"](?P<hook>[^'"]+)['"]\s*,\s*"""
+ _PHP_CALLABLE,
re.VERBOSE,
)
table: dict[str, set[str]] = {}
for target in targets:
if target.language != "php":
@@ -140,7 +157,7 @@ def php_hook_callbacks(root: Path, targets: list[FileTarget]) -> dict[str, tuple
text = (root / target.path).read_text(errors="ignore")
except OSError:
continue
for match in _PHP_REGISTRATION.finditer(text):
for match in pattern.finditer(text):
handler = match.group("handler") or match.group("method")
if handler:
table.setdefault(match.group("hook"), set()).add(handler)