Count 404 requests with foreign extensions as attack wave scans#292
Count 404 requests with foreign extensions as attack wave scans#292bitterpanda63 wants to merge 1 commit into
Conversation
Ports AikidoSec/firewall-node#1041 to Ruby. Requests to foreign-platform extensions (php, java, jsp, etc.) are only counted as scan hits when the response status is 404 — a 200 response may indicate the Ruby app is proxying to a PHP/Java backend rather than serving the file itself. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
||
| return true if SUSPICIOUS_FILE_EXTENSIONS.include?(file_extension) | ||
|
|
||
| return true if FOREIGN_EXTENSIONS.include?(file_extension) && status_code == 404 |
There was a problem hiding this comment.
Avoid a chained condition in the nested file_name branch. Split FOREIGN_EXTENSIONS check and status_code check into clearer guard/early-return steps to reduce nesting and improve readability.
| return true if FOREIGN_EXTENSIONS.include?(file_extension) && status_code == 404 | |
| if FOREIGN_EXTENSIONS.include?(file_extension) | |
| return true if status_code == 404 | |
| end |
Details
✨ AI Reasoning
The change inserted a new return that combines two checks with && inside the nested file_name branch, increasing branching complexity in a block that already contains multiple return-true checks. Separating these into explicit guard checks (e.g., check file_extension membership first, then check status_code) or inverting the condition into an early-return/guard would flatten nesting and improve readability and maintainability.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
php,php3,php4,php5,phtml,java,jsp,jspx) are only counted as scan hits when the HTTP response status is 404Changes
lib/aikido/zen/attack_wave/helpers.rb: AddedFOREIGN_EXTENSIONSset; updatedsuspicious_path?andweb_scanner?to accept and usestatus_codelib/aikido/zen/attack_wave.rb: UpdatedDetector#attack_wave?to accept and forwardstatus_codelib/aikido/zen/middleware/attack_wave_protector.rb: Extractsstatus_codefrom the Rack response and passes it throughprotect→attack_wave?→ detectortest/aikido/zen/attack_wave_test.rb: AddedHelpersTestcovering the 404-only and always-suspicious behavioursTest plan
suspicious_path?("/admin.php", 404)→ truesuspicious_path?("/admin.php", 200)→ falsesuspicious_path?("/app.jsp", 404)→ true.sql,.db,.bak) still return true regardless of statuswp-config.php) still return true regardless of statusbundle exec rake testand confirm no regressions🤖 Generated with Claude Code
Summary by Aikido
⚡ Enhancements
More info