fix(http): harden http command against SSRF and DoS#36
Conversation
Summary by BeetleThis PR hardens the HTTP command against Server-Side Request Forgery (SSRF) and Denial of Service (DoS) attacks by implementing comprehensive security validations and resource limits. The changes add robust IP filtering, DNS resolution validation, redirect handling, and response size limits to prevent attackers from using the bot to access internal services or exhaust resources. 📁 File Changes Summary (Consolidated across all commits):
Total Changes: 1 file changed, +307 additions, -51 deletions 🎯 Key Changes:
📊 Impact Assessment:
⚙️ SettingsSeverity Threshold: 📖 User Guide
|
| const records = await dns.lookup(host, { all: true, verbatim: true }); | ||
| if (!records.length || records.some((r) => isBlockedIp(r.address))) { | ||
| throw new Error("Requests to private or local addresses are not allowed."); | ||
| } |
There was a problem hiding this comment.
The DNS lookup validation doesn't account for DNS rebinding attacks that occur between the validation and the actual request. While the code implements IP pinning via the lookup option (line 323), there's a potential race condition window if the DNS record changes between the dns.lookup() call (line 173) and when the pinned lookup is actually used.
Additionally, the dns.lookup() call uses verbatim: true which is good, but the code should verify that all resolved addresses are safe, not just check if any are blocked. The current logic at line 174 (records.some((r) => isBlockedIp(r.address))) correctly rejects if ANY record is blocked, which is the right approach.
However, there's a subtle issue: if DNS returns multiple records and one is blocked, the entire request is rejected. But if all records are safe, only the first one is used (line 178). This is correct behavior, but the code should document this clearly.
Actually, upon further review: The implementation is correct. The IP pinning at line 323 ensures that even if DNS changes between validation and request, the connection uses the validated IP. This is the proper TOCTOU mitigation.
No genuine issue here - the implementation is sound.
📍 This suggestion applies to lines 173-176
Confidence: 4/5
|
Note Linting checks passed successfully 🎉 All formatting and code quality checks are clean. You're good to merge 🚀 |
refined version of #35