Check reference

Dangerous code patterns

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.

FindingSeverityMeaning
eval() is used
php.eval
Higheval() 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 code
php.assert_dynamic
HighOn older PHP versions assert() evaluates a string argument as code, a common backdoor technique.
create_function() is used
php.create_function
Highcreate_function() evaluates code internally and was removed in PHP 8. It is also used by malware.
preg_replace() with the /e modifier
php.preg_replace_e
CriticalThe /e modifier evaluates the replacement as PHP code. It only works on very old PHP and is a well-known backdoor pattern.
Shell command execution
php.shell_exec
HighFunctions such as shell_exec(), system(), exec() and passthru() run operating system commands. Themes rarely need them and web shells rely on them.
Chained decoding functions
php.decode_chain
CriticalNested calls such as base64_decode(gzinflate(…)) are typical of obfuscated malware.
base64_decode() is used
php.base64_decode
Lowbase64_decode() has legitimate uses but is also used to hide code.
Remote or stream file inclusion
php.remote_include
Criticalinclude/require with a URL or stream wrapper (http://, php://, data://) executes code from outside the server.
External URL is loaded
php.remote_fetch
InfoThe code fetches content from a fixed external URL. This can be legitimate (APIs) but is also used to download payloads.
unserialize() on request data
php.unserialize_input
CriticalUnserializing user input enables PHP object injection.
extract() on request data
php.extract_input
Highextract() on $_GET/$_POST lets visitors overwrite any local variable.
Error reporting disabled in code
php.error_reporting_off
Lowerror_reporting(0) hides errors. Malware uses it to stay unnoticed.
Known web shell signature
php.webshell_marker
CriticalThe file contains a string used by well-known web shells.
External script is loaded
html.external_script
InfoA script is loaded from another domain. If that domain is compromised, so is your site.
Variable function call
php.variable_function
LowCalling $name(…) runs whatever function the variable contains. Malware uses it to hide calls such as system().
Backtick shell execution
php.backtick_exec
HighText between backticks is executed as a shell command.
Request data is output without escaping
php.input_output
HighA value from $_GET/$_POST/$_REQUEST/$_COOKIE is printed directly, which allows cross-site scripting (XSS).
Request data in a SQL query
php.input_sql
CriticalA request value is used in a database query without $wpdb->prepare(), which allows SQL injection.
Request data in include/require
php.input_include
CriticalA request value decides which file is included, which allows local or remote file inclusion.
Request data in a file operation
php.input_file
HighA 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 MediumA $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 check
php.ajax_missing_nonce
High MediumThe 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 check
php.ajax_missing_capability
MediumAny logged-in user (including subscribers) can call this handler because current_user_can() is not checked.
REST route without permission_callback
php.rest_missing_permission
HighThe route has no permission_callback, so access control is undefined.
Public REST route
php.rest_public_endpoint
LowThe route is open to everyone (permission_callback is __return_true).
Form processing without nonce check
php.form_missing_nonce
MediumThe file handles $_POST and changes data, but no nonce is verified anywhere in the file.
Obfuscated string
php.obfuscated_string
HighA 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, .svn and cache).