Skip to content

Commit

Permalink
Refactor of the PropagationModule and removal of WebModule (#6033)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-alvarez-alvarez authored and jandro996 committed Oct 27, 2023
1 parent 9db54a0 commit b68b8f0
Show file tree
Hide file tree
Showing 213 changed files with 2,252 additions and 2,097 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.datadog.iast.propagation;

import static com.datadog.iast.model.Range.NOT_MARKED;
import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import com.datadog.iast.IastRequestContext;
import com.datadog.iast.model.Range;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.datadog.iast.propagation;

import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;
import static java.util.concurrent.TimeUnit.MICROSECONDS;

import com.datadog.iast.IastRequestContext;
Expand Down Expand Up @@ -34,8 +35,7 @@ protected StringBuilderBatchBenchmark.Context initializeContext() {
final String value;
if (current < limit) {
value =
tainted(
context, UUID.randomUUID().toString(), new Range(3, 6, source(), Range.NOT_MARKED));
tainted(context, UUID.randomUUID().toString(), new Range(3, 6, source(), NOT_MARKED));
} else {
value = notTainted(UUID.randomUUID().toString());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.datadog.iast.propagation;

import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import com.datadog.iast.IastRequestContext;
import com.datadog.iast.model.Range;
import datadog.trace.instrumentation.java.lang.StringBuilderCallSite;
Expand All @@ -14,7 +16,7 @@ protected Context initializeContext() {
final IastRequestContext context = new IastRequestContext();
final String notTainted = notTainted("I am not a tainted string");
final String tainted =
tainted(context, "I am a tainted string", new Range(3, 6, source(), Range.NOT_MARKED));
tainted(context, "I am a tainted string", new Range(3, 6, source(), NOT_MARKED));
return new Context(context, notTainted, tainted);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.datadog.iast.propagation;

import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import com.datadog.iast.IastRequestContext;
import com.datadog.iast.model.Range;
import datadog.trace.instrumentation.java.lang.StringBuilderCallSite;
Expand All @@ -18,7 +20,7 @@ protected Context initializeContext() {
tainted(
context,
new StringBuilder("I am a tainted string builder"),
new Range(5, 7, source(), Range.NOT_MARKED));
new Range(5, 7, source(), NOT_MARKED));
return new Context(context, notTaintedBuilder, taintedBuilder);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.datadog.iast.propagation;

import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import com.datadog.iast.IastRequestContext;
import com.datadog.iast.model.Range;
import datadog.trace.instrumentation.java.lang.StringCallSite;
Expand All @@ -13,7 +15,7 @@ protected StringConcatBenchmark.Context initializeContext() {
final IastRequestContext context = new IastRequestContext();
final String notTainted = notTainted("I am not a tainted string");
final String tainted =
tainted(context, "I am a tainted string", new Range(3, 5, source(), Range.NOT_MARKED));
tainted(context, "I am a tainted string", new Range(3, 5, source(), NOT_MARKED));
return new StringConcatBenchmark.Context(context, notTainted, tainted);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.datadog.iast.propagation;

import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;
import static java.util.concurrent.TimeUnit.MICROSECONDS;

import com.datadog.iast.IastRequestContext;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected StringConcatFactoryBatchBenchmark.Context initializeContext() {
double current = i / (double) stringCount;
final String value;
if (current < limit) {
value = tainted(context, "Yep, tainted", new Range(3, 5, source(), Range.NOT_MARKED));
value = tainted(context, "Yep, tainted", new Range(3, 5, source(), NOT_MARKED));
} else {
value = notTainted("Nop, tainted");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.datadog.iast.propagation;

import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import com.datadog.iast.IastRequestContext;
import com.datadog.iast.model.Range;
import datadog.trace.api.iast.InstrumentationBridge;
Expand All @@ -13,8 +15,7 @@ public class StringConcatFactoryBenchmark
protected StringConcatFactoryBenchmark.Context initializeContext() {
final IastRequestContext context = new IastRequestContext();
final String notTainted = notTainted("Nop, tainted");
final String tainted =
tainted(context, "Yep, tainted", new Range(3, 5, source(), Range.NOT_MARKED));
final String tainted = tainted(context, "Yep, tainted", new Range(3, 5, source(), NOT_MARKED));
return new StringConcatFactoryBenchmark.Context(context, notTainted, tainted);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.datadog.iast.propagation;

import static com.datadog.iast.model.Range.NOT_MARKED;
import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import com.datadog.iast.IastRequestContext;
import com.datadog.iast.model.Range;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.datadog.iast.propagation;

import static com.datadog.iast.model.Range.NOT_MARKED;
import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import com.datadog.iast.IastRequestContext;
import com.datadog.iast.model.Range;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import datadog.trace.api.gateway.Flow;
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;
Expand All @@ -29,9 +29,9 @@ public class GrpcRequestMessageHandler implements BiFunction<RequestContext, Obj
public Flow<Void> apply(final RequestContext ctx, final Object o) {
final PropagationModule module = InstrumentationBridge.PROPAGATION;
if (module != null && o != null) {
final IastRequestContext iastCtx = ctx.getData(RequestContextSlot.IAST);
final IastContext iastCtx = IastContext.Provider.get(ctx);
module.taintDeeply(
iastCtx, SourceTypes.GRPC_BODY, o, GrpcRequestMessageHandler::isProtobufArtifact);
iastCtx, o, SourceTypes.GRPC_BODY, GrpcRequestMessageHandler::isProtobufArtifact);
}
return Flow.ResultFlow.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import com.datadog.iast.overhead.OverheadContext;
import com.datadog.iast.taint.TaintedObjects;
import datadog.trace.api.gateway.RequestContext;
import datadog.trace.api.gateway.RequestContextSlot;
import datadog.trace.api.iast.IastContext;
import datadog.trace.api.iast.telemetry.IastMetricCollector;
import datadog.trace.api.iast.telemetry.IastMetricCollector.HasMetricCollector;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class IastRequestContext implements HasMetricCollector {
public class IastRequestContext implements IastContext, HasMetricCollector {

private final VulnerabilityBatch vulnerabilityBatch;
private final AtomicBoolean spanDataIsSet;
Expand Down Expand Up @@ -85,6 +85,7 @@ public OverheadContext getOverheadContext() {
return overheadContext;
}

@Nonnull
public TaintedObjects getTaintedObjects() {
return taintedObjects;
}
Expand All @@ -97,22 +98,20 @@ public IastMetricCollector getMetricCollector() {

@Nullable
public static IastRequestContext get() {
return get(AgentTracer.activeSpan());
return asRequestContext(IastContext.Provider.get());
}

@Nullable
public static IastRequestContext get(final AgentSpan span) {
if (span == null) {
return null;
}
return get(span.getRequestContext());
return asRequestContext(IastContext.Provider.get(span));
}

@Nullable
public static IastRequestContext get(final RequestContext reqCtx) {
if (reqCtx == null) {
return null;
}
return reqCtx.getData(RequestContextSlot.IAST);
return asRequestContext(IastContext.Provider.get(reqCtx));
}

private static IastRequestContext asRequestContext(final IastContext ctx) {
return ctx instanceof IastRequestContext ? (IastRequestContext) ctx : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.datadog.iast.sink.XContentTypeModuleImpl;
import com.datadog.iast.sink.XPathInjectionModuleImpl;
import com.datadog.iast.sink.XssModuleImpl;
import com.datadog.iast.source.WebModuleImpl;
import com.datadog.iast.telemetry.TelemetryRequestEndedHandler;
import com.datadog.iast.telemetry.TelemetryRequestStartedHandler;
import datadog.trace.api.Config;
Expand Down Expand Up @@ -90,7 +89,6 @@ private static Consumer<IastModule> registerModule(final Dependencies dependenci

private static Stream<IastModule> iastModules() {
return Stream.of(
new WebModuleImpl(),
new StringModuleImpl(),
new FastCodecModule(),
new SqlInjectionModuleImpl(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.datadog.iast.model;

import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import com.datadog.iast.model.json.SourceIndex;
import com.datadog.iast.util.Ranged;
import java.util.Objects;
Expand All @@ -9,8 +11,6 @@

public final class Range implements Ranged {

public static final int NOT_MARKED = 0;

private final @Nonnegative int start;
private final @Nonnegative int length;
private final @Nonnull @SourceIndex Source source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public final class Source implements Taintable.Source {
private final String name;
private final String value;

public Source(final byte origin, final CharSequence name, final CharSequence value) {
this(origin, name == null ? null : name.toString(), value == null ? null : value.toString());
}

public Source(final byte origin, final String name, final String value) {
this.origin = origin;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.datadog.iast.model;

import static com.datadog.iast.model.Range.NOT_MARKED;
import static datadog.trace.api.iast.VulnerabilityMarks.NOT_MARKED;

import datadog.trace.api.iast.VulnerabilityMarks;
import datadog.trace.api.iast.VulnerabilityTypes;
Expand Down
Loading

0 comments on commit b68b8f0

Please sign in to comment.