Check the direct-access guard by tokenising, not by grepping for it
The check asked whether "defined( 'ABSPATH' )" appeared anywhere in the file. A comment containing those words therefore passed it. Measured with a planted file whose only mention was in a comment: 15 shipped PHP files examined, every one guarded Green over a file with no guard at all — one that runs for anyone who fetches it directly, outside WordPress and outside every capability check the code assumes has already happened. This is the check with the worst consequence of being hollow, and it was hollow in the one way a grep always can be. From the cache session by way of security: a check that must RECOGNISE its own code has one blind spot per recognition method, and one that reads what the source actually says has none of that kind. PHP's tokeniser cannot be fooled by a comment, because it is the thing that decides what a comment is. ci/check-abspath.php parses each shipped file and looks for a real defined() call on ABSPATH or WP_UNINSTALL_PLUGIN. Comments and doc blocks are tokens of their own and are simply never examined. The count and the floor stay, for the reason every check here has them. Verified through the container path with php hidden from `command -v`, since static.sh runs on a Gitea runner that has no php: identical output either way. A 31st self-test assertion plants the same fixture. It is grade 2 evidence — a planted instance of exactly the failure the check describes, rather than an arbitrary trigger that only proves the check can go red at all. Two things that assertion caught about itself on its first run: The check's success line now says "parsed" where it said "examined", and the existing assertion on the count was still matching the old word. It went red rather than quietly matching nothing, which is why the wording is asserted at all. And `static.sh | grep -q` reports STATIC.SH's exit status under `set -o pipefail`, not grep's — and static.sh is expected to fail in that fixture, so the assertion read "not found" however the check behaved. The mirror image of the `go test | grep` trap already in the playbook. Output is captured to a variable first now, with the reason inline. Swept the kit for text belonging to other plugins while here, after cache found a comment in its copy describing security's tree: no NLSEC_/NLCAC_ references, and every path named in ci/ and tests/ either exists here or is WordPress core. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
e20c8522b7
commit
d1703dcc03
+30
-1
@@ -127,10 +127,39 @@ for f in control-hash.txt control-placeholder.txt control-masked.txt \
|
||||
done
|
||||
|
||||
# The guard check must report a plausible number rather than a bare adjective.
|
||||
echo "$out" | grep -qE '^ [0-9]+ shipped PHP files examined' \
|
||||
echo "$out" | grep -qE '^ [0-9]+ shipped PHP files parsed' \
|
||||
&& ok "the direct-access check reports a count" \
|
||||
|| bad "the direct-access check printed no count — it cannot tell 13 files from 0"
|
||||
|
||||
# --------------------------------------------------- direct-access guard
|
||||
# 🔴 Grade 2 evidence: a planted instance of exactly the failure the check
|
||||
# describes, not an arbitrary trigger. The grep version of this check passed
|
||||
# this fixture — the words are present, in a comment, and there is no guard.
|
||||
# It reported "every one guarded" over a file that runs for anyone who fetches
|
||||
# it directly.
|
||||
echo
|
||||
echo "→ the direct-access check reads structure, not text"
|
||||
cat > includes/class-selftest-unguarded.php <<'FIXTURE'
|
||||
<?php
|
||||
// This file is safe because defined( 'ABSPATH' ) is checked elsewhere.
|
||||
// It is not. There is no guard anywhere below this line.
|
||||
echo 'reachable';
|
||||
FIXTURE
|
||||
git add -N includes/class-selftest-unguarded.php >/dev/null
|
||||
# Captured first, NOT piped into grep. This script runs under `set -o
|
||||
# pipefail`, and static.sh is expected to exit non-zero here — so
|
||||
# `static.sh | grep -q` would report STATIC.SH's status, not grep's, and the
|
||||
# assertion would read "not found" however the check behaved. The mirror image
|
||||
# of the `go test | grep` trap, and it cost this assertion one red run.
|
||||
guard_out=$(./ci/static.sh 2>&1 || true)
|
||||
if printf '%s' "$guard_out" | grep -q 'class-selftest-unguarded.php,line=1::No guard'; then
|
||||
ok "a file mentioning the guard only in a comment is still flagged"
|
||||
else
|
||||
bad "an unguarded file passed because the words appear in a comment"
|
||||
fi
|
||||
rm -f includes/class-selftest-unguarded.php
|
||||
git rm -q --cached includes/class-selftest-unguarded.php >/dev/null 2>&1 || true
|
||||
|
||||
# ---------------------------------------------------------------- text domain
|
||||
# 🔴 ci_php, never a bare `php`. The Gitea runner image has NO php — that is
|
||||
# why ci_php exists and says so — and this section originally called `php`
|
||||
|
||||
Reference in New Issue
Block a user