phpwarden

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

cmd-backtick · CWE-78

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

cmd-exec · CWE-78

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

cmd-passthru · CWE-78

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

cmd-pcntl-exec · CWE-78

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

cmd-popen · CWE-78

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

cmd-proc-open · CWE-78

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

cmd-process · CWE-78

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

cmd-shell-exec · CWE-78

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

cmd-system · CWE-78

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

mail-params-injection · CWE-88

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

sql-db-query · CWE-89

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

sql-doctrine · CWE-89

Request data is concatenated into createQuery()/executeQuery()/createNativeQuery().

Fix: Use setParameter() / parameter arrays instead of concatenation.

SQL injection via DB::select/statement/unpreparedhigh

sql-laravel-db · CWE-89

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

sql-laravel-raw · CWE-89

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

sql-mysql-query · CWE-89

A request value reaches the removed mysql_* API.

Fix: Migrate to PDO/mysqli prepared statements.

SQL injection via mysqli_query()high

sql-mysqli-query · CWE-89

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

sql-pg-query · CWE-89

A request value is concatenated into a pg_query() string.

Fix: Use pg_query_params() / pg_prepare().

Request data concatenated into prepare()high

sql-prepare-tainted · CWE-89

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

sql-sqlite · CWE-89

Request data is concatenated into an SQLite query.

Fix: Use SQLite3::prepare() with bindValue().

SQL injection via $wpdb without prepare()high

sql-wpdb · CWE-89

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-superglobal · CWE-621

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-tainted · CWE-15

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

ldap-injection · CWE-90

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

variable-variable-tainted · CWE-621

$$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

mail-header-injection · CWE-93

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-one-arg · CWE-621

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-fixation · CWE-384

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

xpath-injection · CWE-643

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-tainted · CWE-95

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

eval-tainted · CWE-95

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-tainted · CWE-470

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-encoded-payload · CWE-506

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

preg-replace-e · CWE-95

The /e modifier evaluates the replacement as PHP code.

Fix: Use preg_replace_callback().

User-controlled variable function callhigh

variable-function-tainted · CWE-470

$fn() is called where $fn comes from the request.

Fix: Map allowed actions to callables via a fixed whitelist.

create_function() usedmedium

create-function · CWE-95

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

path-copy-rename · CWE-22

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

path-delete · CWE-22

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

path-move-upload · CWE-434

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

path-read · CWE-22

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

path-readfile · CWE-22

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

path-write · CWE-73

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

upload-unrestricted · CWE-434

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

tls-verify-disabled · CWE-295

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

weak-hash-password · CWE-916

Fast unsalted hashes are cracked trivially; passwords need a slow adaptive hash.

Fix: Use password_hash() / password_verify().

openssl_encrypt() with ECB modemedium

openssl-ecb · CWE-327

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

weak-random-secret · CWE-338

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-no-salt · CWE-759

crypt() with one argument uses a weak, implementation-defined salt.

Fix: Use password_hash().

mcrypt_* usedlow

mcrypt-deprecated · CWE-327

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

ssrf-curl · CWE-918

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

ssrf-file-get-contents · CWE-918

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

ssrf-fsockopen · CWE-918

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

ssrf-http-client · CWE-918

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

ssrf-laravel-http · CWE-918

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

ssrf-wp-remote · CWE-918

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

blade-raw · CWE-79

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

twig-raw · CWE-79

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

xss-echo · CWE-79

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

xss-printf · CWE-79

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

xss-response · CWE-79

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

display_errors enabled at runtimelow

display-errors-on · CWE-209

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-call · CWE-200

phpinfo() discloses configuration, paths and environment secrets.

Fix: Remove the call or protect it behind admin authentication.

WordPress handlers

Unauthenticated AJAX handler performs writeshigh

wp-nopriv-ajax-no-auth · CWE-862

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

wp-option-key-tainted · CWE-15

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

wp-ajax-no-nonce · CWE-352

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

wp-rest-open-write · CWE-862

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

laravel-idor-hint · CWE-639

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

laravel-route-no-auth · CWE-862

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

symfony-route-no-auth · CWE-862

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

redirect-header · CWE-601

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

redirect-laravel · CWE-601

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

redirect-wp · CWE-601

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

hardcoded-aws-key · CWE-798

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

hardcoded-private-key · CWE-321

A PEM private key literal is committed in source.

Fix: Move the key to a protected file/secret store and rotate it.

Hardcoded credentialmedium

hardcoded-secret · CWE-798

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

xxe-entity-loader · CWE-611

libxml_disable_entity_loader(false) re-enables external entity loading.

Fix: Remove the call; do not enable entity substitution.

XML parsed with LIBXML_NOENThigh

xxe-noent · CWE-611

LIBXML_NOENT substitutes entities, enabling XXE file disclosure/SSRF.

Fix: Remove LIBXML_NOENT (and LIBXML_DTDLOAD).

XMLReader entity substitution enabledhigh

xxe-xmlreader-subst · CWE-611

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

laravel-csrf-excluded · CWE-352

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

wp-admin-post-no-nonce · CWE-352

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

unserialize-tainted · CWE-502

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-no-allowed-classes · CWE-502

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

include-tainted · CWE-98

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

allow-url-include · CWE-98

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

laravel-app-debug-env · CWE-489

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

laravel-guarded-empty · CWE-915

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

mass-assignment · CWE-915

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

second-order-injection · CWE-74

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.