-
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.
Remove callsites for IAST sources and use bytebuddy advices
- Loading branch information
1 parent
9f8489a
commit 0dbd55b
Showing
46 changed files
with
1,838 additions
and
2,111 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...nt/agent-tooling/src/main/java/datadog/trace/agent/tooling/iast/TaintableEnumeration.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,90 @@ | ||
package datadog.trace.agent.tooling.iast; | ||
|
||
import datadog.trace.api.iast.IastContext; | ||
import datadog.trace.api.iast.propagation.PropagationModule; | ||
import datadog.trace.util.stacktrace.StackUtils; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.util.Enumeration; | ||
import javax.annotation.Nullable; | ||
|
||
public class TaintableEnumeration implements Enumeration<String> { | ||
|
||
private static final String USE_NAME_FROM_VALUE = "USE_NAME_FROM_VALUE"; | ||
private static final String CLASS_NAME = TaintableEnumeration.class.getName(); | ||
|
||
private volatile IastContext context; | ||
private volatile boolean contextFetched; | ||
|
||
private final PropagationModule module; | ||
|
||
private final byte origin; | ||
|
||
private final CharSequence name; | ||
|
||
private final Enumeration<String> delegate; | ||
|
||
private TaintableEnumeration( | ||
@NonNull final Enumeration<String> delegate, | ||
@NonNull final PropagationModule module, | ||
final byte origin, | ||
@Nullable final CharSequence name) { | ||
this.delegate = delegate; | ||
this.module = module; | ||
this.origin = origin; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean hasMoreElements() { | ||
try { | ||
return delegate.hasMoreElements(); | ||
} catch (Throwable e) { | ||
StackUtils.filterFirst(e, TaintableEnumeration::isValidStack); | ||
throw e; | ||
} | ||
} | ||
|
||
@Override | ||
public String nextElement() { | ||
final String next; | ||
try { | ||
next = delegate.nextElement(); | ||
} catch (Throwable e) { | ||
StackUtils.filterFirst(e, TaintableEnumeration::isValidStack); | ||
throw e; | ||
} | ||
try { | ||
module.taint(context(), next, origin, name == USE_NAME_FROM_VALUE ? next : name); | ||
} catch (final Throwable e) { | ||
module.onUnexpectedException("Failed to taint enumeration", e); | ||
} | ||
return next; | ||
} | ||
|
||
private IastContext context() { | ||
if (!contextFetched) { | ||
contextFetched = true; | ||
context = IastContext.Provider.get(); | ||
} | ||
return context; | ||
} | ||
|
||
private static boolean isValidStack(final StackTraceElement element) { | ||
return !CLASS_NAME.equals(element.getClassName()); | ||
} | ||
|
||
public static Enumeration<String> wrap( | ||
@NonNull final Enumeration<String> delegate, | ||
@NonNull final PropagationModule module, | ||
final byte origin, | ||
@Nullable final CharSequence name) { | ||
return new TaintableEnumeration(delegate, module, origin, name); | ||
} | ||
|
||
public static Enumeration<String> wrapNameFromValue( | ||
@NonNull final Enumeration<String> delegate, | ||
@NonNull final PropagationModule module, | ||
final byte origin) { | ||
return wrap(delegate, module, origin, USE_NAME_FROM_VALUE); | ||
} | ||
} |
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
99 changes: 99 additions & 0 deletions
99
...-tooling/src/test/groovy/datadog/trace/agent/tooling/iast/TaintableEnumerationTest.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,99 @@ | ||
package datadog.trace.agent.tooling.iast | ||
|
||
import datadog.trace.api.gateway.RequestContext | ||
import datadog.trace.api.gateway.RequestContextSlot | ||
import datadog.trace.api.iast.IastContext | ||
import datadog.trace.api.iast.InstrumentationBridge | ||
import datadog.trace.api.iast.SourceTypes | ||
import datadog.trace.api.iast.propagation.PropagationModule | ||
import datadog.trace.bootstrap.instrumentation.api.AgentSpan | ||
import datadog.trace.bootstrap.instrumentation.api.AgentTracer | ||
import datadog.trace.test.util.DDSpecification | ||
import spock.lang.Shared | ||
|
||
class TaintableEnumerationTest extends DDSpecification { | ||
|
||
@Shared | ||
protected static final AgentTracer.TracerAPI ORIGINAL_TRACER = AgentTracer.get() | ||
|
||
protected AgentTracer.TracerAPI tracer = Mock(AgentTracer.TracerAPI) | ||
|
||
protected IastContext iastCtx = Mock(IastContext) | ||
|
||
protected RequestContext reqCtx = Mock(RequestContext) { | ||
getData(RequestContextSlot.IAST) >> iastCtx | ||
} | ||
|
||
protected AgentSpan span = Mock(AgentSpan) { | ||
getRequestContext() >> reqCtx | ||
} | ||
|
||
protected PropagationModule module | ||
|
||
|
||
void setup() { | ||
AgentTracer.forceRegister(tracer) | ||
module = Mock(PropagationModule) | ||
InstrumentationBridge.registerIastModule(module) | ||
} | ||
|
||
void cleanup() { | ||
AgentTracer.forceRegister(ORIGINAL_TRACER) | ||
InstrumentationBridge.clearIastModules() | ||
} | ||
|
||
void 'underlying enumerated values are tainted with a name'() { | ||
given: | ||
final values = (1..10).collect { "value$it".toString() } | ||
final origin = SourceTypes.REQUEST_PARAMETER_NAME | ||
final name = 'test' | ||
final enumeration = TaintableEnumeration.wrap(Collections.enumeration(values), module, origin, name) | ||
|
||
when: | ||
final result = enumeration.collect() | ||
|
||
then: | ||
result == values | ||
values.each { 1 * module.taint(_, it, origin, name) } | ||
1 * tracer.activeSpan() >> span | ||
} | ||
|
||
void 'underlying enumerated values are tainted with the value as a name'() { | ||
given: | ||
final values = (1..10).collect { "value$it".toString() } | ||
final origin = SourceTypes.REQUEST_PARAMETER_NAME | ||
final enumeration = TaintableEnumeration.wrapNameFromValue(Collections.enumeration(values), module, origin) | ||
|
||
when: | ||
final result = enumeration.collect() | ||
|
||
then: | ||
result == values | ||
values.each { 1 * module.taint(_, it, origin, it) } | ||
} | ||
|
||
void 'taintable enumeration leaves no trace in case of error'() { | ||
given: | ||
final origin = SourceTypes.REQUEST_PARAMETER_NAME | ||
final enumeration = TaintableEnumeration.wrapNameFromValue(new BadEnumeration(), module, origin) | ||
|
||
when: | ||
enumeration.hasMoreElements() | ||
|
||
then: | ||
final first = thrown(Error) | ||
first.stackTrace.find { it.className == TaintableEnumeration.name } == null | ||
} | ||
|
||
private static class BadEnumeration implements Enumeration<String> { | ||
@Override | ||
boolean hasMoreElements() { | ||
throw new Error('Ooops!!!') | ||
} | ||
|
||
@Override | ||
String nextElement() { | ||
throw new Error('Boom!!!') | ||
} | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
...ain/java/datadog/trace/instrumentation/servlet3/callsite/HttpServlet3RequestCallSite.java
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
...rc/main/java/datadog/trace/instrumentation/servlet3/callsite/Servlet3RequestCallSite.java
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
...entation/servlet/request-3/src/test/groovy/Servlet3TestGetParameterInstrumentation.groovy
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...trumentation/servlet/request-3/src/test/java/foo/bar/smoketest/HttpServlet3TestSuite.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...ation/servlet/request-3/src/test/java/foo/bar/smoketest/HttpServletWrapper3TestSuite.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
.../instrumentation/servlet/request-3/src/test/java/foo/bar/smoketest/Servlet3TestSuite.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...agent/instrumentation/servlet/request-3/src/test/java/foo/bar/smoketest/ServletSuite.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.