Harden router.php against path traversal and non-PHP execution - #102
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe router now resolves canonical paths, restricts direct serving to the document root, falls back to WordPress for external paths, and executes only PHP files. Feature coverage verifies encoded traversal protection and static handling of non-PHP files. ChangesServer routing security
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens the wp server router to reduce exposure to path traversal (including via resolved real paths) and to ensure only .php files are executed, while adding Behat coverage for these security behaviors.
Changes:
- Resolve real paths and enforce that requested targets stay within
DOCUMENT_ROOTbefore routing/executing. - Restrict execution to files with a
.phpextension (case-insensitive), returning static handling for non-PHP files. - Add Behat scenarios validating traversal attempts don’t escape the docroot and that non-PHP extensions aren’t executed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| router.php | Adds realpath-based docroot containment checks and enforces PHP-only execution in the router. |
| features/server.feature | Adds Behat scenarios to cover traversal blocking and non-PHP non-execution behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@features/server.feature`:
- Around line 102-111: Remove the contradictory STDOUT assertion in the curl
scenario: retain the check that the response contains the literal PHP source and
delete the subsequent assertion requiring STDOUT not to contain FAIL_EXECUTION.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: edf407d5-96c6-4d52-afe6-1b50e9c52a91
📒 Files selected for processing (2)
features/server.featurerouter.php
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary by CodeRabbit