-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand SSRF support in IAST to apache-httpclient-5 and apache-httpasy…
…ncclient-4 (#7920)
- Loading branch information
Showing
17 changed files
with
330 additions
and
11 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
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
53 changes: 53 additions & 0 deletions
53
...atadog/trace/instrumentation/apachehttpclient5/IastHttpUriRequestBaseInstrumentation.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,53 @@ | ||
package datadog.trace.instrumentation.apachehttpclient5; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.agent.tooling.InstrumenterModule; | ||
import datadog.trace.agent.tooling.bytebuddy.iast.TaintableVisitor; | ||
import datadog.trace.api.iast.InstrumentationBridge; | ||
import datadog.trace.api.iast.Propagation; | ||
import datadog.trace.api.iast.propagation.PropagationModule; | ||
import java.net.URI; | ||
import net.bytebuddy.asm.Advice; | ||
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; | ||
|
||
@AutoService(InstrumenterModule.class) | ||
public class IastHttpUriRequestBaseInstrumentation extends InstrumenterModule.Iast | ||
implements Instrumenter.ForSingleType, Instrumenter.HasTypeAdvice { | ||
|
||
public IastHttpUriRequestBaseInstrumentation() { | ||
super("apache-httpclient", "httpclient5"); | ||
} | ||
|
||
@Override | ||
public String instrumentedType() { | ||
return "org.apache.hc.client5.http.classic.methods.HttpUriRequestBase"; | ||
} | ||
|
||
@Override | ||
public void typeAdvice(TypeTransformer transformer) { | ||
transformer.applyAdvice(new TaintableVisitor(instrumentedType())); | ||
} | ||
|
||
@Override | ||
public void methodAdvice(MethodTransformer transformer) { | ||
transformer.applyAdvice( | ||
isConstructor().and(takesArguments(String.class, URI.class)), | ||
IastHttpUriRequestBaseInstrumentation.class.getName() + "$CtorAdvice"); | ||
} | ||
|
||
public static class CtorAdvice { | ||
@Advice.OnMethodExit() | ||
@Propagation | ||
public static void afterCtor( | ||
@Advice.This final HttpUriRequestBase self, @Advice.Argument(1) final URI uri) { | ||
final PropagationModule module = InstrumentationBridge.PROPAGATION; | ||
if (module != null) { | ||
module.taintObjectIfTainted(self, uri); | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...tion/apache-httpclient-5/src/test/groovy/IastHttpUriRequestBaseInstrumentationTest.groovy
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,29 @@ | ||
import datadog.trace.agent.test.AgentTestRunner | ||
import datadog.trace.api.iast.InstrumentationBridge | ||
import datadog.trace.api.iast.propagation.PropagationModule | ||
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase | ||
|
||
class IastHttpUriRequestBaseInstrumentationTest extends AgentTestRunner { | ||
|
||
@Override | ||
protected void configurePreAgent() { | ||
injectSysConfig('dd.iast.enabled', 'true') | ||
} | ||
|
||
void 'test constructor'() { | ||
given: | ||
final module = Mock(PropagationModule) | ||
InstrumentationBridge.registerIastModule(module) | ||
|
||
when: | ||
HttpUriRequestBase.newInstance(method, new URI(uri)) | ||
|
||
then: | ||
1 * module.taintObjectIfTainted(_ as HttpUriRequestBase, _ as URI) | ||
0 * _ | ||
|
||
where: | ||
method | uri | ||
"GET" | 'http://localhost.com' | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
dd-java-agent/instrumentation/apache-httpcore-5/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,20 @@ | ||
muzzle { | ||
pass { | ||
group = "org.apache.httpcomponents.core5" | ||
module = "httpcore5" | ||
versions = "[5.0,)" | ||
assertInverse = true | ||
} | ||
} | ||
|
||
apply from: "$rootDir/gradle/java.gradle" | ||
|
||
addTestSuiteForDir('latestDepTest', 'test') | ||
|
||
dependencies { | ||
compileOnly group: 'org.apache.httpcomponents.core5', name: 'httpcore5', version: '5.0' | ||
|
||
testImplementation group: 'org.apache.httpcomponents.core5', name: 'httpcore5', version: '5.0' | ||
|
||
latestDepTestImplementation group: 'org.apache.httpcomponents.core5', name: 'httpcore5', version: '+' | ||
} |
47 changes: 47 additions & 0 deletions
47
.../main/java/datadog/trace/instrumentation/apachehttpcore5/IastHttpHostInstrumentation.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,47 @@ | ||
package datadog.trace.instrumentation.apachehttpcore5; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.agent.tooling.InstrumenterModule; | ||
import datadog.trace.api.iast.InstrumentationBridge; | ||
import datadog.trace.api.iast.Propagation; | ||
import datadog.trace.api.iast.propagation.PropagationModule; | ||
import java.net.InetAddress; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
@AutoService(InstrumenterModule.class) | ||
public class IastHttpHostInstrumentation extends InstrumenterModule.Iast | ||
implements Instrumenter.ForSingleType { | ||
|
||
public IastHttpHostInstrumentation() { | ||
super("httpcore-5", "apache-httpcore-5", "apache-http-core-5"); | ||
} | ||
|
||
@Override | ||
public String instrumentedType() { | ||
return "org.apache.hc.core5.http.HttpHost"; | ||
} | ||
|
||
@Override | ||
public void methodAdvice(MethodTransformer transformer) { | ||
transformer.applyAdvice( | ||
isConstructor() | ||
.and(takesArguments(String.class, InetAddress.class, String.class, int.class)), | ||
IastHttpHostInstrumentation.class.getName() + "$CtorAdvice"); | ||
} | ||
|
||
public static class CtorAdvice { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
@Propagation | ||
public static void afterCtor( | ||
@Advice.This final Object self, @Advice.Argument(2) final String host) { | ||
final PropagationModule module = InstrumentationBridge.PROPAGATION; | ||
if (module != null) { | ||
module.taintObjectIfTainted(self, host); | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...oovy/datadog/trace/instrumentation/apachehttpcore5/IastHttpHostInstrumentationTest.groovy
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,31 @@ | ||
package datadog.trace.instrumentation.apachehttpcore5 | ||
|
||
import datadog.trace.agent.test.AgentTestRunner | ||
import datadog.trace.api.iast.InstrumentationBridge | ||
import datadog.trace.api.iast.propagation.PropagationModule | ||
import org.apache.hc.core5.http.HttpHost | ||
|
||
class IastHttpHostInstrumentationTest extends AgentTestRunner { | ||
|
||
@Override | ||
protected void configurePreAgent() { | ||
injectSysConfig('dd.iast.enabled', 'true') | ||
} | ||
|
||
void 'test constructor'(){ | ||
given: | ||
final module = Mock(PropagationModule) | ||
InstrumentationBridge.registerIastModule(module) | ||
|
||
when: | ||
HttpHost.newInstance(*args) | ||
|
||
then: | ||
1 * module.taintObjectIfTainted( _ as HttpHost, 'localhost') | ||
|
||
where: | ||
args | _ | ||
['localhost'] | _ | ||
['localhost', 8080] | _ | ||
} | ||
} |
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
Oops, something went wrong.