Skip to content

Commit

Permalink
Refactor UntrustedDeserializationModule call to onObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariovido committed Aug 21, 2024
1 parent 99cfdba commit e79cb51
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.datadog.iast.Dependencies;
import com.datadog.iast.model.VulnerabilityType;
import datadog.trace.api.iast.sink.UntrustedDeserializationModule;
import java.io.InputStream;
import javax.annotation.Nullable;

public class UntrustedDeserializationModuleImpl extends SinkModuleBase
Expand All @@ -14,10 +13,10 @@ public UntrustedDeserializationModuleImpl(final Dependencies dependencies) {
}

@Override
public void onInputStream(@Nullable InputStream is) {
if (is == null) {
public void onObject(@Nullable Object object) {
if (object == null) {
return;
}
checkInjection(VulnerabilityType.UNTRUSTED_DESERIALIZATION, is);
checkInjection(VulnerabilityType.UNTRUSTED_DESERIALIZATION, object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ class UntrustedDeserializationModuleTest extends IastModuleImplTestBase {
return Mock(Reporter)
}

void 'test null value'() {
void 'test null value with object null'() {
when:
module.onInputStream(null)
module.onObject(null)

then:
0 * _
}

void 'test untrusted deserialization detection' () {
setup:
def inputStream = Mock(InputStream)
def object = Mock(Object)

when:
module.onInputStream(inputStream)
module.onObject(object)

then: 'without tainted input stream'
then: 'without tainted object'
0 * reporter.report(_, _)

when:
taint(inputStream)
module.onInputStream(inputStream)
taint(object)
module.onObject(object)

then: 'with tainted input stream'
then: 'with tainted object'
1 * reporter.report(_, { Vulnerability vul -> vul.type == VulnerabilityType.UNTRUSTED_DESERIALIZATION})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void beforeConstructorUntrusted(@CallSite.Argument(0) final InputS

if (module != null) {
try {
module.onInputStream(is);
module.onObject(is);
} catch (Throwable e) {
module.onUnexpectedException("before constructor untrusted threw", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ObjectInputStreamCallSiteTest extends AgentTestRunner {
injectSysConfig('dd.iast.enabled', 'true')
}

void 'test onInputStream'() {
void 'test onObject'() {
setup:
final module = Mock(UntrustedDeserializationModule)
InstrumentationBridge.registerIastModule(module)
Expand All @@ -23,6 +23,6 @@ class ObjectInputStreamCallSiteTest extends AgentTestRunner {
TestObjectInputStreamSuite.init(inputStream)

then:
1 * module.onInputStream(_)
1 * module.onObject(_)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package datadog.trace.api.iast.sink;

import datadog.trace.api.iast.IastModule;
import java.io.InputStream;
import javax.annotation.Nullable;

public interface UntrustedDeserializationModule extends IastModule {

void onInputStream(@Nullable InputStream is);
void onObject(@Nullable Object object);
}

0 comments on commit e79cb51

Please sign in to comment.