diff --git a/src/main/java/burp/RequestSender.java b/src/main/java/burp/RequestSender.java index 382b534..34f7059 100644 --- a/src/main/java/burp/RequestSender.java +++ b/src/main/java/burp/RequestSender.java @@ -392,7 +392,7 @@ protected static Map retrieveResponseDetails(IHttpService servic private static Map retrieveResponseDetails(IHttpService service, byte[] request, int retryCount) { try { String hostKey = service.getHost(); - String cacheKey = service.toString() + Arrays.hashCode(request); + String cacheKey = buildServiceCacheKey(service, request); // Check circuit breaker if (isCircuitOpen(hostKey)) { @@ -459,6 +459,28 @@ private static Map retrieveResponseDetails(IHttpService service, return null; } } + + /** + * Builds a cache key that normalizes the service attributes (protocol, host, port) + * and appends the request hash. This ensures equivalent services share cache + * entries while keeping cache growth in check. + */ + private static String buildServiceCacheKey(IHttpService service, byte[] request) { + String protocol = service.getProtocol() != null + ? service.getProtocol().toLowerCase(Locale.ROOT) + : "http"; + String host = service.getHost() != null + ? service.getHost().toLowerCase(Locale.ROOT) + : ""; + int port = service.getPort(); + + if (port <= 0) { + port = "https".equals(protocol) ? 443 : 80; + } + + String serviceKey = protocol + "://" + host + ":" + port; + return serviceKey + "|" + Arrays.hashCode(request); + } private static boolean isCircuitOpen(String hostKey) { AtomicInteger failures = FAILURE_COUNTS.computeIfAbsent(hostKey, k -> new AtomicInteger(0));