Code rules
The 89 rules behind phpwarden code (88 run by default; the rest are opt-in with --all-rules).
13 critical, 45 high, 23 medium, 8 low.
Each rule looks for one pattern that is almost always a real bug. Most follow request data
($_GET, $_POST, cookies, headers, Laravel, Symfony and WordPress request objects) through
the whole program, across files, classes, array keys and includes, to a dangerous call. Rules tagged
whole-program use the framework models (routes, authorisation, Blade, Twig, Eloquent, options) and are
not in the faster PHPWARDEN_CODE_ENGINE=tokens mode. Data saved to a database and read back is followed, matched by
table name (not by row; names from constants, config, $wpdb->prefix and Eloquent $table are resolved, names built from run-time data are not), and run-time callbacks are followed too; a clean run means "none of these patterns", not "this code is safe". How to run it and how to silence a finding:
docs. To silence one line: // phpwarden-ignore: <rule-id>.
Command injection (10)SQL injection (10)Other injection (8)Code execution (7)Path traversal and file operations (7)Cryptography and TLS (6)Server-side request forgery (6)Cross-site scripting (5)Configuration (4)WordPress handlers (4)Missing authorisation and IDOR (3)Open redirect (3)Hardcoded secrets (3)XML external entities (3)Cross-site request forgery (2)Deserialization (2)File inclusion (2)Laravel (2)Framework (mass assignment) (1)Second-order injection (1)
Command injection
User input in backtick shell commandcritical
A request value is interpolated into a `backtick` shell command.
Fix: Use escapeshellarg() on every interpolated value, or avoid the shell.
User input reaches exec()critical
Request data is passed to exec(), allowing OS command injection.
Fix: Avoid the shell; if unavoidable, escape each argument with escapeshellarg() and whitelist values.
User input reaches passthru()critical
Request data is passed to passthru(), allowing OS command injection.
Fix: Avoid the shell; if unavoidable, escape each argument with escapeshellarg() and whitelist values.
User input reaches pcntl_exec()critical
Request data is passed to pcntl_exec(), allowing OS command injection.
Fix: Avoid the shell; if unavoidable, escape each argument with escapeshellarg() and whitelist values.
User input reaches popen()critical
Request data is passed to popen(), allowing OS command injection.
Fix: Avoid the shell; if unavoidable, escape each argument with escapeshellarg() and whitelist values.
User input reaches proc_open()critical
Request data is passed to proc_open(), allowing OS command injection.
Fix: Avoid the shell; if unavoidable, escape each argument with escapeshellarg() and whitelist values.
User input in a shell command line (Process)criticalwhole-program
Request data is part of a command string given to Process::fromShellCommandline(), new Process(string) or Laravel's Process::run(), which runs it through a shell.
Fix: Pass the command as an array of arguments (new Process(['cmd', $arg])) and validate each value.
User input reaches shell_exec()critical
Request data is passed to shell_exec(), allowing OS command injection.
Fix: Avoid the shell; if unavoidable, escape each argument with escapeshellarg() and whitelist values.
User input reaches system()critical
Request data is passed to system(), allowing OS command injection.
Fix: Avoid the shell; if unavoidable, escape each argument with escapeshellarg() and whitelist values.
User input in mail() additional parametershigh
The 5th mail() argument is passed to sendmail; attacker control allows writing files (RCE).
Fix: Never pass request data as mail() additional_params; use escapeshellarg() and a fixed value.
SQL injection
SQL injection via ->query()/->exec()high
A request value is concatenated into a SQL string run by PDO/mysqli query()/exec().
Fix: Use ->prepare() with placeholders and bind values.
SQL/DQL injection via Doctrinehigh
Request data is concatenated into createQuery()/executeQuery()/createNativeQuery().
Fix: Use setParameter() / parameter arrays instead of concatenation.
SQL injection via DB::select/statement/unpreparedhigh
Request data is concatenated into a raw DB facade query.
Fix: Pass values as the bindings array: DB::select('... where id = ?', [$id]).
SQL injection via Laravel raw expressionhigh
Request data is concatenated into DB::raw()/whereRaw()/selectRaw()/orderByRaw().
Fix: Use bindings: whereRaw('col = ?', [$value]); whitelist identifiers for ORDER BY.
SQL injection via mysql_query()high
A request value reaches the removed mysql_* API.
Fix: Migrate to PDO/mysqli prepared statements.
SQL injection via mysqli_query()high
A request value is concatenated/interpolated into a mysqli_query() string.
Fix: Use mysqli prepared statements with bound parameters.
SQL injection via pg_query()high
A request value is concatenated into a pg_query() string.
Fix: Use pg_query_params() / pg_prepare().
Request data concatenated into prepare()high
Building the prepare() template from request data defeats the prepared statement.
Fix: Put placeholders (? / :name / %s) in the template and pass values separately.
SQL injection via SQLite APIhigh
Request data is concatenated into an SQLite query.
Fix: Use SQLite3::prepare() with bindValue().
SQL injection via $wpdb without prepare()high
A request value is interpolated into a $wpdb query without $wpdb->prepare().
Fix: Wrap the query in $wpdb->prepare() with %s/%d placeholders.
Other injection
extract() on request superglobalhigh
extract($_GET/$_POST/$_REQUEST) re-creates register_globals: attackers can overwrite any variable.
Fix: Read the specific keys you need from the request.
PHP configuration set from request datahigh
ini_set()/putenv() with request data lets an attacker change runtime configuration.
Fix: Never pass request data to ini_set()/putenv().
LDAP filter built from request datahigh
A request value is concatenated into an LDAP search filter.
Fix: Escape with ldap_escape($v, '', LDAP_ESCAPE_FILTER).
Variable variable named by request datahigh
$$name where $name comes from the request lets attackers overwrite arbitrary variables.
Fix: Use an array with whitelisted keys instead of variable variables.
User input in mail headersmediumwhole-program
Request data is used in the headers argument of mail()/wp_mail(); a newline lets an attacker add headers.
Fix: Never build mail headers from request data; strip CR/LF and validate addresses.
parse_str() without result arraymedium
parse_str() with one argument writes variables into the current scope (removed in PHP 8).
Fix: Pass a second argument: parse_str($qs, $out).
Session ID set from request datamedium
session_id() is set from client input (session fixation).
Fix: Let PHP generate IDs; call session_regenerate_id(true) on login.
XPath expression built from request datamedium
A request value is concatenated into an XPath query.
Fix: Whitelist or strictly validate the value before using it in XPath.
Code execution
User input reaches assert()critical
assert() with a string argument evaluates it as code on PHP < 8.
Fix: Never pass request data to assert(); use explicit validation.
User input reaches eval()critical
Request data is evaluated as PHP code, giving an attacker remote code execution.
Fix: Never eval() request data. Replace with a whitelist/dispatch table.
User-controlled callback namehigh
call_user_func*/array_map etc. invoked with a callable chosen by the request.
Fix: Map allowed actions to callables via a fixed whitelist.
eval() of decoded payloadhigh
eval(base64_decode(...))/gzinflate is the signature of obfuscated backdoors and webshells.
Fix: Remove the code and investigate how it got there (possible compromise).
preg_replace() with /e modifierhigh
The /e modifier evaluates the replacement as PHP code.
Fix: Use preg_replace_callback().
User-controlled variable function callhigh
$fn() is called where $fn comes from the request.
Fix: Map allowed actions to callables via a fixed whitelist.
create_function() usedmedium
create_function() is an eval() wrapper, removed in PHP 8.
Fix: Replace with an anonymous function (closure).
Path traversal and file operations
User-controlled path in copy()/rename()/symlink()high
A request value controls a filesystem copy/rename/link target.
Fix: Never accept filesystem paths from the client.
User-controlled path in unlink()/rmdir()high
A request value controls which file is deleted.
Fix: Map IDs to paths server-side and verify containment with realpath().
Upload destination built from request datahigh
move_uploaded_file() destination uses a client-supplied name (traversal, .php upload).
Fix: Generate the stored file name server-side and whitelist extensions.
User-controlled path in file readhigh
A request value controls the path given to file_get_contents()/file()/fopen().
Fix: Resolve with basename()/realpath() and verify the result is inside an allowed directory.
User-controlled path in readfile()/show_source()high
A request value controls a file that is streamed to the client (arbitrary file disclosure).
Fix: Map download IDs to paths server-side; never accept paths from the client.
User-controlled path in file writehigh
A request value controls the path of file_put_contents()/fwrite target (can write webshells).
Fix: Fix the directory and sanitize the file name with basename() plus an extension whitelist.
Uploaded file stored without a type checkhigh
move_uploaded_file() keeps the client's file name or extension and nothing in the function restricts the file type, so a .php file can be uploaded and run. basename() only stops directory traversal.
Fix: Allow-list extensions (pathinfo + in_array) and check the content type (finfo/getimagesize); store under a server-generated name outside the web root.
Cryptography and TLS
TLS certificate verification disabledhigh
CURLOPT_SSL_VERIFYPEER/VERIFYHOST, 'verify_peer', 'sslverify' or Guzzle 'verify' turned off: man-in-the-middle possible.
Fix: Keep verification on; point CURLOPT_CAINFO / 'verify' at a CA bundle if needed.
Password hashed with md5()/sha1()high
Fast unsalted hashes are cracked trivially; passwords need a slow adaptive hash.
Fix: Use password_hash() / password_verify().
openssl_encrypt() with ECB modemedium
ECB mode leaks plaintext structure and has no integrity.
Fix: Use an AEAD mode such as aes-256-gcm with a random IV, or libsodium.
Predictable random used for a secretmedium
rand()/mt_rand()/uniqid()/lcg_value()/str_shuffle() are not cryptographically secure but generate a token/password/nonce.
Fix: Use random_bytes() / random_int() / bin2hex(random_bytes(32)).
crypt() without saltlow
crypt() with one argument uses a weak, implementation-defined salt.
Fix: Use password_hash().
mcrypt_* usedlow
mcrypt is abandoned and removed in PHP 7.2.
Fix: Use openssl_* with AEAD modes or libsodium (sodium_crypto_*).
Server-side request forgery
User-controlled URL in cURL requesthigh
A request value is used as CURLOPT_URL / curl_init() URL (server-side request forgery).
Fix: Validate the host against an allowlist and block internal address ranges.
User-controlled URL in file_get_contents()/fopen()high
A request value completes an http(s) URL fetched by the server.
Fix: Validate the host against an allowlist; prefer a fixed base URL plus encoded parameters.
User-controlled host in fsockopen()high
A request value chooses the host the server connects to.
Fix: Validate the host against an allowlist.
User-controlled URL in an HTTP client requesthighwhole-program
A request value is used as the URL of a Guzzle / Symfony HttpClient / PSR-18 request (server-side request forgery).
Fix: Allow-list hosts and schemes before requesting a URL that comes from the request.
User-controlled URL in Http:: clienthigh
A request value is used as the URL of a Laravel Http:: request.
Fix: Validate the host against an allowlist.
User-controlled URL in wp_remote_*()high
A request value is fetched with wp_remote_get/post/request (not the wp_safe_* variants).
Fix: Use wp_safe_remote_get()/wp_safe_remote_post() and validate the host.
Cross-site scripting
Request data printed unescaped in a Blade templatemediumwhole-program
A value that comes from the request reaches {!! ... !!} in a Blade view, which prints it without escaping.
Fix: Use {{ ... }} (escaped), or sanitize with clean()/strip_tags before using {!! !!}.
Request data printed with |raw in a Twig templatemediumwhole-program
A value that comes from the request is printed with the |raw filter or inside {% autoescape false %}.
Fix: Remove |raw, or sanitize the value (e.g. with an HTML sanitizer) before rendering.
Unescaped user input echoedmedium
Request data is written to the response with echo/print/die without escaping.
Fix: Escape on output: htmlspecialchars($x, ENT_QUOTES, 'UTF-8') / esc_html() / e().
Unescaped user input in printf()medium
Request data is formatted into the response by printf()/vprintf() without escaping.
Fix: Escape each argument with htmlspecialchars()/esc_html().
Request data returned as an HTML response bodymediumwhole-program
Request data is the body of a Response with the default text/html content type.
Fix: Escape the value, return JSON (JsonResponse/response()->json()), or set a non-HTML Content-Type.
Configuration
Sensitive cookie without Secure/HttpOnlylow
A session/auth-like cookie is set without both the secure and httponly flags.
Fix: setcookie($n, $v, ['secure' => true, 'httponly' => true, 'samesite' => 'Lax']).
display_errors enabled at runtimelow
Error messages with paths and SQL leak to visitors.
Fix: Log errors (log_errors=On) and keep display_errors Off in production.
phpinfo() call in application codelow
phpinfo() discloses configuration, paths and environment secrets.
Fix: Remove the call or protect it behind admin authentication.
Session cookie flags disabledlow
ini_set('session.cookie_httponly'/'session.cookie_secure', 0) weakens the session cookie.
Fix: Keep session.cookie_httponly=1 and session.cookie_secure=1 (and cookie_samesite).
WordPress handlers
Unauthenticated AJAX handler performs writeshigh
A wp_ajax_nopriv_ handler changes options/users/posts/DB without a nonce or capability check.
Fix: Add check_ajax_referer() and current_user_can(); drop the nopriv hook if not needed.
Request data chooses which option or meta key is writtenhighwhole-program
update_option()/update_user_meta() and similar are called with a key taken from the request, so a request can overwrite any setting (e.g. users_can_register, default_role, wp_capabilities).
Fix: Map allowed keys from a fixed list; never use a request value as the option or meta name.
AJAX handler performs writes without nonce checkmedium
A wp_ajax_ handler writes without check_ajax_referer()/wp_verify_nonce() (CSRF).
Fix: Call check_ajax_referer('action') and current_user_can() before writing.
REST route with __return_true permission writes datamedium
register_rest_route() with 'permission_callback' => '__return_true' whose callback writes.
Fix: Use a permission_callback that checks current_user_can().
Missing authorisation and IDOR
Record from a route parameter changed without an ownership checkmediumwhole-program
An authenticated route loads a model from a route parameter and updates or deletes it, with no policy, Gate or ownership comparison, so one user may change another user's record (IDOR).
Fix: Authorize with a policy ($this->authorize('update', $post)) or scope the query to the current user.
State-changing route with no authentication or authorizationmediumwhole-program
A POST/PUT/PATCH/DELETE route reaches a database write, but neither the route (or its group) has auth middleware nor does the controller call authorize() or a Gate.
Fix: Add ->middleware('auth') (or 'can:...') to the route or group, or call $this->authorize() in the controller.
Controller action writes entities with no access checkmediumwhole-program
A #[Route] action persists or removes entities without #[IsGranted] or denyAccessUnlessGranted().
Fix: Add #[IsGranted('ROLE_...')] or call $this->denyAccessUnlessGranted(); or cover the path in access_control.
Open redirect
Open redirect via header('Location: ...')medium
The redirect target comes from the request.
Fix: Redirect only to relative paths or an allowlist of hosts.
Open redirect via redirect()/Redirect::to()medium
A Laravel redirect target comes from the request.
Fix: Redirect to named routes, or validate the URL host against an allowlist.
Open redirect via wp_redirect()medium
wp_redirect() with a request-supplied URL allows redirects to any host.
Fix: Use wp_safe_redirect() (optionally with wp_validate_redirect()).
Hardcoded secrets
AWS access key ID in sourcehigh
An AKIA/ASIA access key ID literal is committed in source.
Fix: Revoke the key in IAM and load credentials from the environment/instance role.
Private key embedded in sourcehigh
A PEM private key literal is committed in source.
Fix: Move the key to a protected file/secret store and rotate it.
Hardcoded credentialmedium
A literal password/secret/API key/token is committed in source.
Fix: Load it from the environment (getenv/env()) or a secret store and rotate the exposed value.
XML external entities
External entity loader enabledhigh
libxml_disable_entity_loader(false) re-enables external entity loading.
Fix: Remove the call; do not enable entity substitution.
XML parsed with LIBXML_NOENThigh
LIBXML_NOENT substitutes entities, enabling XXE file disclosure/SSRF.
Fix: Remove LIBXML_NOENT (and LIBXML_DTDLOAD).
XMLReader entity substitution enabledhigh
XMLReader::SUBST_ENTITIES set to true enables XXE.
Fix: Do not enable SUBST_ENTITIES.
Cross-site request forgery
State-changing route excluded from CSRF protectionmediumwhole-program
A URI in VerifyCsrfToken::$except (or validateCsrfTokens(except: ...)) matches a POST/PUT/PATCH/DELETE web route, so another site can submit it on behalf of a signed-in user.
Fix: Remove it from the exception list, or verify the caller another way (a webhook signature).
admin-post handler changes state without a nonce checkmediumwhole-program
An admin_post_ action handler writes options, posts or the database without check_admin_referer() or wp_verify_nonce(), so another site can trigger it for a logged-in administrator.
Fix: Add a nonce to the form and call check_admin_referer('action') at the top of the handler.
Deserialization
User input reaches unserialize()critical
Deserializing request data allows PHP object injection (POP gadget chains -> RCE).
Fix: Use json_decode(), or unserialize($x, ['allowed_classes' => false]) for trusted formats only.
unserialize() without allowed_classeslowopt-in
unserialize() of non-literal data without an allowed_classes restriction can instantiate arbitrary classes.
Fix: Pass ['allowed_classes' => false] (or an explicit class list), or switch to JSON.
File inclusion
User input in include/require pathcritical
A request value controls the path of include/require (LFI/RFI, often RCE).
Fix: Include from a fixed whitelist of files; never build include paths from input.
allow_url_include enabled at runtimehigh
Enabling allow_url_include makes any inclusion bug a remote code execution.
Fix: Remove the ini_set() call; keep allow_url_include Off.
Laravel
APP_DEBUG=true in committed .envhigh
Debug mode exposes stack traces, environment variables and secrets (Ignition RCE history).
Fix: Set APP_DEBUG=false in production and do not commit .env (add it to .gitignore).
Model with $guarded = []low
All attributes are mass assignable; request data passed to create()/update() can set any column.
Fix: Declare $fillable with the allowed columns.
Framework (mass assignment)
Whole request mass-assigned to an Eloquent modelhighwhole-program
The complete request ($request->all(), except(), input()) is passed to create()/fill()/update() on a model with $guarded = [] (or through forceFill/forceCreate), so a request can set any column, e.g. is_admin.
Fix: Pass $request->validated() or $request->only([...]) with an explicit list, and declare $fillable.
Second-order injection
Stored request data used later in a sink (second-order)highwhole-program
Request data is saved under a fixed option or meta key and read back elsewhere, where it reaches a SQL query, HTML output, an include or another sink without being sanitised for that use.
Fix: Sanitise when the value is used, not only when it is stored: prepare SQL, escape output, whitelist paths.