-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
dd-java-agent/instrumentation/apache-httpcore-4/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" | ||
module = "httpcore" | ||
versions = "[4.0,5)" | ||
assertInverse = true | ||
} | ||
} | ||
|
||
apply from: "$rootDir/gradle/java.gradle" | ||
|
||
addTestSuiteForDir('latestDepTest', 'test') | ||
|
||
dependencies { | ||
compileOnly group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.0' | ||
|
||
testImplementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.0' | ||
|
||
latestDepTestImplementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '+' | ||
} |
49 changes: 49 additions & 0 deletions
49
...c/main/java/datadog/trace/instrumentation/apachehttpcore/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,49 @@ | ||
package datadog.trace.instrumentation.apachehttpcore; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.api.iast.InstrumentationBridge; | ||
import datadog.trace.api.iast.Propagation; | ||
import datadog.trace.api.iast.propagation.PropagationModule; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
@AutoService(Instrumenter.class) | ||
public class IastHttpHostInstrumentation extends Instrumenter.Iast | ||
implements Instrumenter.ForSingleType { | ||
|
||
public IastHttpHostInstrumentation() { | ||
super("httpcore", "apache-httpcore", "apache-http-core"); | ||
} | ||
|
||
@Override | ||
public String instrumentedType() { | ||
return "org.apache.http.HttpHost"; | ||
} | ||
|
||
@Override | ||
public void adviceTransformations(AdviceTransformation transformation) { | ||
transformation.applyAdvice( | ||
isConstructor() | ||
.and(takesArguments(3)) | ||
.and(takesArgument(0, String.class)) | ||
.and(takesArgument(1, int.class)) | ||
.and(takesArgument(2, String.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(0) final Object argument) { | ||
final PropagationModule module = InstrumentationBridge.PROPAGATION; | ||
if (module != null) { | ||
module.taintIfTainted(self, argument); | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...roovy/datadog/trace/instrumentation/apachehttpcore/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,33 @@ | ||
package datadog.trace.instrumentation.apachehttpcore | ||
|
||
import datadog.trace.agent.test.AgentTestRunner | ||
import datadog.trace.api.iast.InstrumentationBridge | ||
import datadog.trace.api.iast.propagation.PropagationModule | ||
import org.apache.http.HttpHost | ||
|
||
class IastHttpHostInstrumentationTest extends AgentTestRunner { | ||
|
||
@Override | ||
protected void configurePreAgent() { | ||
injectSysConfig('dd.iast.enabled', 'true') | ||
} | ||
|
||
void 'test'(){ | ||
given: | ||
final module = Mock(PropagationModule) | ||
InstrumentationBridge.registerIastModule(module) | ||
|
||
when: | ||
HttpHost.newInstance(*args) | ||
|
||
then: | ||
1 * module.taintIfTainted( _ as HttpHost, 'localhost') | ||
|
||
where: | ||
args | _ | ||
['localhost'] | _ | ||
['localhost', 8080] | _ | ||
['localhost', 8080, 'http'] | _ | ||
[new HttpHost('localhost')] | _ | ||
} | ||
} |
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