Skip to content

Fix: Anchor blocklist patterns to prevent false positives in file check - #506

Open
CookieDarb wants to merge 1 commit into
WordPress:trunkfrom
CookieDarb:fix/file-check-anchor-file-extension
Open

CookieDarb wants to merge 1 commit into
WordPress:trunkfrom
CookieDarb:fix/file-check-anchor-file-extension

Conversation

@CookieDarb

Copy link
Copy Markdown

What?

Closes #504

Fixes false-positive REQUIRED errors in File_Check by anchoring file extension patterns in the blocklist to the end of the filename.

Why?

File_Check matches its blocklist using preg_grep( '/' . $file . '/', $filenames ).

Because extension patterns like \.sh, \.dat, and \.sql lacked end-of-string anchors ($), the regex matched those characters anywhere in the path. This caused ordinary CSS, JS, and data files (such as Material Design token stylesheets like tokens.sys.shape.css, modular scripts like theme.shortcodes.js, and data files like sample.data.json) to be incorrectly flagged as shell scripts, customizer import files, or SQL dumps. Since these checks raise a REQUIRED error, themes with valid assets failed automated Theme Check scans.

How?

  • checks/class-file-check.php:
    • Appended the end-of-string anchor ($) to all file extension patterns in $blocklist (\.sh$, \.sql$, \.dat$, \.xml$, \.wie$, \.kpf$, \.lubith$).
    • Left filename, prefix, and folder patterns (thumbs\.db, desktop\.ini, error_log, __MACOSX, ^\.+[a-zA-Z0-9]) untouched.

Testing Instructions

  1. In a test theme, include legitimate asset files whose names contain blocked extension substrings:
    • assets/styles/tokens.sys.shape.css
    • assets/js/theme.shortcodes.js
    • assets/data/sample.data.json
    • assets/data/db.sqlite3
  2. Also include actual banned files to verify no regressions:
    • deploy.sh
    • backup.sql
    • export.dat
  3. Run Theme Check on the theme.
  4. Verify that:
    • Valid assets (tokens.sys.shape.css, theme.shortcodes.js, sample.data.json, db.sqlite3) pass without false positives.
    • Genuinely disallowed files (deploy.sh, backup.sql, export.dat) are still correctly flagged with REQUIRED errors.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Reviewing the existing regex patterns and drafting test files. Final code and testing were done by me.

@jamesbregenzer

Copy link
Copy Markdown

I checked File_Check at c2ffc32 against the base 9c21ede using PHP 8.4.27 via WebAssembly. All four asset names in the testing instructions were rejected by the base and accepted by this PR’s version.

I also checked all seven blocked extensions in lowercase and uppercase, the three XML allowlist names, and thumbs.db, desktop.ini and .hidden. Those 20 controls behaved the same in both versions: blocked files stayed blocked and allowlisted files stayed accepted.

That’s 24 cases checked against each version. This was an isolated call to File_Check::check() with minimal WordPress stubs, not a full Theme Check scan or native PHP test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blocklisted file-extension patterns are unanchored, so ordinary filenames fail the check

2 participants