-
Notifications
You must be signed in to change notification settings - Fork 5
Stop reporting DNS noise #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import dev.aikido.agent_api.vulnerabilities.ssrf.SSRFException; | ||
| import dev.aikido.agent_api.helpers.logging.LogManager; | ||
| import dev.aikido.agent_api.helpers.logging.Logger; | ||
| import dev.aikido.agent_api.vulnerabilities.ssrf.IsPrivateIP; | ||
| import dev.aikido.agent_api.vulnerabilities.ssrf.StoredSSRFDetector; | ||
| import dev.aikido.agent_api.vulnerabilities.ssrf.StoredSSRFException; | ||
|
|
||
|
|
@@ -27,6 +28,7 @@ public final class DNSRecordCollector { | |
| private DNSRecordCollector() {} | ||
| private static final Logger logger = LogManager.getLogger(DNSRecordCollector.class); | ||
| private static final String OPERATION_NAME = "java.net.InetAddress.getAllByName"; | ||
|
|
||
| public static void report(String hostname, InetAddress[] inetAddresses) { | ||
| try { | ||
| logger.trace("DNSRecordCollector called with %s & inet addresses: %s", hostname, List.of(inetAddresses)); | ||
|
|
@@ -37,12 +39,9 @@ public static void report(String hostname, InetAddress[] inetAddresses) { | |
| // Consume pending ports recorded by URLCollector for this hostname. | ||
| // Removing them here ensures each (hostname, port) pair is counted exactly once. | ||
| Set<Integer> ports = PendingHostnamesStore.getAndRemove(hostname); | ||
| if (!ports.isEmpty()) { | ||
| for (int port : ports) { | ||
| HostnamesStore.incrementHits(hostname, port); | ||
| } | ||
| } else { | ||
| // We still need to report a hit to the hostname for outbound domain blocking | ||
| // URLCollector already recorded known-port hits. This is the fallback for hostnames | ||
| // it never saw (JDBC, raw sockets, ...) - skip only private IP literals, infra noise. | ||
| if (ports.isEmpty() && !IsPrivateIP.isPrivateIp(hostname)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DNSRecordCollector.report's behavior now conditionally skips recording hostname hits for private IPs when ports are absent, increasing mixed responsibilities and making the method's purpose less clear; consider renaming or extracting the fallback hit-recording into a well-named function. Details✨ AI Reasoning 🔧 How do I fix it? Reply |
||
| HostnamesStore.incrementHits(hostname, 0); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import dev.aikido.agent_api.helpers.logging.LogManager; | ||
| import dev.aikido.agent_api.helpers.logging.Logger; | ||
| import dev.aikido.agent_api.storage.HostnamesStore; | ||
| import dev.aikido.agent_api.storage.PendingHostnamesStore; | ||
|
|
||
| import java.net.URL; | ||
|
|
@@ -18,9 +19,14 @@ public static void report(URL url) { | |
| return; // Non-HTTP(S) URL | ||
| } | ||
| logger.trace("Adding a new URL to the cache: %s", url); | ||
| int port = getPortFromURL(url); | ||
| // Store hostname+port in the pending store so DNSRecordCollector can pick it | ||
| // up during the DNS lookup that follows, for SSRF detection and outbound hostnames | ||
| PendingHostnamesStore.add(url.getHost(), getPortFromURL(url)); | ||
| // up during the DNS lookup that follows, for SSRF detection | ||
| PendingHostnamesStore.add(url.getHost(), port); | ||
| // Record the hit here, at the real call site, where the port is always known - | ||
| // instead of waiting for the DNS lookup, which can't distinguish this call from | ||
| // unrelated infra noise resolving the same hostname. | ||
| HostnamesStore.incrementHits(url.getHost(), port); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. URLCollector.report now both adds to PendingHostnamesStore and records HostnamesStore.incrementHits, mixing responsibilities and adding an unexpected side-effect; consider renaming or splitting into clearer methods. Details✨ AI Reasoning 🔧 How do I fix it? Reply |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OPERATION_NAME constant was added but the same string literal is still used in registerCall. Use OPERATION_NAME in registerCall to avoid duplicated literals and simplify maintenance.
Details
✨ AI Reasoning
A constant OPERATION_NAME was added and later used in SSRFDetector and StoredSSRFDetector calls, but the call to StatisticsStore.registerCall still uses the literal string "java.net.InetAddress.getAllByName". This duplicates the same string in two places and was introduced by the current diff (the added OPERATION_NAME constant at the top of the file). Using the constant in the registerCall call would be a simpler, less error-prone, and consistent approach. This change is purely readability/maintenance (no behavior change) and is fixable within this PR.
🔧 How do I fix it?
Rewrite the snippet in the simpler, behavior-equivalent form: return a boolean expression directly instead of
if cond return true else return false, avoid using lists when they are guaranteed to contain one element, etc.Reply
@AikidoSec feedback: [FEEDBACK]to get better review comments in the future.Reply
@AikidoSec ignore: [REASON]to ignore this issue.More info