一键导入
wp-plugin-improvement-auditor
WordPress plugin security and code quality audit for improvement planning
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
WordPress plugin security and code quality audit for improvement planning
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | wp-plugin-improvement-auditor |
| description | WordPress plugin security and code quality audit for improvement planning |
Use these instructions when the user requests a security audit, code quality review, or improvement assessment of a WordPress plugin. This skill is configured for PublishPress Shortlinks (tinypress.php), a link shortening, tracking, branding, and affiliate link management plugin. It generates both detailed security findings (GHSA format) and spreadsheet-compatible metrics for planning improvement priorities.
Conduct a comprehensive technical audit covering security, code quality, and maintainability. The goal is to identify the current state of the codebase and produce a prioritized improvement roadmap. Generate both:
The output is formatted for direct paste into tracking spreadsheets with scores aligned to improvement planning criteria.
NEVER analyze code in these directories (applies to all searches, greps, and phpmetrics):
/vendor//lib/vendor//dist//.git/ and all hidden folders (.*)/dev-workspace//node_modules//tests/Use Grep tool to search for these patterns (exclude vendor, lib, tests, dist, dev-workspace):
SQL Injection:
\$wpdb->get_results.*\$ or \$wpdb->query.*\$ without prepare()$wpdb->get_results("SELECT * FROM table WHERE id = $id")XSS (Cross-Site Scripting):
echo \$_(POST|GET|REQUEST) without escapingesc_html(), esc_attr(), esc_url()dangerouslySetInnerHTML with user inputCSRF (Cross-Site Request Forgery):
wp_verify_nonce()Authentication & Authorization:
current_user_can() checks before privileged operationspermission_callbackDangerous Functions:
eval\(|exec\(|system\(|shell_exec\(|passthru\(|base64_decode\(unserialize() with user input, create_function()File Operations:
move_uploaded_file(), file_put_contents()../), missing extension checksOpen Redirect (Shortlinks-Specific — HIGH PRIORITY):
class-redirection.php and tinypress.phpwp_redirect() or header('Location: ...')wp_redirect($_GET['url']) without domain validationURL Validation (Shortlinks-Specific):
esc_url(), esc_url_raw(), or filter_var($url, FILTER_VALIDATE_URL) on savejavascript: or data: URI scheme blocked?esc_url()?Click Tracking & Analytics (Shortlinks-Specific):
class-table-logs.php or TINYPRESS_TABLE_REPORTS$wpdb->prepare()?Link Permissions (Shortlinks-Specific):
sanitize_text_field, sanitize_email, absint, etc.)esc_html, esc_attr, esc_url, wp_kses, etc.)$wpdb->prepare() is used for all dynamic SQL queriescurrent_user_can) before privileged operationspermission_callback implementationswp_remote_* functions vs. curlScore Guidelines:
Grade each finding: CRITICAL / HIGH / MEDIUM / LOW with file:line references
Analyze:
find . -name "*.php" -not -path "*/vendor/*" -not -path "*/tests/*" -exec wc -l {} \;Scoring:
Identify:
global $ usage with Grep$wpdb callsTODO|FIXME|HACK|XXX comments (exclude vendor/tests)Scoring:
Check:
Scoring:
Calculate Code Quality Score: (Architecture + Maintainability + Documentation) ÷ 3
Check composer.json files for:
Key library dependencies to verify:
publishpress/instance-protection — instance conflict preventionpublishpress/wordpress-reviews — review prompt controllerlib/vendor/ — all lib dependencies managed separately via lib/composer.jsonAnalyze:
Shortlinks-Specific Performance Checks:
class-redirection.php: Check if early exit (before WordPress fully boots) is used for performanceclass-autolist.php): Check for N+1 patterns when scanning post content for link injectionRun PHPMetrics (after manual analysis):
phpmetrics --report-html=metrics --exclude=vendor,lib/vendor,tests,dist,dev-workspace .
Extract these metrics from the report:
Categorize all findings into improvement tiers:
Use these thresholds to guide improvement tier assignment:
Generate TWO types of outputs:
Create a file named AUDIT_REPORT.md in the plugin root with this exact structure:
# [PLUGIN_NAME] Security & Code Quality Audit
## SPREADSHEET DATA (Copy and paste into spreadsheet tab)
**IMPORTANT**: Use actual TAB characters between columns, not spaces. Format for direct paste into spreadsheet.
Metric Score/Value Notes Security Score [X.X] [Brief: Main security findings, max 2 sentences] Architecture & Design [X.X] [Brief: Code structure assessment, max 2 sentences] Code Maintainability [X.X] [Brief: Readability & maintenance, max 2 sentences] Documentation [X.X] [Brief: Docs quality, max 2 sentences] Code Quality Score [X.X] [Auto-calculated: (Architecture + Maintainability + Documentation) ÷ 3] Violations [X] [From phpmetrics report] Lines of Code [X] [From phpmetrics report] Classes [X] [From phpmetrics report] Avg Cyclomatic Complexity [X.X] [From phpmetrics report] Avg Bugs by Class [X.X] [From phpmetrics report] Overall Health [HEALTHY/NEEDS WORK/AT RISK] [One-line rationale based on scores]
**Example of properly formatted data:**
Metric Score/Value Notes Security Score 4.2 Minor CSRF issues in admin forms. No critical vulnerabilities found. Architecture & Design 3.8 Generally well-structured MVC pattern. Some tight coupling in admin module. Code Maintainability 3.5 Readable code with consistent naming. Large god classes need refactoring. Documentation 2.8 Basic PHPDoc present. Missing inline comments in complex logic sections. Code Quality Score 3.4 Average of Architecture (3.8), Maintainability (3.5), and Documentation (2.8). Violations 23 Moderate code violations, mainly complexity warnings in core classes. Lines of Code 15420 Reasonable size for plugin functionality. Well-distributed across modules. Classes 87 Good separation of concerns. Some classes could be further decomposed. Avg Cyclomatic Complexity 5.2 Acceptable complexity. Few methods exceed threshold of 10. Avg Bugs by Class 0.8 Low predicted bug count. Indicates stable codebase with good practices. Overall Health NEEDS WORK Security is solid but Code Quality 3.4 needs targeted refactoring.
## 1. Security Assessment (Brief)
**Score: X.X/5.0**
🔴 **Critical Issues:**
- [Issue description] (file:line)
🟡 **Concerns:**
- [Issue description] (file:line)
🟢 **Strengths:**
- [Positive finding]
## 2. Code Quality Breakdown
**Overall: X.X/5.0**
| Sub-Metric | Score | Key Finding |
|------------|-------|-------------|
| Architecture & Design | X.X/5.0 | [One-line summary] |
| Code Maintainability | X.X/5.0 | [One-line summary] |
| Documentation | X.X/5.0 | [One-line summary] |
**Major Issues:**
- God classes: [List files >1000 lines if any]
- Global variables: [Count]
- TODO/FIXME comments: [Count]
- Large functions: [Notable examples >100 lines]
## 3. Dependencies
**Outdated/At-Risk Packages:** [List packages needing updates]
**Immediate Updates Required:** [What needs updating and why]
**PHP Version:** [Current requirement]
**WordPress Version:** [Current requirement]
## 4. Improvement Roadmap
### P1 — Fix Now (Security/Stability Blockers)
1. [Issue] - [Brief description and impact]
2. [Issue] - [Brief description and impact]
### P2 — Short-Term (1-4 Weeks)
1. [Issue] - [Brief description and impact]
2. [Issue] - [Brief description and impact]
### P3 — Medium-Term (1-3 Months)
1. [Issue] - [Brief description and impact]
2. [Issue] - [Brief description and impact]
### P4 — Long-Term / Ongoing
1. [Issue] - [Brief description]
2. [Issue] - [Brief description]
## 5. Overall Health: [HEALTHY/NEEDS WORK/AT RISK]
**Summary:** [2-3 sentence assessment of current state and improvement direction]
**Top 3 Priorities:**
- [Priority 1 with brief rationale]
- [Priority 2 with brief rationale]
- [Priority 3 with brief rationale]
**Answer:** Can a new developer onboard and safely contribute to this codebase? [Yes/Partially/No with brief explanation]
For EACH security vulnerability found, create a separate markdown file in the /security-audit/ directory.
Use this format: [plugin-name]-[###]-[SEVERITY]-[short-description].md
Examples:
myplugin-001-CRITICAL-sql-injection-custom-query.mdmyplugin-002-HIGH-xss-unescaped-output.mdmyplugin-003-MEDIUM-csrf-missing-nonce.mdRules:
Each security advisory file must contain:
## Security Advisory
### Summary
[One-line description of the vulnerability]
### Severity
[Critical / High / Medium / Low]
### CVSS Score
[Calculate CVSS 3.1 score, e.g., 8.8 (High)]
### CWE
[CWE ID and name, e.g., CWE-89: SQL Injection]
### Affected Versions
[Version range or "all versions" based on code analysis]
### Vulnerability Details
**Type:** [Vulnerability type]
**Location:** [File path and line number(s)]
**Attack Vector:** [Network/Local]
**User Interaction:** [Required/None]
**Privileges Required:** [None/Low/High]
### Description
[Detailed technical description of the vulnerability, explaining:
- What the vulnerable code does
- Why it's vulnerable
- What an attacker could achieve]
### Proof of Concept
[Provide specific steps or example payloads to demonstrate the vulnerability]
### Vulnerable Code
```php
[Exact code snippet showing the vulnerable code with file path and line numbers]
[Specific code fix with corrected code example]
[Fixed code snippet]
## Quality Assurance Checklist
### Accuracy Requirements
1. ✅ All numeric scores use exactly one decimal place (e.g., 3.7, not 3 or 3.70)
2. ✅ Code Quality Score is calculated: (Architecture + Maintainability + Documentation) ÷ 3
3. ✅ Spreadsheet data uses actual TAB characters (not spaces) between columns
4. ✅ All file:line references are accurate and verifiable
5. ✅ Security vulnerabilities are exploitable, not just theoretical
6. ✅ Code path to vulnerability is reachable by users
7. ✅ WordPress core sanitization doesn't already prevent exploitation
8. ✅ CVSS scores accurately reflect impact
9. ✅ Improvement tier assignments (P1–P4) accurately reflect priority and impact
10. ✅ Overall Health classification follows the improvement priority logic
### False Positive Avoidance
- Check if data is sanitized before the vulnerable function
- Verify capability checks aren't performed earlier in the call stack
- Confirm nonces aren't verified in parent functions
- Check for output escaping before assuming XSS
- Trace data flow through multiple files if necessary
### Reporting Standards
- Be objective and concise: 1-2 sentences max in spreadsheet Notes column
- Provide code snippets as evidence with file:line references
- Brief descriptions in main report, detailed in individual GHSA files
- Frame every finding with its improvement impact: "Fixing this will allow..."
- Answer the key question: "Can a new developer safely contribute to this codebase?"
## Execution Workflow
Follow this sequence for comprehensive audit:
1. **Start with searches** (use Grep tool):
- SQL injection patterns
- XSS patterns
- CSRF patterns
- Open redirect patterns (`wp_redirect`, `header('Location`)
- URL validation patterns (`esc_url`, `filter_var`, `FILTER_VALIDATE_URL`)
- Dangerous functions
- TODO/FIXME comments
- Global variable usage
2. **Analyze architecture** (use Read/Glob tools):
- Find large files (>1000 lines)
- Identify god classes
- Check dependency files (`composer.json`, `lib/composer.json`)
- Review main plugin structure — key files: `tinypress.php`, `includes-core/ShortlinksCoreAdmin.php`, `includes/classes/class-redirection.php`, `includes/classes/class-functions.php`, `includes/classes/class-table-logs.php`
3. **Run PHPMetrics** (use Shell tool):
```bash
phpmetrics --report-html=metrics --exclude=vendor,lib/vendor,tests,dist,dev-workspace .
Calculate scores:
Build improvement roadmap:
Apply overall health classification:
Generate outputs: