From 6be1a6cfc879b820d9a3e8c86c079c6c341ba9e6 Mon Sep 17 00:00:00 2001 From: Monu Lakshkar Date: Mon, 9 Oct 2023 13:33:08 +0530 Subject: [PATCH] Removed use of NewField --- .../BasicRequestProducer_Instrumentation.java | 9 ++++----- .../httpclient50/HttpAsyncClient_Instrumentation.java | 10 +++------- .../instrumentation/httpclient50/SecurityHelper.java | 1 + 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/BasicRequestProducer_Instrumentation.java b/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/BasicRequestProducer_Instrumentation.java index 68080c342..2803b7cf1 100644 --- a/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/BasicRequestProducer_Instrumentation.java +++ b/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/BasicRequestProducer_Instrumentation.java @@ -7,19 +7,18 @@ package com.newrelic.agent.security.instrumentation.httpclient50; +import com.newrelic.api.agent.security.NewRelicSecurity; import com.newrelic.api.agent.weaver.MatchType; -import com.newrelic.api.agent.weaver.NewField; import com.newrelic.api.agent.weaver.Weave; import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.nio.AsyncEntityProducer; +import static com.newrelic.agent.security.instrumentation.httpclient50.SecurityHelper.APACHE5_ASYNC_REQUEST_PRODUCER; + @Weave(type=MatchType.BaseClass, originalName = "org.apache.hc.core5.http.nio.support.BasicRequestProducer") public class BasicRequestProducer_Instrumentation { - @NewField - public final HttpRequest nrRequest; - public BasicRequestProducer_Instrumentation(final HttpRequest request, final AsyncEntityProducer dataProducer) { - nrRequest = request; + NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute(APACHE5_ASYNC_REQUEST_PRODUCER+this.hashCode(), request); } } diff --git a/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/HttpAsyncClient_Instrumentation.java b/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/HttpAsyncClient_Instrumentation.java index 40258c8dd..26cc6fd5a 100644 --- a/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/HttpAsyncClient_Instrumentation.java +++ b/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/HttpAsyncClient_Instrumentation.java @@ -9,13 +9,7 @@ import com.newrelic.api.agent.security.NewRelicSecurity; import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; -import com.newrelic.api.agent.security.instrumentation.helpers.R2dbcHelper; -import com.newrelic.api.agent.security.instrumentation.helpers.ServletHelper; import com.newrelic.api.agent.security.schema.AbstractOperation; -import com.newrelic.api.agent.security.schema.SecurityMetaData; -import com.newrelic.api.agent.security.schema.exceptions.NewRelicSecurityException; -import com.newrelic.api.agent.security.schema.operation.SSRFOperation; -import com.newrelic.api.agent.security.utils.SSRFUtils; import com.newrelic.api.agent.weaver.MatchType; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; @@ -30,6 +24,8 @@ import java.net.URISyntaxException; import java.util.concurrent.Future; +import static com.newrelic.agent.security.instrumentation.httpclient50.SecurityHelper.APACHE5_ASYNC_REQUEST_PRODUCER; + @Weave(type = MatchType.Interface, originalName = "org.apache.hc.client5.http.async.HttpAsyncClient") public class HttpAsyncClient_Instrumentation { @@ -39,7 +35,7 @@ public Future execute( HandlerFactory pushHandlerFactory, HttpContext context, FutureCallback callback) { - HttpRequest request = ((BasicRequestProducer_Instrumentation)requestProducer).nrRequest; + HttpRequest request = NewRelicSecurity.getAgent().getSecurityMetaData().getCustomAttribute(APACHE5_ASYNC_REQUEST_PRODUCER+requestProducer.hashCode(), HttpRequest.class);; boolean isLockAcquired = acquireLockIfPossible(); AbstractOperation operation = null; diff --git a/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/SecurityHelper.java b/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/SecurityHelper.java index 06bf8a86f..7b643cc53 100644 --- a/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/SecurityHelper.java +++ b/instrumentation-security/httpclient-5.0/src/main/java/com/newrelic/agent/security/instrumentation/httpclient50/SecurityHelper.java @@ -15,6 +15,7 @@ public class SecurityHelper { public static final String METHOD_NAME_EXECUTE = "execute"; public static final String NR_SEC_CUSTOM_ATTRIB_NAME = "SSRF_OPERATION_LOCK_APACHE5-"; + public static final String APACHE5_ASYNC_REQUEST_PRODUCER = "APACHE5_ASYNC_REQUEST_PRODUCER_"; public static void registerExitOperation(boolean isProcessingAllowed, AbstractOperation operation) { try {