-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/insecure_cookie_issue
- Loading branch information
Showing
60 changed files
with
3,752 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Snyk Vulnerability Scan | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '00 15 * * 1' | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
security: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Java Agent | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: 'main' | ||
|
||
- name: Set gradle.properties Workaround | ||
shell: bash | ||
run: | | ||
echo "jdk8=/tmp" >> gradle.properties | ||
echo "jdk11=/tmp" >> gradle.properties | ||
echo "jdk17=/tmp" >> gradle.properties | ||
- name: Run Snyk to check for vulnerabilities | ||
uses: snyk/actions/gradle@master | ||
env: | ||
SNYK_TOKEN: ${{ secrets.JAVA_AGENT_SNYK_TOKEN }} | ||
with: | ||
command: monitor | ||
args: --all-sub-projects --org=java-agent --configuration-matching='(includeInJar)|(shadowIntoJar)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
24 changes: 24 additions & 0 deletions
24
instrumentation-security/cassandra-datastax-3/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
dependencies { | ||
implementation(project(":newrelic-security-api")) | ||
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") | ||
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") | ||
implementation("com.datastax.cassandra:cassandra-driver-core:3.2.0") | ||
|
||
testImplementation("org.cassandraunit:cassandra-unit:3.1.1.0") | ||
testImplementation("com.github.jbellis:jamm:0.3.2") | ||
} | ||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.cassandra-datastax-3' } | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly 'com.datastax.cassandra:cassandra-driver-core:[3.0.0,4.0.0)' | ||
excludeRegex ".*(rc|beta|alpha).*" | ||
excludeRegex('com.datastax.cassandra:cassandra-driver-core:2.*') | ||
} | ||
|
||
site { | ||
title 'Cassandra' | ||
type 'Datastore' | ||
} |
39 changes: 39 additions & 0 deletions
39
...dra-datastax-3/src/main/java/com/datastax/driver/core/SessionManager_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.datastax.driver.core; | ||
|
||
import com.newrelic.agent.security.instrumentation.cassandra3.CassandraUtils; | ||
import com.newrelic.api.agent.security.NewRelicSecurity; | ||
import com.newrelic.api.agent.security.schema.AbstractOperation; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
@Weave(type = MatchType.ExactClass, originalName = "com.datastax.driver.core.SessionManager") | ||
abstract class SessionManager_Instrumentation { | ||
abstract Configuration configuration(); | ||
|
||
public ResultSetFuture executeAsync(Statement statement) { | ||
boolean isLockAcquired = CassandraUtils.acquireLockIfPossible(statement.hashCode()); | ||
ResultSetFuture result; | ||
AbstractOperation cqlOperation = null; | ||
|
||
try { | ||
result = Weaver.callOriginal(); | ||
if(statement instanceof StatementWrapper){ | ||
statement = ((StatementWrapper) statement).getWrappedStatement(); | ||
} | ||
|
||
if(isLockAcquired){ | ||
cqlOperation = CassandraUtils.preProcessSecurityHook(statement, configuration(), this.getClass().getName()); | ||
if(cqlOperation != null){ | ||
NewRelicSecurity.getAgent().registerOperation(cqlOperation); | ||
} | ||
} | ||
} finally { | ||
if(isLockAcquired){ | ||
CassandraUtils.releaseLock(statement.hashCode()); | ||
} | ||
} | ||
CassandraUtils.registerExitOperation(isLockAcquired, cqlOperation); | ||
return result; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...ra-datastax-3/src/main/java/com/datastax/driver/core/SimpleStatement_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.datastax.driver.core; | ||
|
||
import com.newrelic.agent.security.instrumentation.cassandra3.CassandraUtils; | ||
import com.newrelic.api.agent.security.NewRelicSecurity; | ||
import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; | ||
import com.newrelic.api.agent.security.schema.operation.SQLOperation; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Weave(type= MatchType.ExactClass, originalName = "com.datastax.driver.core.SimpleStatement") | ||
public abstract class SimpleStatement_Instrumentation { | ||
|
||
public SimpleStatement_Instrumentation(String query, Object... values) { | ||
boolean isLockAcquired = CassandraUtils.acquireLockIfPossible(hashCode()); | ||
|
||
try{ | ||
if(isLockAcquired){ | ||
SQLOperation cqlOperation = new SQLOperation(this.getClass().getName(), CassandraUtils.METHOD_EXECUTE_ASYNC); | ||
cqlOperation.setQuery(query); | ||
cqlOperation.setCaseType(VulnerabilityCaseType.NOSQL_DB_COMMAND); | ||
cqlOperation.setDbName(CassandraUtils.EVENT_CATEGORY); | ||
if (values != null){ | ||
cqlOperation.setParams(setParams(values)); | ||
} | ||
NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute( | ||
CassandraUtils.NR_SEC_CUSTOM_ATTRIB_CQL_STMT + hashCode(), cqlOperation); | ||
} | ||
} finally { | ||
if(isLockAcquired){ | ||
CassandraUtils.releaseLock(hashCode()); | ||
} | ||
} | ||
} | ||
|
||
public SimpleStatement_Instrumentation(String query, Map<String, Object> values){ | ||
boolean isLockAcquired = CassandraUtils.acquireLockIfPossible(hashCode()); | ||
|
||
try{ | ||
if(isLockAcquired){ | ||
SQLOperation cqlOperation = new SQLOperation(this.getClass().getName(), CassandraUtils.METHOD_EXECUTE_ASYNC); | ||
cqlOperation.setQuery(query); | ||
cqlOperation.setCaseType(VulnerabilityCaseType.NOSQL_DB_COMMAND); | ||
cqlOperation.setDbName(CassandraUtils.EVENT_CATEGORY); | ||
cqlOperation.setParams(setParams(values)); | ||
NewRelicSecurity.getAgent().getSecurityMetaData().addCustomAttribute( | ||
CassandraUtils.NR_SEC_CUSTOM_ATTRIB_CQL_STMT + hashCode(), cqlOperation); | ||
} | ||
} finally { | ||
if(isLockAcquired){ | ||
CassandraUtils.releaseLock(hashCode()); | ||
} | ||
} | ||
} | ||
private Map<String, String> setParams(Object... values) { | ||
Map<String, String> params = new HashMap<>(); | ||
for(int i = 0; i < values.length; i++){ | ||
if(!(values[i] instanceof ByteBuffer)){ | ||
params.put(String.valueOf(i), String.valueOf(values[i])); | ||
} | ||
} | ||
return params; | ||
} | ||
private Map<String, String> setParams(Map<String, Object> values) { | ||
Map<String, String> params = new HashMap<>(); | ||
for( Map.Entry<String, Object> namedVal: values.entrySet()) { | ||
if(!(namedVal.getValue() instanceof ByteBuffer)){ | ||
params.put(namedVal.getKey(), String.valueOf(namedVal.getValue())); | ||
} | ||
} | ||
return params; | ||
} | ||
} |
Oops, something went wrong.