Class RequestResponseDocBuilder

java.lang.Object
ai.attackframework.tools.burp.sinks.RequestResponseDocBuilder

public final class RequestResponseDocBuilder extends Object
Builds request and response sub-documents in the same shape as the traffic index, for use by both TrafficHttpHandler and SitemapIndexReporter.
  • Method Details

    • buildRequestDoc

      public static Map<String,Object> buildRequestDoc(burp.api.montoya.http.message.requests.HttpRequest request)
      Builds a request sub-document matching the traffic index request shape.

      Body bytes are always stored as full base64 in body.b64 for exact replay. When the payload is classified as textual, body.text contains the full decoded text.

      Parameters:
      request - the HTTP request (never null)
      Returns:
      map with method, path, headers, parameters, and body content fields.
    • buildBestEffortUrl

      public static String buildBestEffortUrl(burp.api.montoya.http.message.requests.HttpRequest request, burp.api.montoya.http.HttpService service, Map<String,Object> requestDoc, String logPrefix)
      Resolves the best-effort request URL for top-level traffic documents.

      When HttpRequest.url() throws for malformed or partially bound Repeater requests, this helper reconstructs a usable URL from HttpService plus the already-recovered request path so top-level fields stay aligned with the nested request document.

      Parameters:
      request - request whose direct URL accessor may throw
      service - HTTP service backing the request
      requestDoc - already-built request sub-document, usually from buildRequestDoc(HttpRequest)
      logPrefix - logger prefix without brackets, for example "RepeaterTabs"
      Returns:
      direct URL when available, otherwise a best-effort reconstructed URL or null
    • buildResponseDoc

      public static Map<String,Object> buildResponseDoc(burp.api.montoya.http.message.responses.HttpResponse response)
      Builds a response sub-document matching the traffic index response shape.

      Body bytes are always stored as full base64 in body.b64 for exact replay. When the payload is classified as textual, body.text contains the full decoded text. For HttpResponseReceived, response attributes such as visible_text are preserved as returned by Montoya.

      Parameters:
      response - the HTTP response (never null)
      Returns:
      map with status, headers, cookies, and body content fields.
    • safeRequestUrl

      public static String safeRequestUrl(burp.api.montoya.http.message.requests.HttpRequest request, String logPrefix)
      Returns HttpRequest.url() when available, or null when Montoya throws.

      Use this for lightweight call sites (for example scope filtering) that only need a safe URL lookup without the reconstruction cost of buildBestEffortUrl(burp.api.montoya.http.message.requests.HttpRequest, burp.api.montoya.http.HttpService, java.util.Map<java.lang.String, java.lang.Object>, java.lang.String). The logged context mirrors the reconstruction helper so failure reasons stay traceable across exports.

      Parameters:
      request - request whose direct URL accessor may throw
      logPrefix - logger prefix without brackets, for example "Sitemap"
      Returns:
      trimmed URL when available, otherwise null