|
4 | 4 | import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
|
5 | 5 | import com.newrelic.api.agent.security.schema.AbstractOperation;
|
6 | 6 | import com.newrelic.api.agent.security.schema.StringUtils;
|
| 7 | +import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; |
7 | 8 | import com.newrelic.api.agent.security.schema.exceptions.NewRelicSecurityException;
|
8 | 9 | import com.newrelic.api.agent.security.schema.operation.JavaReflectionOperation;
|
9 | 10 | import com.newrelic.api.agent.security.utils.logging.LogLevel;
|
@@ -45,21 +46,20 @@ private void registerExitOperation(AbstractOperation operation) {
|
45 | 46 |
|
46 | 47 | private AbstractOperation preprocessSecurityHook(Object obj, Class<?> declaringClass, Class<?>[] parameterTypes, String name, Object[] args) {
|
47 | 48 | try {
|
48 |
| - if (!NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty() && NewRelicSecurity.getAgent().getSecurityMetaData().getDeserializationInvocation() != null && NewRelicSecurity.getAgent().getSecurityMetaData().getDeserializationInvocation().getActive()) { |
49 |
| - if(StringUtils.isNotBlank(NewRelicSecurity.getAgent().getSecurityMetaData().getDeserializationInvocation().peekReadObjectInAction()) |
50 |
| - && !StringUtils.equals(name, "readObject")) { |
51 |
| - JavaReflectionOperation operation = new JavaReflectionOperation(this.getClass().getName(), "invoke", declaringClass.getName(), name, args, obj); |
52 |
| - List<String> methodNames = new ArrayList<>(); |
53 |
| - for (Method method : declaringClass.getDeclaredMethods()) { |
54 |
| - if(Arrays.equals(method.getParameterTypes(), parameterTypes)) { |
55 |
| - methodNames.add(method.getName()); |
56 |
| - } |
57 |
| - } |
58 |
| - operation.setDeclaredMethods(methodNames); |
59 |
| - NewRelicSecurity.getAgent().registerOperation(operation); |
60 |
| - return operation; |
| 49 | + if(NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty() || !GenericHelper.isLockAcquirePossible(VulnerabilityCaseType.REFLECTION)) { |
| 50 | + return null; |
| 51 | + } |
| 52 | + |
| 53 | + JavaReflectionOperation operation = new JavaReflectionOperation(this.getClass().getName(), "invoke", declaringClass.getName(), name, args, obj); |
| 54 | + List<String> methodNames = new ArrayList<>(); |
| 55 | + for (Method method : declaringClass.getDeclaredMethods()) { |
| 56 | + if(Arrays.equals(method.getParameterTypes(), parameterTypes)) { |
| 57 | + methodNames.add(method.getName()); |
61 | 58 | }
|
62 | 59 | }
|
| 60 | + operation.setDeclaredMethods(methodNames); |
| 61 | + NewRelicSecurity.getAgent().registerOperation(operation); |
| 62 | + return operation; |
63 | 63 | } catch (Throwable e) {
|
64 | 64 | if(e instanceof NewRelicSecurityException){
|
65 | 65 | NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.SECURITY_EXCEPTION_MESSAGE, "JAVA-REFLECTION", e.getMessage()), e, Method_Instrumentation.class.getName());
|
|
0 commit comments