-
Notifications
You must be signed in to change notification settings - Fork 303
Expand SSRF support in IAST to apache-httpclient-5 and apache-httpasyncclient-4 #7920
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
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
09d100c
Draft status commit
Mariovido 821f857
Remove comments and leave minimal changes
Mariovido 453d57b
Remove AgentInstaller code
Mariovido b07f70f
Merge master
Mariovido e65bf5b
Undo move of apache core module
Mariovido c4bd2fb
Undo apache decorator
Mariovido b24df39
Remove unused variable in the ssrf controller
Mariovido c7ffba1
Simplify instrumentation
Mariovido 29ea5f2
First working solution
Mariovido af7c2aa
Add support for host methods
Mariovido 160c0ca
Added support for last methods
Mariovido 03a95d6
Add test propagationUtils
Mariovido 7c085ba
Add support for apache-httpasynclient
Mariovido faa2492
Merge branch 'master' into mario.vidal/expand_support_ssrf_apache
Mariovido 7b2ee35
Minor changes
Mariovido 5347dd7
Change argument to string
Mariovido d7ed872
Merge branch 'master' into mario.vidal/expand_support_ssrf_apache
Mariovido File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 Object 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.