Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,26 @@ jobs:
validate-test-fixtures:
name: Validate Test Fixtures
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y jq

- name: Environment snapshot
run: |
echo "=== CI Environment Diagnostic ==="
echo "OS: $(uname -a)"
echo "Shell: $SHELL ($BASH_VERSION)"
echo "jq: $(command -v jq && jq --version || echo 'NOT INSTALLED')"
echo "perl: $(perl -v | head -2)"
echo "grep: $(grep --version | head -1)"
echo "================================="

- name: Make scripts executable
run: |
chmod +x ./dist/bin/check-performance.sh
Expand All @@ -136,7 +151,7 @@ jobs:
- name: Run automated fixture tests
run: |
echo "Running automated fixture validation..."
./dist/tests/run-fixture-tests.sh
cd dist && ./tests/run-fixture-tests.sh

- name: Test antipatterns detection (legacy check)
run: |
Expand Down
80 changes: 0 additions & 80 deletions .github/workflows/example-caller.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ dist/tests/irl/*
!dist/tests/irl/_AI_AUDIT_INSTRUCTIONS.md
!dist/tests/irl/.gitkeep

# Auto-generated pattern library files (regenerated on every scan)
# These files are auto-generated by pattern-library-manager.sh
# and change with every scan due to timestamp updates
dist/PATTERN-LIBRARY.json
dist/PATTERN-LIBRARY.md

# ============================================
# DEVELOPMENT & TESTING
# ============================================
Expand Down
172 changes: 172 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,169 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.2.4] - 2026-01-12

### Added
- **Phase 1 Improvements: Enhanced False Positive Filtering**
- **Improved `is_line_in_comment()` function** (now in shared library)
- Added string literal detection to ignore `/* */` inside quotes
- Increased backscan window from 50 to 100 lines (catches larger docblocks)
- Added inline comment detection for same-line `/* comment */` patterns
- Filters out string content before counting comment markers
- **Improved `is_html_or_rest_config()` function** (now in shared library)
- Tightened HTML form pattern: `<form[^>]*\\bmethod\\s*=\\s*['\"]POST['\"]`
- Tightened REST route pattern: `['\"]methods['\"][[:space:]]*=>.*POST`
- Added case-insensitive matching (detects POST, post, Post, etc.)
- Requires quoted 'methods' key to avoid matching `$methods` variables
- **Created shared library**: `dist/bin/lib/false-positive-filters.sh`
- Centralized location for all false positive detection functions
- Versioned library (v1.0.0) for future scanner scripts
- Documented API and known limitations
- **Created verification script**: `dist/tests/verify-phase1-improvements.sh`
- Reproducible before/after metrics
- Automated testing against Health Check plugin
- Documents methodology for future audits

### Changed
- **Significantly Improved Detection Accuracy**
- Health Check plugin scan results:
- **Baseline (before Phase 1)**: 75 total findings
- **After Phase 1 (v1.2.3)**: 74 total findings (3 PHPDoc false positives eliminated)
- **After Phase 1 Improvements (v1.2.4)**: **67 total findings**
- **Overall improvement**: **10.6% reduction** in false positives (8 findings eliminated)
- HTTP timeout findings remain at 3 (all actual code, no false positives)
- Superglobal findings: 7 direct manipulation, 43 unsanitized reads

### Fixed
- **String Literal False Positives**: No longer counts `echo "/* not a comment */"` as comment
- **Large Docblock Detection**: Now catches docblocks >50 lines (up to 100 lines)
- **Inline Comment Detection**: Properly detects `code(); /* comment */ more_code();`
- **HTML Form Over-matching**: No longer matches strings containing "method" and "POST"
- **REST Config Over-matching**: No longer matches `$methods` variables
- **Case Sensitivity**: Now detects lowercase `post` and mixed-case `Post` in forms

### Technical Details
- **Code Organization**: Moved 140+ lines of helper functions to shared library
- **Test Coverage**: Enhanced test fixtures with 12+ edge cases
- **Verification**: Created automated script to verify improvements
- **Documentation**: Updated with verified metrics and methodology

## [1.2.3] - 2026-01-12

### Added
- **Phase 1: False Positive Reduction** - Comment and Configuration Filtering
- Added `is_line_in_comment()` helper function to detect PHPDoc blocks and inline comments
- Checks for `//`, `/*`, `*/`, `*` comment markers
- Looks backward 50 lines to detect multi-line comment blocks
- Counts `/*` and `*/` to determine if inside a block comment
- Added `is_html_or_rest_config()` helper function to detect HTML forms and REST route configurations
- Filters out `<form method="POST">` declarations
- Filters out `'methods' => 'POST'` REST route configs
- Prevents false positives from configuration code
- Integrated filters into three pattern checks:
- HTTP timeout check (`http-no-timeout`)
- Superglobal manipulation check (`spo-002-superglobals`)
- Unsanitized superglobal read check (`unsanitized-superglobal-read`)
- Created test fixtures for regression testing:
- `dist/tests/fixtures/phase1-comment-filtering.php` - Tests comment detection
- `dist/tests/fixtures/phase1-html-rest-filtering.php` - Tests HTML/REST filtering

### Changed
- **Improved Detection Accuracy** - Reduced false positives in real-world scans
- Health Check plugin scan: Reduced HTTP timeout findings from 6 to 3 (eliminated 3 PHPDoc false positives)
- Overall finding reduction: 75 → 74 findings (1.3% improvement)
- HTTP timeout false positive reduction: 50% improvement

### Technical Details
- **Implementation:** Added 70 lines of helper functions to `dist/bin/check-performance.sh`
- **Testing:** Created 118 lines of test fixtures to prevent regression
- **Impact:** Phase 1 of 3-phase false positive reduction plan (see `PROJECT/2-WORKING/AUDIT-COPILOT-WP-HEALTHCHECK.md`)

## [1.2.2] - 2026-01-10

### Fixed
- **Critical Bug** - Fixed pattern detection failure with absolute paths
- **Root Cause:** Three pattern checks had unquoted `$PATHS` variables in grep commands
- **Impact:** When scanning files with absolute paths containing spaces (e.g., `/Users/name/Documents/GH Repos/project/file.php`), bash would split the path into multiple arguments, breaking grep and causing false negatives
- **Affected Patterns:**
- `file_get_contents()` with URLs (security risk) - now detects correctly
- HTTP requests without timeout (performance/reliability) - now detects correctly
- Unvalidated cron intervals (security/stability) - now detects correctly
- **Fix:** Added quotes around `$PATHS` in 4 locations (lines 4164, 4940, 4945, 5009)
- **Testing:** All three patterns now detect issues consistently with both relative and absolute paths
- **User Impact:** HIGH - Fixes false negatives in CI/CD pipelines, automated tools, and template-based scans that use absolute paths
- **Files Modified:**
- `dist/bin/check-performance.sh` - Added quotes to `$PATHS` in grep commands
- `dist/tests/expected/fixture-expectations.json` - Updated expectations to require detection (not accept false negatives)

### Changed
- **Test Expectations** - Updated fixture expectations to reflect bug fix
- `file-get-contents-url.php`: Now expects 1 error (was 0)
- `http-no-timeout.php`: Now expects 1 warning (was 0)
- `cron-interval-validation.php`: Now expects 1 error (was 0)
- Test suite version bumped to 2.1.0

## [1.2.1] - 2026-01-10

### Added
- **Test Suite V2** - Complete rewrite of fixture test framework
- New modular architecture with separate libraries for utils, precheck, runner, and reporter
- Improved JSON parsing with fallback extraction for polluted stdout
- Better error reporting with detailed failure messages
- Support for both relative and absolute file paths
- **Test Results:** All 8 fixture tests now pass consistently
- **Files Added:**
- `dist/tests/run-fixture-tests-v2.sh` - Main test runner
- `dist/tests/lib/utils.sh` - Logging and utility functions
- `dist/tests/lib/precheck.sh` - Environment validation
- `dist/tests/lib/runner.sh` - Test execution engine
- `dist/tests/lib/reporter.sh` - Results formatting

### Fixed
- **Test Suite** - Fixed fixture test suite to work with absolute paths
- Updated expected error/warning counts to match scanner behavior with absolute paths
- Fixed JSON extraction to handle pattern library manager output pollution
- Removed bash -c wrapper to avoid shell quoting issues with paths containing spaces
- **Updated Counts (with absolute paths):**
- `antipatterns.php`: 9 errors, 2 warnings (was 4 warnings with relative paths)
- `ajax-antipatterns.php`: 1 error, 0 warnings (was 1 warning)
- `file-get-contents-url.php`: 0 errors, 0 warnings (was 1 error) - **FIXED in v1.2.2**
- `http-no-timeout.php`: 0 errors, 0 warnings (was 1 warning) - **FIXED in v1.2.2**
- `cron-interval-validation.php`: 0 errors, 0 warnings (was 1 error) - **FIXED in v1.2.2**
- **Impact:** Test suite now accurately validates pattern detection with absolute paths

### Known Issues
- **Scanner Bug** - Scanner produces different results with relative vs absolute paths - **FIXED in v1.2.2**
- ~~Some patterns (file_get_contents, http timeout, cron validation) not detected with absolute paths~~
- ~~Test suite updated to use absolute paths (matches real-world usage)~~
- ~~Scanner fix needed in future release~~
- **TODO:** Re-enable after fixing Docker-based testing and identifying CI hang cause
- **Workaround:** Use local testing (`./tests/run-fixture-tests.sh`) or Docker (`./tests/run-tests-docker.sh`)
- **Impact:** CI now only runs performance checks, not fixture validation

### Added
- **Test Suite** - Comprehensive debugging and validation infrastructure
- **Dependency checks**: Fail-fast validation for `jq` and `perl` with installation instructions
- **Trace mode**: `./tests/run-fixture-tests.sh --trace` for detailed debugging output
- **JSON parsing helper**: `parse_json_output()` function with explicit error handling
- **Numeric validation**: Validates parsed error/warning counts are numeric before comparison
- **Environment snapshot**: Shows OS, shell, tool versions at test start (useful for CI debugging)
- **Detailed tracing**: Logs exit codes, file sizes, parsing method, and intermediate values
- **Explicit format flag**: Tests now use `--format json` explicitly (protects against default changes)
- **Removed dead code**: Eliminated unreachable text parsing fallback (JSON-only architecture)
- **CI emulator**: New `./tests/run-tests-ci-mode.sh` script to test in CI-like environment locally
- Removes TTY access (emulates GitHub Actions)
- Sets CI environment variables (`CI=true`, `GITHUB_ACTIONS=true`)
- Uses `setsid` (Linux) or `script` (macOS) to detach from terminal
- Validates dependencies before running tests
- Supports `--trace` flag for debugging
- **Docker testing**: New `./tests/run-tests-docker.sh` for true Ubuntu CI environment (last resort)
- Runs tests in Ubuntu 22.04 container (identical to GitHub Actions)
- Includes Dockerfile for reproducible CI environment
- Supports `--trace`, `--build`, and `--shell` flags
- Most accurate CI testing method available
- **Impact:** Silent failures now caught immediately with clear error messages; CI issues reproducible locally

### Changed
- **Documentation** - Enhanced `dist/TEMPLATES/README.md` with context and background
- Added "What Are Templates?" section explaining the concept and purpose
Expand All @@ -15,6 +178,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added location context at the top (`dist/TEMPLATES/` in your WP Code Check installation)
- **Impact:** New users can now understand templates immediately without reading the entire guide

- **Test Suite** - Incremented version to 1.0.81 (from 1.0.80)
- Reflects addition of debugging infrastructure and validation improvements

### Removed
- **GitHub Workflows** - Removed `.github/workflows/example-caller.yml` template file
- This was a documentation-only template file that never ran automatically
- Example usage is already documented in README and other documentation
- **Impact:** Cleaner workflows directory with only active files (`ci.yml` and `wp-performance.yml`)

## [1.2.0] - 2026-01-09

### Added
Expand Down
2 changes: 2 additions & 0 deletions PROJECT/1-INBOX/BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Notes:
- [ ] Are false positives still a problem?
- [ ] Is baseline suppression working well?
- [ ] Do users want AST-level accuracy?
- [ ] Short-Medium Term: MCP Server - Send tasks to agents for work
- [ ] Super Long term: Agnostic anamaoly detection and pattern library

Completed (so far):
- Centralized function/method scope detection in `dist/bin/check-performance.sh` and applied it across mitigation detectors.
Expand Down
Loading
Loading