Skip to content

Commit

Permalink
Fix for NR-315260, where csec instrumentation packages were present i…
Browse files Browse the repository at this point in the history
…n stacktrace
  • Loading branch information
IshikaDawda committed Sep 30, 2024
1 parent 31396e1 commit b0ecd0f
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mongodb.async.SingleResultCallback;
import com.mongodb.binding.AsyncReadBinding;
import com.mongodb.binding.ReadBinding;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.AbstractOperation;
import com.newrelic.api.agent.security.schema.VulnerabilityCaseType;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -19,6 +20,9 @@ public class CommandReadOperation_Instrumentation<T> {
public T execute(final ReadBinding binding) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_READ, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand All @@ -37,6 +41,9 @@ public T execute(final ReadBinding binding) {
public void executeAsync(final AsyncReadBinding binding, final SingleResultCallback<T> callback) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_READ, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mongodb.async.SingleResultCallback;
import com.mongodb.binding.AsyncWriteBinding;
import com.mongodb.binding.WriteBinding;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.AbstractOperation;
import com.newrelic.api.agent.security.schema.VulnerabilityCaseType;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -19,6 +20,9 @@ public class CommandWriteOperation_Instrumentation<T> {
public T execute(final WriteBinding binding) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_WRITE, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand All @@ -37,6 +41,9 @@ public T execute(final WriteBinding binding) {
public void executeAsync(final AsyncWriteBinding binding, final SingleResultCallback<T> callback) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_WRITE, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static AbstractOperation recordMongoOperation(BsonDocument command, Strin
if (NewRelicSecurity.isHookProcessingActive() &&
!NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty() && command != null) {
operation = new NoSQLOperation(command.toJson(), typeOfOperation, klassName, methodName);
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
NewRelicSecurity.getAgent().registerOperation(operation);
}
} catch (Throwable e) {
Expand Down Expand Up @@ -158,6 +157,9 @@ public static <T> AbstractOperation getReadAbstractOperation(ReadOperation<T> op
AbstractOperation noSQLOperation = null;
try {
List<BsonDocument> operations;
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(4);
}
if (operation instanceof AggregateOperation) {
AggregateOperation aggregateOperation = (AggregateOperation) operation;
noSQLOperation = recordMongoOperation(aggregateOperation.getPipeline(), MongoUtil.OP_AGGREGATE, className, methodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mongodb.async.SingleResultCallback;
import com.mongodb.binding.AsyncReadBinding;
import com.mongodb.binding.ReadBinding;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.AbstractOperation;
import com.newrelic.api.agent.security.schema.VulnerabilityCaseType;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -19,6 +20,9 @@ public class CommandReadOperation_Instrumentation<T> {
public T execute(final ReadBinding binding) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_READ, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand All @@ -37,6 +41,9 @@ public T execute(final ReadBinding binding) {
public void executeAsync(final AsyncReadBinding binding, final SingleResultCallback<T> callback) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(4);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_READ, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public static AbstractOperation recordMongoOperation(BsonDocument command, Strin
if (NewRelicSecurity.isHookProcessingActive() &&
!NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty() && command != null) {
operation = new NoSQLOperation(command.toJson(), typeOfOperation, klassName, methodName);
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
NewRelicSecurity.getAgent().registerOperation(operation);
}
} catch (Throwable e) {
Expand Down Expand Up @@ -170,6 +169,9 @@ public static <T> AbstractOperation getReadAbstractOperation(ReadOperation<T> op
AbstractOperation noSQLOperation = null;
try {
List<BsonDocument> operations;
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(4);
}
if (operation instanceof AggregateOperation) {
AggregateOperation aggregateOperation = (AggregateOperation) operation;
noSQLOperation = recordMongoOperation(aggregateOperation.getPipeline(), MongoUtil.OP_AGGREGATE, className, methodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mongodb.async.SingleResultCallback;
import com.mongodb.binding.AsyncReadBinding;
import com.mongodb.binding.ReadBinding;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.AbstractOperation;
import com.newrelic.api.agent.security.schema.VulnerabilityCaseType;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -19,6 +20,9 @@ public class CommandReadOperation_Instrumentation<T> {
public T execute(final ReadBinding binding) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_READ, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mongodb.async.SingleResultCallback;
import com.mongodb.binding.AsyncWriteBinding;
import com.mongodb.binding.WriteBinding;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.AbstractOperation;
import com.newrelic.api.agent.security.schema.VulnerabilityCaseType;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -19,6 +20,9 @@ public class CommandWriteOperation_Instrumentation<T> {
public T execute(final WriteBinding binding) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_WRITE, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static AbstractOperation recordMongoOperation(BsonDocument command, Strin
if (NewRelicSecurity.isHookProcessingActive() &&
!NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty() && command != null) {
operation = new NoSQLOperation(command.toJson(), typeOfOperation, klassName, methodName);
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
NewRelicSecurity.getAgent().registerOperation(operation);
}
} catch (Throwable e) {
Expand Down Expand Up @@ -168,6 +167,9 @@ public static <T> AbstractOperation getReadAbstractOperation(ReadOperation<T> op
AbstractOperation noSQLOperation = null;
try {
List<BsonDocument> operations;
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(4);
}
if (operation instanceof AggregateOperation) {
AggregateOperation aggregateOperation = (AggregateOperation) operation;
noSQLOperation = recordMongoOperation(aggregateOperation.getPipeline(), MongoUtil.OP_AGGREGATE, className, methodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mongodb.async.SingleResultCallback;
import com.mongodb.binding.AsyncReadBinding;
import com.mongodb.binding.ReadBinding;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.AbstractOperation;
import com.newrelic.api.agent.security.schema.VulnerabilityCaseType;
import com.newrelic.api.agent.weaver.MatchType;
Expand All @@ -19,6 +20,9 @@ public class CommandReadOperation_Instrumentation<T> {
public T execute(final ReadBinding binding) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_READ, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand All @@ -37,6 +41,9 @@ public T execute(final ReadBinding binding) {
public void executeAsync(final AsyncReadBinding binding, final SingleResultCallback<T> callback) {
AbstractOperation noSQLOperation = null;
boolean isLockAcquired = MongoUtil.acquireLockIfPossible(VulnerabilityCaseType.NOSQL_DB_COMMAND, this.hashCode());
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
}
if (isLockAcquired) {
noSQLOperation = MongoUtil.recordMongoOperation(command, MongoUtil.OP_READ, this.getClass().getName(), MongoUtil.METHOD_EXECUTE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static AbstractOperation recordMongoOperation(BsonDocument command, Strin
if (NewRelicSecurity.isHookProcessingActive() &&
!NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty() && command != null) {
operation = new NoSQLOperation(command.toJson(), typeOfOperation, klassName, methodName);
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(3);
NewRelicSecurity.getAgent().registerOperation(operation);
}
} catch (Throwable e) {
Expand Down Expand Up @@ -235,6 +234,9 @@ public static <T> AbstractOperation getReadAbstractOperation(ReadOperation<T> op
AbstractOperation noSQLOperation = null;
try {
List<BsonDocument> operations;
if (NewRelicSecurity.isHookProcessingActive()){
NewRelicSecurity.getAgent().getSecurityMetaData().getMetaData().setFromJumpRequiredInStackTrace(4);
}
if (operation instanceof AggregateOperation) {
AggregateOperation aggregateOperation = (AggregateOperation) operation;
noSQLOperation = recordMongoOperation(aggregateOperation.getPipeline(), MongoUtil.OP_AGGREGATE, className, methodName);
Expand Down

0 comments on commit b0ecd0f

Please sign in to comment.