wp-attack-surface
Map every place where outside input can reach a WordPress plugin's code, without running WordPress or installing PHP.
wp-attack-surface reads a plugin's PHP source and lists its entry points:
| Type | Recognised registration | Reached via |
|---|---|---|
ajax |
add_action( 'wp_ajax_[nopriv_]…' ) |
/wp-admin/admin-ajax.php?action=… |
admin_post |
add_action( 'admin_post_[nopriv_]…' ) |
/wp-admin/admin-post.php?action=… |
rest_route |
register_rest_route() |
/wp-json/<namespace>/<route> |
shortcode |
add_shortcode() |
[tag] in post content |
admin_page |
add_menu_page(), add_submenu_page(), add_options_page(), … |
/wp-admin/admin.php?page=… |
block |
register_block_type() (dynamic blocks with render_callback) |
block editor / block renderer |
widget |
class … extends WP_Widget |
public pages |
query_vars |
add_filter( 'query_vars' ) |
query string |
For each entry point it reports whether it is reachable without logging in, a triage risk level, and whether the handler calls a nonce check (check_ajax_referer, check_admin_referer, wp_verify_nonce) or a capability check (current_user_can, user_can, …). The handler is located even when it is defined in a different file from the registration.
It is meant as the first step of a security review: it tells you where to look.
Install
pip install wp-attack-surface
Zero dependencies, pure Python 3.10+.
Command line
$ wp-attack-surface ./contact-form-7 --public-only
== Contact Form 7 6.1.5 (contact-form-7)
files scanned: 111 entry points: 6 public: 6 high risk: 3
RISK TYPE PUBLIC NONCE CAP NAME -> CALLBACK [FILE:LINE]
HIGH rest_route yes no no {self::route_namespace}/contact-forms/(?P<id>\d+)/feedback -> $this->create_feedback [includes/rest-api.php:107]
...
MEDIUM shortcode yes no no contact-form-7 -> wpcf7_contact_form_tag_func [load.php:136]
NONCE and CAP are yes or no when the handler body was found, and ? when it could not be located (for example a callback stored in a variable).
wp-attack-surface ./plugin --json > surface.json # machine-readable output
wp-attack-surface ./plugin --type ajax --type rest_route
wp-attack-surface ./plugins/* # several plugins at once
wp-attack-surface ./plugin --exclude vendor --exclude lib
python -m wp_attack_surface ./plugin # same as the console script
Python API
from wp_attack_surface import map_plugin
surface = map_plugin("path/to/plugin")
print(surface.metadata.name, surface.metadata.version)
print(surface.summary())
# {'plugin': 'my-plugin', 'version': '1.2.3', 'files_scanned': 42, 'entry_points': 17,
# 'public': 6, 'high_risk': 4, 'by_type': {'ajax': 9, 'admin_post': 1, 'rest_route': 3, ...}}
# Unauthenticated AJAX handlers with no nonce check: the classic CSRF / missing-auth pattern
for ep in surface.by_type("ajax"):
if ep.public and ep.has_nonce_check is False:
print(ep.name, ep.callback, f"{ep.file}:{ep.line}")
surface.to_dict() # JSON-serialisable
Each EntryPoint has:
| Field | Meaning |
|---|---|
type |
one of EntryPointType.ALL |
name |
action, route, tag, menu slug, block or class name ({…} marks a dynamic part) |
file, line |
where it is registered (path relative to the plugin root) |
callback |
handler, e.g. "$this->save", "My_Class::run", "<closure>" |
public |
reachable without authentication |
risk_level |
HIGH, MEDIUM or LOW triage hint |
url_example |
how to reach it |
has_nonce_check, has_capability_check |
True / False, or None if the handler was not found |
details |
extras such as methods, permission_callback, capability, dynamic_name, handler_located |
Other helpers:
from wp_attack_surface import map_source, read_plugin_metadata, parse_plugin_headers
map_source(php_code, "file.php") # one source string
read_plugin_metadata("path/to/plugin") # plugin header + readme.txt (Tested up to, Stable tag, ...)
parse_plugin_headers(php_code) # same rules as WordPress core get_file_data()
How it works
There is no PHP parser and no PHP runtime. The library has just enough lexical awareness to be reliable:
- comments are removed and string contents are masked, so commented-out or quoted
add_action(...)calls are ignored and line numbers stay exact; - call arguments are split with bracket and string awareness, so multi-line registrations,
array( $this, 'cb' ),[ $this, 'cb' ],'Class::method'and closures are all understood; - REST route option arrays are read for
methods,callbackandpermission_callback. A route with nopermission_callback, or with__return_true, is reported as public; - handler bodies are found in the same file first, then through a plugin-wide function index.
Directories named vendor, node_modules, test, tests, .git and .svn are skipped by default (whole path components only, so a folder named latest/ is still scanned). PHP files over 2 MB are skipped and listed in files_skipped.
Accuracy on real plugins
Across 34 popular WordPress.org plugins (WooCommerce, Jetpack, Elementor, Yoast SEO, WPForms and others):
- every one of the 594 literal
wp_ajax_*registrations found by a plain-text search was mapped; - 904 REST routes were mapped;
- the handler body was located for 96% of AJAX entry points.
Limitations
- Checks are detected only when they appear directly in the handler body. A handler that calls
$this->verify_request(), which in turn callscheck_ajax_referer(), is reported ashas_nonce_check=False. TreatFalseas "verify manually", not as a confirmed vulnerability. - Hook names and routes built at runtime are reported with the dynamic part in braces, e.g.
{$this->namespace}/items. - Routes registered through
$this->get_routes()or option arrays held in variables are reported withdetails["options_unresolved"] = Trueand treated as public. - Handlers are matched by function name. If two classes define a method with the same name, the first definition found is used.
Origin
Extracted and substantially extended from the attack-surface stage of the ARKA WordPress plugin vulnerability scanner.
License
Metadata
Release files for wp-attack-surface 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_attack_surface-0.1.0.tar.gz | 19.1 kB | Without provenance | Details for wp_attack_surface-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wp_attack_surface-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for wp_attack_surface-0.1.0-py3-none-any.whl |
Total release size: 38.2 kB
Release files / wp_attack_surface-0.1.0.tar.gz
| Download URL | wp_attack_surface-0.1.0.tar.gz |
|---|---|
| Size | 19.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
967ae1e24bfdc78ed8620a9aa6dff18268e7b1b5c3253698de478068cdc624cc
|
|
BLAKE2b-256 checksum How to use checksums |
afbd1dbea090deed185b4031849bedc96a2da78296b53cd12dd092aa7ae34390
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / wp_attack_surface-0.1.0-py3-none-any.whl
| Download URL | wp_attack_surface-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
982a4c640c7ccdf3be99c017ab70f8087adcb3c55ccdc7151035c0208222784f
|
|
BLAKE2b-256 checksum How to use checksums |
019504781ef6232c00d022f2a42315dfbe658101e1646cb71245248e6dba3cc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Security for wp-attack-surface 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.