Skip to content

CSEC Java Agent Version 1.7.0 #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Noteworthy changes to the agent are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.7.0] - TBD
## [1.7.0] - 2025-4-25
### Adds
- [PR-395](https://github.com/newrelic/csec-java-agent/pull/395) **Support for Deserialization Vulnerability Detection**: Implemented mechanisms to detect vulnerabilities arising from unsafe deserialization processes.
- [PR-395](https://github.com/newrelic/csec-java-agent/pull/395) **Support for Vulnerability Detection of Remote Code Invocation via Reflection**: Enhanced capability to identify security risks associated with remote code execution through reflection.
Expand All @@ -16,8 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [PR-403](https://github.com/newrelic/csec-java-agent/pull/403) GraphQL Supported Version Range: Restricted the supported version range for GraphQL due to the release of a new version on April 7th, 2025

### Fixes
- [PR-372](https://github.com/newrelic/csec-java-agent/pull/372) **Repeat IAST Request Relay Commands**: Reconfigured logic to repeat IAST control commands until the endpoint is confirmed.
- [PR-372](https://github.com/newrelic/csec-java-agent/pull/372) **Repeat IAST Request Replay Commands**: Reconfigured logic to repeat IAST control commands until the endpoint is confirmed.

### Note
- The instrumentation for the module `com.newrelic.instrumentation.security.java-reflection` is disabled by default. This is due to its impact on CPU utilization, which can significantly increase when the module is active.
- **Action Required**: To detect unsafe reflection vulnerabilities effectively, enable the `com.newrelic.instrumentation.security.java-reflection` module.

## [1.6.1] - 2025-3-1
### Adds
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The agent version.
agentVersion=1.6.1
agentVersion=1.7.0
jsonVersion=1.2.11
# Updated exposed NR APM API version.
nrAPIVersion=8.12.0
Expand Down
2 changes: 1 addition & 1 deletion instrumentation-security/java-reflection/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {


jar {
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.java-reflection' }
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.java-reflection', 'Enabled': 'false' }
}

verifyInstrumentation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class ContainerResponse_Instrumentation {
public void close() {
boolean isLockAcquired = false;
try {
isLockAcquired = GenericHelper.acquireLockIfPossible(VulnerabilityCaseType.REFLECTED_XSS, SERVLET_GET_IS_OPERATION_LOCK);
isLockAcquired = GenericHelper.acquireLockIfPossible(SERVLET_GET_IS_OPERATION_LOCK);
if(isLockAcquired && GenericHelper.isLockAcquired(HttpRequestHelper.getNrSecCustomAttribForPostProcessing())) {
HttpRequestHelper.postProcessSecurityHook(this.getClass().getName(), getWrappedMessageContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class ContainerResponse_Instrumentation {
public void close() {
boolean isLockAcquired = false;
try {
isLockAcquired = GenericHelper.acquireLockIfPossible(VulnerabilityCaseType.REFLECTED_XSS, SERVLET_GET_IS_OPERATION_LOCK);
isLockAcquired = GenericHelper.acquireLockIfPossible(SERVLET_GET_IS_OPERATION_LOCK);
if(isLockAcquired && GenericHelper.isLockAcquired(HttpRequestHelper.getNrSecCustomAttribForPostProcessing())) {
HttpRequestHelper.postProcessSecurityHook(this.getClass().getName(), getWrappedMessageContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class ContainerResponse_Instrumentation {
public void close() {
boolean isLockAcquired = false;
try {
isLockAcquired = GenericHelper.acquireLockIfPossible(VulnerabilityCaseType.REFLECTED_XSS, SERVLET_GET_IS_OPERATION_LOCK);
isLockAcquired = GenericHelper.acquireLockIfPossible(SERVLET_GET_IS_OPERATION_LOCK);
if(isLockAcquired && GenericHelper.isLockAcquired(HttpRequestHelper.getNrSecCustomAttribForPostProcessing())) {
HttpRequestHelper.postProcessSecurityHook(this.getClass().getName(), getWrappedMessageContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
@Weave(type = MatchType.ExactClass, originalName = "org.mule.module.http.internal.domain.response.HttpResponseBuilder")
public class HttpResponseBuilder_Instrumentation {

private final ResponseStatus responseStatus = Weaver.callOriginal();
private final HttpEntity body = Weaver.callOriginal();
private ResponseStatus responseStatus = Weaver.callOriginal();
private HttpEntity body = Weaver.callOriginal();

public HttpResponse build() {
HttpResponse response = Weaver.callOriginal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
@Weave(type = MatchType.ExactClass, originalName = "org.mule.module.http.internal.domain.response.HttpResponseBuilder")
public class HttpResponseBuilder_Instrumentation {

private final ResponseStatus responseStatus = Weaver.callOriginal();
private final HttpEntity body = Weaver.callOriginal();
private ResponseStatus responseStatus = Weaver.callOriginal();
private HttpEntity body = Weaver.callOriginal();

public HttpResponse build() {
HttpResponse response = Weaver.callOriginal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public void addCookie(Cookie cookie){
releaseLock(cookie.hashCode());
}
}
if (isOwaspHookEnabled) {
registerExitOperation(isLockAcquired, operation);
}
}

private AbstractOperation preprocessSecurityHook(Cookie cookie, String className, String methodName) {
Expand Down Expand Up @@ -78,6 +81,17 @@ private AbstractOperation preprocessSecurityHook(Cookie cookie, String className
return null;
}

private static void registerExitOperation(boolean isProcessingAllowed, AbstractOperation operation) {
try {
if (operation == null || !isProcessingAllowed || !NewRelicSecurity.isHookProcessingActive() || NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) {
return;
}
NewRelicSecurity.getAgent().registerExitEvent(operation);
} catch (Throwable e) {
NewRelicSecurity.getAgent().log(LogLevel.FINEST, String.format(GenericHelper.EXIT_OPERATION_EXCEPTION_MESSAGE, HttpServletHelper.SERVLET_2_4, e.getMessage()), e, HttpServletResponse_Instrumentation.class.getName());
}
}

private void releaseLock(int hashCode) {
GenericHelper.releaseLock(ServletHelper.NR_SEC_HTTP_SERVLET_RESPONSE_ATTRIB_NAME, hashCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void testSessionSetAttribute() throws IOException, URISyntaxException {
SecurityIntrospector introspector = SecurityInstrumentationTestRunner.getIntrospector();
List<AbstractOperation> operations = introspector.getOperations();
Assert.assertTrue("No operations detected", operations.size() > 0);
Assert.assertTrue("Unexpected operation count detected", operations.size() == 2 || operations.size() == 3);
TrustBoundaryOperation targetOperation = null;
int i=0;
for (AbstractOperation operation : operations) {
Expand Down Expand Up @@ -65,7 +64,6 @@ public void testSessionPutValue() throws IOException, URISyntaxException {
SecurityIntrospector introspector = SecurityInstrumentationTestRunner.getIntrospector();
List<AbstractOperation> operations = introspector.getOperations();
Assert.assertFalse(operations.isEmpty());
Assert.assertTrue("Unexpected operation count detected", operations.size() == 2 || operations.size() == 3);
TrustBoundaryOperation targetOperation = null;
for (AbstractOperation operation : operations) {
if (operation instanceof TrustBoundaryOperation)
Expand All @@ -86,7 +84,6 @@ public void testAddCookie() throws IOException, URISyntaxException {
SecurityIntrospector introspector = SecurityInstrumentationTestRunner.getIntrospector();
List<AbstractOperation> operations = introspector.getOperations();
Assert.assertTrue("No operations detected", operations.size() > 0);
Assert.assertTrue("Unexpected operation count detected", operations.size() == 1 || operations.size() == 2);
SecureCookieOperationSet targetOperation = null;
targetOperation = verifySecureCookieOp(operations);

Expand Down
3 changes: 3 additions & 0 deletions newrelic-security-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ tasks.register('generate-sbom') {
def parsedJson = new JsonSlurper().parseText(req.getInputStream().getText())

try {
if (!project.buildDir.exists()) {
mkdir project.buildDir;
}
def reportsDir = Paths.get("$buildDir", "reports")
def sbomFile = new File("$buildDir/reports", "SBOM.json")
if (Files.exists(reportsDir) || Files.createDirectory(reportsDir)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private String applyRequiredLogLevel() {
if(value instanceof Boolean) {
logLevel = IUtilConstants.OFF;
} else {
logLevel = NewRelic.getAgent().getConfig().getValue(IUtilConstants.NR_LOG_LEVEL, LogLevel.FINEST.name());
logLevel = NewRelic.getAgent().getConfig().getValue(IUtilConstants.NR_LOG_LEVEL, IUtilConstants.INFO);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.newrelic.api.agent.security.schema.ServerConnectionConfiguration;
import com.newrelic.api.agent.security.schema.operation.FileIntegrityOperation;
import com.newrelic.api.agent.security.schema.operation.FileOperation;
import com.newrelic.api.agent.security.schema.operation.SecureCookieOperationSet;
import com.newrelic.api.agent.security.schema.policy.AgentPolicy;
import com.newrelic.api.agent.security.schema.policy.IastDetectionCategory;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
Expand Down Expand Up @@ -85,6 +86,8 @@ public void registerOperation(AbstractOperation operation) {
return;
}
operation.setApiID(apiId);
String executionId = "dummy-exec-id";
operation.setExecutionId(executionId);
operation.setStartTime(Instant.now().toEpochMilli());
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
operation.setStackTrace(Arrays.copyOfRange(trace, 1, trace.length));
Expand All @@ -93,6 +96,9 @@ public void registerOperation(AbstractOperation operation) {

@Override
public void registerExitEvent(AbstractOperation operation) {
if (operation instanceof SecureCookieOperationSet) {
this.getSecurityMetaData().getCustomAttribute(OPERATIONS, List.class).add(operation);
}
this.getSecurityMetaData().getCustomAttribute(EXIT_OPERATIONS, List.class).add(operation);
}

Expand Down
Loading