wp-security-rules
Security rules for reviewing WordPress plugins, in three layers:
- Semgrep taint rules. 12 rules that follow user input (
$_GET,$_POST,$_REQUEST,$_COOKIE,$_FILES,WP_REST_Requestparameters, …) through variables and string building into dangerous sinks, and understand WordPress sanitizers such as$wpdb->prepare(),esc_html(),absint()andsanitize_file_name(). Every rule ships with annotated test cases. - 219 regex patterns. Fast, line-based triage patterns across 19 categories, usable from Python,
grep -iEorrg -i, with no other tooling needed. - Classification. Map any finding to a CWE id, severity, CVSS v3.1 vector and WordPress-specific remediation advice.
Pure Python, zero dependencies. Semgrep is only needed if you want to run the Semgrep rules.
Install
pip install wp-security-rules
pip install "wp-security-rules[semgrep]" # also installs the Semgrep CLI (Linux/macOS)
Semgrep rules
| Rule id | Finds | CWE |
|---|---|---|
wordpress-sql-injection |
input in $wpdb->query/get_results/get_var/get_row/get_col without prepare() |
CWE-89 |
wordpress-xss |
input reaching echo, print, printf, wp_die() unescaped |
CWE-79 |
wordpress-command-injection |
input in exec, system, shell_exec, passthru, popen, proc_open, backticks |
CWE-78 |
wordpress-code-injection |
input in eval, assert, create_function, call_user_func, dynamic calls |
CWE-94 |
wordpress-preg-replace-eval-modifier |
preg_replace() with the /e modifier |
CWE-94 |
wordpress-file-inclusion |
input in include / require |
CWE-98 |
wordpress-path-traversal |
input in readfile, fopen, file_put_contents, unlink, copy, rename, … |
CWE-22 |
wordpress-object-injection |
input in unserialize() / maybe_unserialize() |
CWE-502 |
wordpress-ssrf |
input as the URL of wp_remote_*, cURL, file_get_contents |
CWE-918 |
wordpress-open-redirect |
input in wp_redirect() or a Location: header |
CWE-601 |
wordpress-privilege-escalation |
input as an option name, user id, role, capability or user-meta key | CWE-269 |
wordpress-unsafe-file-upload |
move_uploaded_file() in a function with no file-type check |
CWE-434 |
Run them on a plugin:
semgrep --config "$(wp-security-rules semgrep-path)" path/to/plugin
Or copy them into your own rules repository or CI:
wp-security-rules export-semgrep ./semgrep-rules/wordpress
From Python:
from wp_security_rules import run_semgrep, semgrep_rules_dir
results = run_semgrep("path/to/plugin") # parsed Semgrep JSON
for r in results["results"]:
print(r["check_id"], r["path"], r["start"]["line"])
Semgrep does not run natively on Windows. Use WSL, or Docker:
docker run --rm -v "$PWD:/src" semgrep/semgrep semgrep --config /src/rules /src/plugin
On real code: across 34 popular WordPress.org plugins (16,696 PHP files, including WooCommerce, Jetpack, Elementor and Yoast SEO), the pack reports 126 findings, about 4 per plugin. These are leads for manual review in well-maintained code, not confirmed vulnerabilities.
The rules are validated with semgrep --validate and tested with semgrep --test against vulnerable (// ruleid:) and safe (// ok:) samples in tests/semgrep/. CI runs both on every push.
Regex patterns
from wp_security_rules import scan_directory, scan_text, VULNERABILITY_PATTERNS, CATEGORIES
for m in scan_directory("path/to/plugin", categories=["SQLi", "RCE", "Unserialize"]):
print(m.severity, m.cwe, f"{m.file}:{m.line}", m.pattern)
print(" ", m.snippet)
scan_text("<?php echo $_GET['q'];")
# [PatternMatch(pattern='XSS - Direct Echo User Input', category='XSS', severity='MEDIUM',
# cwe='CWE-79', file='<string>', line=1, column=7, snippet="<?php echo $_GET['q'];")]
len(VULNERABILITY_PATTERNS) # 219
CATEGORIES # ('Auth', 'CSRF', 'Crypto', 'Info', 'LFI', 'POP Chain', 'Path', 'Privesc', 'RCE',
# 'REST', 'RFI', 'Redirect', 'SQLi', 'SSRF', 'Unserialize', 'Upload', 'WP', 'XSS', 'XXE')
Command line (exit code 1 when anything matches, so it can gate CI):
wp-security-rules scan path/to/plugin --min-severity HIGH
wp-security-rules scan path/to/plugin --category SQLi --category XSS --json
The patterns are deliberately broad. They are for finding code worth reading, and will produce false positives. Use the Semgrep rules when you need data-flow precision.
Classification
from wp_security_rules import classify, get_cwe_id, get_severity, get_cvss_vector, get_remediation
classify("SQLi - Direct wpdb Query")
# {'type': 'SQLi - Direct wpdb Query', 'cwe': 'CWE-89', 'cwe_name': 'SQL Injection',
# 'severity': 'CRITICAL', 'cvss_vector': 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H',
# 'remediation': '**SQL Injection Remediation:**\n1. Use $wpdb->prepare() ...'}
get_cwe_id("wordpress-ssrf") # 'CWE-918'
get_cvss_vector({"type": "XSS", "authenticated": True}) # 'CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N'
$ wp-security-rules classify path traversal
CWE: CWE-22 Path Traversal
Severity: HIGH
CVSS: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N
...
Keywords are matched as whole words, and specific vulnerability names take precedence over generic words. So "XSS - Wp_kses Bypass" is classified as XSS rather than authentication bypass, and "Source code disclosure" is not mistaken for remote code execution.
Limitations
- The Semgrep rules are intraprocedural taint rules. Input that flows through a helper function in another file, or through the database (second-order injection), is not tracked. A sanitizer applied in the wrong context (for example
esc_html()inside a JavaScript string) is still treated as safe. - Capability and nonce checks are not modelled by the taint rules. An authenticated, capability-checked admin form that writes
$_POSTinto an option will still be reported. For entry-point and authorization analysis, seewp-attack-surface. - CVSS vectors are heuristic starting points. Score each confirmed vulnerability yourself.
Origin
Extracted from the static-analysis stages of the ARKA WordPress plugin vulnerability scanner. The Semgrep rules were rewritten in taint mode for this release.
License
Metadata
Release files for wp-security-rules 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wp_security_rules-0.1.0.tar.gz | 28.4 kB | Without provenance | Details for wp_security_rules-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wp_security_rules-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for wp_security_rules-0.1.0-py3-none-any.whl |
Total release size: 63.3 kB
Release files / wp_security_rules-0.1.0.tar.gz
| Download URL | wp_security_rules-0.1.0.tar.gz |
|---|---|
| Size | 28.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d7f9fa138d5153b947d7a78ae7572374669c107eea80c2f865f7235e2ffc3e7d
|
|
BLAKE2b-256 checksum How to use checksums |
69fa85d2508bcab5bda18c46732c110d6078cfcb711fc4cba68de4bff4ac4e62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / wp_security_rules-0.1.0-py3-none-any.whl
| Download URL | wp_security_rules-0.1.0-py3-none-any.whl |
|---|---|
| Size | 34.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4ad0a985c1ad0d0c919bef3260f70bb9330bb345115f62429a6418c69d15df4
|
|
BLAKE2b-256 checksum How to use checksums |
8d9f4ae9ced0f54e29de27328513675814a38764daf30dfa824b230cd5e0cb2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Security for wp-security-rules 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.