From 54e7380634a8880774d544e1c6789853180ce7c6 Mon Sep 17 00:00:00 2001 From: lovesh-ap Date: Fri, 3 May 2024 10:23:05 +0530 Subject: [PATCH] add checks to register media type wrt content-type reflected in CC --- .../security/instrumentator/httpclient/RequestUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/httpclient/RequestUtils.java b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/httpclient/RequestUtils.java index bb66bdbf0..c390f088e 100644 --- a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/httpclient/RequestUtils.java +++ b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/httpclient/RequestUtils.java @@ -18,6 +18,7 @@ public class RequestUtils { private static final FileLoggerThreadPool logger = FileLoggerThreadPool.getInstance(); public static final String ERROR_IN_FUZZ_REQUEST_GENERATION = "Error in fuzz request generation {}"; + public static final String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded"; public static Request generateK2Request(FuzzRequestBean httpRequest, String endpoint) { try { @@ -27,7 +28,7 @@ public static Request generateK2Request(FuzzRequestBean httpRequest, String endp RequestBody requestBody = null; if (StringUtils.isNotBlank(httpRequest.getContentType())) { - if (httpRequest.getParameterMap() != null && !httpRequest.getParameterMap().isEmpty()) { + if (httpRequest.getParameterMap() != null && !httpRequest.getParameterMap().isEmpty() && StringUtils.startsWith(httpRequest.getContentType(), APPLICATION_X_WWW_FORM_URLENCODED)) { FormBody.Builder builder = new FormBody.Builder(); for (Entry param : httpRequest.getParameterMap().entrySet()) { for (int i = 0; i < param.getValue().length; i++) { @@ -35,11 +36,12 @@ public static Request generateK2Request(FuzzRequestBean httpRequest, String endp } } requestBody = builder.build(); - } else { + } else if( StringUtils.isNotBlank(httpRequest.getBody().toString())) { requestBody = RequestBody.create(httpRequest.getBody().toString(), MediaType.parse(httpRequest.getContentType())); } - } else if (StringUtils.equalsIgnoreCase(httpRequest.getMethod(), "POST")) { + } + if (requestBody == null && HttpMethod.permitsRequestBody(httpRequest.getMethod())) { requestBody = RequestBody.create(httpRequest.getBody().toString(), null); }