GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add propagation to URI#toURL method by manuel-alvarez-alvarez · Pull Request #8146 · DataDog/dd-trace-java

Add propagation to URI#toURL method #8146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
manuel-alvarez-alvarez merged 1 commit into master from malvarez/iast-uri-to-url
Jan 8, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Add propagation to URI#toURL method #8146

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
5bf9991
Add propagation to URI#toURL method
manuel-alvarez-alvarez Jan 3, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

16 changes: 16 additions & 0 deletions 16 ...umentation/java-net/src/main/java/datadog/trace/instrumentation/java/net/URICallSite.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import datadog.trace.api.iast.propagation.CodecModule;
import datadog.trace.api.iast.propagation.PropagationModule;
import java.net.URI;
import java.net.URL;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -105,4 +106,19 @@ public static URI afterNormalize(
}
return result;
}

@Propagation
@CallSite.After("java.net.URL java.net.URI.toURL()")
public static URL afterToURL(@CallSite.This final URI uri, @CallSite.Return final URL result) {
final PropagationModule module = InstrumentationBridge.PROPAGATION;
if (module != null && result != null) {
try {
boolean keepRanges = uri.toString().equals(result.toString());
module.taintObjectIfTainted(result, uri, keepRanges, NOT_MARKED);
} catch (final Throwable e) {
module.onUnexpectedException("After toURL threw", e);
}
}
return result;
}
}
1 change: 1 addition & 0 deletions 1 ...on/java-net/src/test/groovy/datadog/trace/instrumentation/java/net/URICallSIteTest.groovy
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ class URICallSIteTest extends AgentTestRunner {
'toASCIIString' | 'String' | [new URI('http://test.com/index?name=value#fragment')] | true
'toASCIIString' | 'String' | [new URI('http://test.com/漢/index?name=value#fragment')] | false
'toString' | 'String' | [new URI('http://test.com/index?name=value#fragment')] | true
'toURL' | 'Object' | [new URI('http://test.com/index?name=value#fragment')] | true
}
}
9 changes: 9 additions & 0 deletions 9 dd-java-agent/instrumentation/java-net/src/test/java/foo/bar/TestURICallSiteSuite.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package foo.bar;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -105,4 +107,11 @@ public static String toASCIIString(final URI uri) {
LOGGER.debug("After toAsciiString {}", result);
return result;
}

public static URL toURL(final URI uri) throws MalformedURLException {
LOGGER.debug("Before toURL {}", uri);
final URL result = uri.toURL();
LOGGER.debug("After toURL {}", result);
return result;
}
}
5 changes: 5 additions & 0 deletions 5 ...tion/vertx-rx-3.5/src/test/groovy/server/VertxRxCircuitBreakerHttpServerForkedTest.groovy
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class VertxRxCircuitBreakerHttpServerForkedTest extends VertxHttpServerForkedTes
false
}

@Override
boolean testSessionId() {
false
}

static class VertxRxCircuitBreakerWebTestServer extends AbstractVerticle {

@Override
Expand Down
16 changes: 16 additions & 0 deletions 16 ...tests/iast-util/src/main/java/datadog/smoketest/springboot/controller/SsrfController.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
Expand Down Expand Up @@ -39,6 +40,21 @@ public String ssrf(
return "ok";
}

@PostMapping("/uri")
public String uri(
@RequestParam(value = "url", required = false) final String url,
@RequestParam(value = "host", required = false) final String host) {
try {
final URI uri =
url != null ? new URI(url) : new URI("https", null, host, 443, "/test", null, null);
final URL target = uri.toURL();
final HttpURLConnection conn = (HttpURLConnection) target.openConnection();
conn.disconnect();
} catch (final Exception e) {
}
return "ok";
}

@PostMapping("/apache-httpclient4")
public String apacheHttpClient4(
@RequestParam(value = "url", required = false) final String url,
Expand Down
10 changes: 6 additions & 4 deletions 10 ...sts/iast-util/src/testFixtures/groovy/datadog/smoketest/AbstractIastSpringBootTest.groovy
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ abstract class AbstractIastSpringBootTest extends AbstractIastServerSmokeTest {

void 'ssrf is present'() {
setup:
final url = "http://localhost:${httpPort}/ssrf"
final url = "http://localhost:${httpPort}/ssrf${path}"
final body = new FormBody.Builder().add(parameter, value).build()
final request = new Request.Builder().url(url).post(body).build()

Expand All @@ -715,9 +715,11 @@ abstract class AbstractIastSpringBootTest extends AbstractIastServerSmokeTest {
}

where:
parameter | value
'url' | 'https://dd.datad0g.com/'
'host' | 'dd.datad0g.com'
path | parameter | value
'' | 'url' | 'https://dd.datad0g.com/'
'' | 'host' | 'dd.datad0g.com'
'/uri' | 'url' | 'https://dd.datad0g.com/'
'/uri' | 'host' | 'dd.datad0g.com'
}

void 'ssrf is present (#path) (#parameter)'() {
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.