|
| 1 | +package datadog.smoketest |
| 2 | + |
| 3 | +import okhttp3.FormBody |
| 4 | +import okhttp3.Request |
| 5 | + |
| 6 | +import static datadog.trace.api.config.IastConfig.IAST_DEBUG_ENABLED |
| 7 | +import static datadog.trace.api.config.IastConfig.IAST_DETECTION_MODE |
| 8 | +import static datadog.trace.api.config.IastConfig.IAST_ENABLED |
| 9 | + |
| 10 | +abstract class AbstractIast11SpringBootTest extends AbstractIastServerSmokeTest { |
| 11 | + |
| 12 | + @Override |
| 13 | + ProcessBuilder createProcessBuilder() { |
| 14 | + String springBootShadowJar = System.getProperty('datadog.smoketest.springboot.shadowJar.path') |
| 15 | + |
| 16 | + List<String> command = [] |
| 17 | + command.add(javaPath()) |
| 18 | + command.addAll(defaultJavaProperties) |
| 19 | + command.addAll(iastJvmOpts()) |
| 20 | + command.addAll((String[]) ['-jar', springBootShadowJar, "--server.port=${httpPort}"]) |
| 21 | + ProcessBuilder processBuilder = new ProcessBuilder(command) |
| 22 | + processBuilder.directory(new File(buildDirectory)) |
| 23 | + // Spring will print all environment variables to the log, which may pollute it and affect log assertions. |
| 24 | + processBuilder.environment().clear() |
| 25 | + return processBuilder |
| 26 | + } |
| 27 | + |
| 28 | + protected List<String> iastJvmOpts() { |
| 29 | + return [ |
| 30 | + withSystemProperty(IAST_ENABLED, true), |
| 31 | + withSystemProperty(IAST_DETECTION_MODE, 'FULL'), |
| 32 | + withSystemProperty(IAST_DEBUG_ENABLED, true), |
| 33 | + ] |
| 34 | + } |
| 35 | + |
| 36 | + void 'ssrf is present (#path)'() { |
| 37 | + setup: |
| 38 | + final url = "http://localhost:${httpPort}/ssrf/${path}" |
| 39 | + final body = new FormBody.Builder() |
| 40 | + .add(parameter, value) |
| 41 | + .add("async", async) |
| 42 | + .add("promise", promise).build() |
| 43 | + final request = new Request.Builder().url(url).post(body).build() |
| 44 | +
|
| 45 | + when: |
| 46 | + client.newCall(request).execute() |
| 47 | +
|
| 48 | + then: |
| 49 | + hasVulnerability { vul -> |
| 50 | + if (vul.type != 'SSRF') { |
| 51 | + return false |
| 52 | + } |
| 53 | + final parts = vul.evidence.valueParts |
| 54 | + if (parameter == 'url') { |
| 55 | + return parts.size() == 1 |
| 56 | + && parts[0].value == value && parts[0].source.origin == 'http.request.parameter' && parts[0].source.name == parameter |
| 57 | + } else { |
| 58 | + throw new IllegalArgumentException("Parameter $parameter not supported") |
| 59 | + } |
| 60 | + } |
| 61 | +
|
| 62 | + where: |
| 63 | + path | parameter | value | async | promise |
| 64 | + "java-net" | "url" | "https://dd.datad0g.com/" | "false" | "false" |
| 65 | + "java-net" | "url" | "https://dd.datad0g.com/" | "true" | "false" |
| 66 | + "java-net" | "url" | "https://dd.datad0g.com/" | "true" | "true" |
| 67 | + } |
| 68 | +} |
0 commit comments