From c9ae0422d3eb7b6cd35c329563d5c0d575a922ea Mon Sep 17 00:00:00 2001 From: atomiczsec <75549184+atomiczsec@users.noreply.github.com> Date: Sun, 16 Nov 2025 11:25:20 -0500 Subject: [PATCH] Normalize cache keys per service --- src/main/java/burp/RequestSender.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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));