What it checks
Scans code for eval, shell execution, obfuscation, unsanitized input, unprepared SQL and missing nonce or capability checks.
Check ID: files.code_pattern
PHP files in the scan targets (including other PHP extensions such as .phtml and .inc) are scanned with the rules below. Some rules are regular expressions; others read the PHP tokens to follow request data, database queries and the handlers of AJAX, admin-post and REST requests. The rule about external scripts also applies to HTML files.
The rules are bundled in rules/core.json. The version of the rule set is shown under Settings → Tools → Status. At most 50 findings are reported per file.
A finding does not always mean a problem. If the code is yours and the use is intended, set the finding to Ignored with a note. An ignored finding about a file becomes active again when the file changes.
What a finding means
The titles, severities and explanations below are the ones shown on the Findings screen.
| Finding | Severity | Meaning |
|---|---|---|
eval() is usedphp.eval | High | eval() runs a string as PHP code. Injected malware often uses it, and if the string contains user input it allows remote code execution. |
assert() with dynamic codephp.assert_dynamic | High | On older PHP versions assert() evaluates a string argument as code, a common backdoor technique. |
create_function() is usedphp.create_function | High | create_function() evaluates code internally and was removed in PHP 8. It is also used by malware. |
preg_replace() with the /e modifierphp.preg_replace_e | Critical | The /e modifier evaluates the replacement as PHP code. It only works on very old PHP and is a well-known backdoor pattern. |
Shell command executionphp.shell_exec | High | Functions such as shell_exec(), system(), exec() and passthru() run operating system commands. Themes rarely need them and web shells rely on them. |
Chained decoding functionsphp.decode_chain | Critical | Nested calls such as base64_decode(gzinflate(…)) are typical of obfuscated malware. |
base64_decode() is usedphp.base64_decode | Low | base64_decode() has legitimate uses but is also used to hide code. |
Remote or stream file inclusionphp.remote_include | Critical | include/require with a URL or stream wrapper (http://, php://, data://) executes code from outside the server. |
External URL is loadedphp.remote_fetch | Info | The code fetches content from a fixed external URL. This can be legitimate (APIs) but is also used to download payloads. |
unserialize() on request dataphp.unserialize_input | Critical | Unserializing user input enables PHP object injection. |
extract() on request dataphp.extract_input | High | extract() on $_GET/$_POST lets visitors overwrite any local variable. |
Error reporting disabled in codephp.error_reporting_off | Low | error_reporting(0) hides errors. Malware uses it to stay unnoticed. |
Known web shell signaturephp.webshell_marker | Critical | The file contains a string used by well-known web shells. |
External script is loadedhtml.external_script | Info | A script is loaded from another domain. If that domain is compromised, so is your site. |
Variable function callphp.variable_function | Low | Calling $name(…) runs whatever function the variable contains. Malware uses it to hide calls such as system(). |
Backtick shell executionphp.backtick_exec | High | Text between backticks is executed as a shell command. |
Request data is output without escapingphp.input_output | High | A value from $_GET/$_POST/$_REQUEST/$_COOKIE is printed directly, which allows cross-site scripting (XSS). |
Request data in a SQL queryphp.input_sql | Critical | A request value is used in a database query without $wpdb->prepare(), which allows SQL injection. |
Request data in include/requirephp.input_include | Critical | A request value decides which file is included, which allows local or remote file inclusion. |
Request data in a file operationphp.input_file | High | A request value is used as a file path or content, which can allow reading or writing arbitrary files. |
Database query without prepare()php.wpdb_unprepared | High Medium | A $wpdb query is built from variables without $wpdb->prepare(). If any part comes from users, this allows SQL injection. High: a variable is placed in the query. Medium: the whole query is a variable that was not built with $wpdb->prepare() in the same file. |
AJAX/admin-post handler without nonce checkphp.ajax_missing_nonce | High Medium | The handler does not call check_ajax_referer(), check_admin_referer() or wp_verify_nonce(), so requests can be forged (CSRF). Medium for handlers that logged-out visitors can call (wp_ajax_nopriv_, admin_post_nopriv_). |
AJAX/admin-post handler without capability checkphp.ajax_missing_capability | Medium | Any logged-in user (including subscribers) can call this handler because current_user_can() is not checked. |
REST route without permission_callbackphp.rest_missing_permission | High | The route has no permission_callback, so access control is undefined. |
Public REST routephp.rest_public_endpoint | Low | The route is open to everyone (permission_callback is __return_true). |
Form processing without nonce checkphp.form_missing_nonce | Medium | The file handles $_POST and changes data, but no nonce is verified anywhere in the file. |
Obfuscated stringphp.obfuscated_string | High | A very long encoded string, a run of escape sequences or a chain of chr() calls was found. This is typical of injected code. |
How to fix
The recommended action shown with each finding:
- eval() is used
Replace eval() with regular code. If you did not write this, the file may be compromised: compare it with your original source. - assert() with dynamic code
Remove the call or pass a boolean expression. Check whether the file was modified by someone else. - create_function() is used
Use an anonymous function instead. - preg_replace() with the /e modifier
Use preg_replace_callback(). Treat the file as suspicious if you did not write it. - Shell command execution
Remove the call if it is not required. If it is, never pass user input and escape arguments with escapeshellarg(). - Chained decoding functions
Decode the payload safely offline to see what it does, and restore the file from a clean copy. - base64_decode() is used
Confirm what is decoded. Ignore this finding if the use is legitimate. - Remote or stream file inclusion
Include only local files. Remove the statement and investigate how it got there. - External URL is loaded
Confirm that the URL is expected and that the response is not executed or output without escaping. - unserialize() on request data
Use json_decode() for user input, or pass allowed_classes => false. - extract() on request data
Read the needed keys explicitly and sanitize each value. - Error reporting disabled in code
Configure error display in php.ini or wp-config.php instead of in theme code. - Known web shell signature
Treat the site as compromised: take a backup for analysis, remove the file, change all passwords and look for other modified files. - External script is loaded
Confirm the source is trusted. Prefer wp_enqueue_script() and consider Subresource Integrity. - Variable function call
Make sure the variable cannot be controlled by users, or call the function directly. - Backtick shell execution
Remove it. Themes should not run shell commands. - Request data is output without escaping
Escape on output with esc_html(), esc_attr() or esc_url() and sanitize on input. - Request data in a SQL query
Use $wpdb->prepare() with placeholders. - Request data in include/require
Map allowed values to fixed file names with an allowlist. - Request data in a file operation
Validate against an allowlist, use basename() and sanitize_file_name(), and keep operations inside a fixed directory. - Database query without prepare()
Build the query with $wpdb->prepare() and placeholders. - AJAX/admin-post handler without nonce check
Verify a nonce at the start of the handler. - AJAX/admin-post handler without capability check
Check the required capability with current_user_can() before doing anything. - REST route without permission_callback
Add a permission_callback that checks capabilities (use __return_true only for truly public data). - Public REST route
Confirm that the route only exposes public data and changes nothing. - Form processing without nonce check
Add wp_nonce_field() to the form and verify it with check_admin_referer() or wp_verify_nonce(). - Obfuscated string
Check what the string contains. Restore the file from a clean copy if you did not add it.
Related settings
- Settings → Targets: Themes to scan, Plugins to scan and Directories outside WordPress decide which files are checked. Each registered directory has its own Checks and exclusions.
- Settings → Checks → Enabled checks: switch “Dangerous code patterns” on or off.
- Settings → Checks → Maximum file size for code analysis: 2,048 KB by default. Larger files are not analyzed.
- Settings → Checks → Exclude patterns: files and folders that are not checked (by default
node_modules,vendor,.git,.svnandcache).