Skip to content

Feature/add pattern library manager#38

Merged
noelsaw1 merged 3 commits intodevelopmentfrom
feature/add-pattern-library-manager
Jan 7, 2026
Merged

Feature/add pattern library manager#38
noelsaw1 merged 3 commits intodevelopmentfrom
feature/add-pattern-library-manager

Conversation

@noelsaw1
Copy link
Contributor

@noelsaw1 noelsaw1 commented Jan 7, 2026

Pattern Library Manager - Automated pattern registry generation and marketing stats
False Positive Reduction - Mitigation Detection
Memory / OOM Crash Prevention Checks

@noelsaw1 noelsaw1 merged commit e68a82a into development Jan 7, 2026
1 of 2 checks passed
noelsaw1 added a commit that referenced this pull request Jan 9, 2026
…elds

Add new pattern wp-json-html-escape to detect HTML escaping functions
(esc_url, esc_attr, esc_html) used in JSON response fields with URL-like
names, which causes double-encoding issues breaking redirects in JavaScript.

Pattern Details:
- ID: wp-json-html-escape
- Category: Reliability / Correctness
- Severity: MEDIUM (heuristic - needs review)
- Type: PHP
- Detection: Two-step approach
  1. Find JSON response functions (wp_send_json_*, WP_REST_Response, wp_json_encode)
  2. Check for esc_* in URL-like keys (url, redirect, link, href, etc.)

Problem:
Using esc_url() in JSON responses encodes & → & which breaks
JavaScript redirects. This is a very common WordPress development mistake
where developers over-escape without understanding context.

Example:
❌ Bad:  wp_send_json_success(['redirect_url' => esc_url($url)]);
✅ Good: wp_send_json_success(['redirect_url' => $url]);

Why Heuristic:
- Sometimes developers intentionally send HTML fragments in JSON
- Escaping may be correct for non-URL fields (e.g., 'message')
- Context matters - pattern flags suspicious cases for review

Changes:
- Added pattern definition: dist/patterns/wp-json-html-escape.json
- Integrated detection logic: dist/bin/check-performance.sh (lines 4778-4844)
- Created test fixture: dist/bin/fixtures/wp-json-html-escape.php (11 test cases)
- Updated CHANGELOG.md with v1.1.2 release notes
- Bumped script version to 1.1.2
- Updated pattern library: 29 patterns total (18 PHP, 6 Headless, 4 Node.js, 1 JS)
- Heuristic patterns: 10 total (was 9)

Test Results:
✅ Detected 11/11 expected cases (8 true positives + 3 edge cases)
✅ Pattern library manager updated successfully
✅ Main scanner integration verified

Impact:
Helps prevent hard-to-debug redirect failures and double-encoding issues
in AJAX/REST API responses. Educational value for teaching context-aware
escaping in WordPress development.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant