From d3b72f7aea8c8f7bf9757e97577ac222f5cd2006 Mon Sep 17 00:00:00 2001 From: Behnam Mozafari Date: Wed, 18 Nov 2026 11:49:12 +1100 Subject: [PATCH 1/5] UID2-8289: Use Core-provided opt-out URL host for opt-out downloads Add UidOptOutClient.buildOptOutUrl, which takes the scheme, host and port from the Core-provided opt-out URL and only the path and query from the configured location. Co-Authored-By: Claude Opus 5.5 --- .../uid2/shared/attest/UidOptOutClient.java | 29 +++++++++++++++++-- .../shared/attest/UidOptOutClientTest.java | 4 +++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java index a0c4e98d..1731382b 100644 --- a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java +++ b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java @@ -9,6 +9,8 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.Proxy; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; public class UidOptOutClient extends UidCoreClient { @@ -45,8 +47,7 @@ public InputStream download(String path) throws CloudStorageException { if (this.attestationResponseHandler.getOptOutUrl() != null) { try { - URL baseUrl = new URL(this.attestationResponseHandler.getOptOutUrl()); - URL fullUrl = new URL(baseUrl, path); + URL fullUrl = buildOptOutUrl(this.attestationResponseHandler.getOptOutUrl(), path); return super.download(fullUrl.toExternalForm()); } catch (MalformedURLException e) { LOGGER.error("Unable to parse OptOut URL", e); @@ -60,4 +61,28 @@ public InputStream download(String path) throws CloudStorageException { return InputStream.nullInputStream(); } + + /** + * Builds an opt-out URL from the scheme, host and port of {@code optOutBaseUrl} and only the path and query of + * {@code configuredLocation}, so the host always comes from the base URL. + */ + public static URL buildOptOutUrl(String optOutBaseUrl, String configuredLocation) throws MalformedURLException { + URL base = new URL(optOutBaseUrl); + String pathAndQuery = ""; + if (configuredLocation != null && !configuredLocation.isEmpty()) { + URI location; + try { + location = new URI(configuredLocation); + } catch (URISyntaxException e) { + throw new MalformedURLException("Invalid opt-out path"); + } + if (location.getRawPath() != null) { + pathAndQuery = location.getRawPath(); + } + if (location.getRawQuery() != null) { + pathAndQuery += "?" + location.getRawQuery(); + } + } + return new URL(base.getProtocol(), base.getHost(), base.getPort(), pathAndQuery); + } } diff --git a/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java b/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java index f9548596..2d760bd0 100644 --- a/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java +++ b/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java @@ -57,6 +57,10 @@ void getJwtReturnsOptOutToken() { "/path1/path2?var=3;https://core.example.com/path1/path2?var=3", ";https://core.example.com", "/;https://core.example.com/", + "https://other.example/optout/refresh?x=1;https://core.example.com/optout/refresh?x=1", + "http://other.example:8081/optout/replicate;https://core.example.com/optout/replicate", + "//other.example/x;https://core.example.com/x", + "https://a//other.example/x;https://core.example.com//other.example/x", }, delimiter = ';') void usesOptOutUrlForDownloadWithPath(String path, String expectedFullPath) throws CloudStorageException, IOException { HttpResponse mockHttpResponse = mock(HttpResponse.class); From dfb059efb4bff8a512f7d1b43dfb559f4c33b393 Mon Sep 17 00:00:00 2001 From: Behnam Mozafari Date: Wed, 18 Nov 2026 11:53:22 +1100 Subject: [PATCH 2/5] UID2-8289: Normalise relative opt-out paths and reject opaque locations Co-Authored-By: Claude Opus 5.5 --- .../com/uid2/shared/attest/UidOptOutClient.java | 8 ++++++-- .../uid2/shared/attest/UidOptOutClientTest.java | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java index 1731382b..39f9a05a 100644 --- a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java +++ b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java @@ -74,10 +74,14 @@ public static URL buildOptOutUrl(String optOutBaseUrl, String configuredLocation try { location = new URI(configuredLocation); } catch (URISyntaxException e) { + throw (MalformedURLException) new MalformedURLException("Invalid opt-out path").initCause(e); + } + if (location.isOpaque()) { throw new MalformedURLException("Invalid opt-out path"); } - if (location.getRawPath() != null) { - pathAndQuery = location.getRawPath(); + String rawPath = location.getRawPath(); + if (rawPath != null && !rawPath.isEmpty()) { + pathAndQuery = rawPath.startsWith("/") ? rawPath : "/" + rawPath; } if (location.getRawQuery() != null) { pathAndQuery += "?" + location.getRawQuery(); diff --git a/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java b/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java index 2d760bd0..03200360 100644 --- a/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java +++ b/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java @@ -36,6 +36,7 @@ public void close() { @BeforeEach void setUp() { + reset(mockedLogger); mockedLoggerFactory = mockStatic(LoggerFactory.class); mockedLoggerFactory.when(() -> LoggerFactory.getLogger(any(Class.class))).thenReturn(mockedLogger); @@ -61,6 +62,9 @@ void getJwtReturnsOptOutToken() { "http://other.example:8081/optout/replicate;https://core.example.com/optout/replicate", "//other.example/x;https://core.example.com/x", "https://a//other.example/x;https://core.example.com//other.example/x", + "optout/refresh;https://core.example.com/optout/refresh", + "other.example/x;https://core.example.com/other.example/x", + "?x=1;https://core.example.com?x=1", }, delimiter = ';') void usesOptOutUrlForDownloadWithPath(String path, String expectedFullPath) throws CloudStorageException, IOException { HttpResponse mockHttpResponse = mock(HttpResponse.class); @@ -88,12 +92,17 @@ void returnsEmptyStreamWhenNoOptOutUrl() throws CloudStorageException, IOExcepti verify(mockedLogger).warn("UidOptOutClient attempting to download but OptOutUrl not available"); } - @Test - void returnsEmptyStreamWhenMalformedUrl() throws CloudStorageException, IOException { + @ParameterizedTest + @CsvSource(value = { + "nowhere;/path", + "https://core.example.com;other.example:8081/path", + "https://core.example.com;/path with space", + }, delimiter = ';') + void returnsEmptyStreamWhenMalformedUrl(String optOutUrl, String path) throws CloudStorageException, IOException { when(mockAttestationResponseHandler.attested()).thenReturn(true); - when(mockAttestationResponseHandler.getOptOutUrl()).thenReturn("nowhere"); + when(mockAttestationResponseHandler.getOptOutUrl()).thenReturn(optOutUrl); - InputStream is = this.optOutClient.download("/path"); + InputStream is = this.optOutClient.download(path); assertEquals(0, is.available()); verify(mockedLogger).error(eq("Unable to parse OptOut URL"), any(MalformedURLException.class)); } From e30cb4ab72f36295a49f65bf3cb016e672773761 Mon Sep 17 00:00:00 2001 From: Behnam Mozafari Date: Wed, 18 Nov 2026 11:58:25 +1100 Subject: [PATCH 3/5] UID2-8289: Trim configured opt-out path and avoid logging it on parse errors Co-Authored-By: Claude Opus 5.5 --- .../uid2/shared/attest/UidOptOutClient.java | 4 +-- .../shared/attest/UidOptOutClientTest.java | 26 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java index 39f9a05a..3381d95c 100644 --- a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java +++ b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java @@ -72,9 +72,9 @@ public static URL buildOptOutUrl(String optOutBaseUrl, String configuredLocation if (configuredLocation != null && !configuredLocation.isEmpty()) { URI location; try { - location = new URI(configuredLocation); + location = new URI(configuredLocation.trim()); } catch (URISyntaxException e) { - throw (MalformedURLException) new MalformedURLException("Invalid opt-out path").initCause(e); + throw new MalformedURLException("Invalid opt-out path: " + e.getReason() + " at index " + e.getIndex()); } if (location.isOpaque()) { throw new MalformedURLException("Invalid opt-out path"); diff --git a/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java b/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java index 03200360..89fc4cce 100644 --- a/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java +++ b/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java @@ -55,18 +55,20 @@ void getJwtReturnsOptOutToken() { @ParameterizedTest @CsvSource(value = { - "/path1/path2?var=3;https://core.example.com/path1/path2?var=3", - ";https://core.example.com", - "/;https://core.example.com/", - "https://other.example/optout/refresh?x=1;https://core.example.com/optout/refresh?x=1", - "http://other.example:8081/optout/replicate;https://core.example.com/optout/replicate", - "//other.example/x;https://core.example.com/x", - "https://a//other.example/x;https://core.example.com//other.example/x", - "optout/refresh;https://core.example.com/optout/refresh", - "other.example/x;https://core.example.com/other.example/x", - "?x=1;https://core.example.com?x=1", + "https://core.example.com;/path1/path2?var=3;https://core.example.com/path1/path2?var=3", + "https://core.example.com;;https://core.example.com", + "https://core.example.com;/;https://core.example.com/", + "https://core.example.com;https://other.example/optout/refresh?x=1;https://core.example.com/optout/refresh?x=1", + "https://core.example.com;http://other.example:8081/optout/replicate;https://core.example.com/optout/replicate", + "https://core.example.com;//other.example/x;https://core.example.com/x", + "https://core.example.com;https://a//other.example/x;https://core.example.com//other.example/x", + "https://core.example.com;optout/refresh;https://core.example.com/optout/refresh", + "https://core.example.com;other.example/x;https://core.example.com/other.example/x", + "https://core.example.com;?x=1;https://core.example.com?x=1", + "http://localhost:8081;https://other.example/optout/refresh;http://localhost:8081/optout/refresh", + "https://core.example.com;' /optout/refresh ';https://core.example.com/optout/refresh", }, delimiter = ';') - void usesOptOutUrlForDownloadWithPath(String path, String expectedFullPath) throws CloudStorageException, IOException { + void usesOptOutUrlForDownloadWithPath(String optOutUrl, String path, String expectedFullPath) throws CloudStorageException, IOException { HttpResponse mockHttpResponse = mock(HttpResponse.class); String expectedResponseBody = "Hello, world!"; when(mockHttpResponse.body()).thenReturn(expectedResponseBody); @@ -75,7 +77,7 @@ void usesOptOutUrlForDownloadWithPath(String path, String expectedFullPath) thro when(mockAttestationResponseHandler.attested()).thenReturn(true); when(mockAttestationResponseHandler.getAttestationToken()).thenReturn("testAttToken"); - when(mockAttestationResponseHandler.getOptOutUrl()).thenReturn("https://core.example.com"); + when(mockAttestationResponseHandler.getOptOutUrl()).thenReturn(optOutUrl); InputStream is = this.optOutClient.download(path); verify(mockAttestationResponseHandler, times(2)).getOptOutUrl(); From cdb1a19e88fe90587de0415e2f1288dea8af6b45 Mon Sep 17 00:00:00 2001 From: Behnam Mozafari Date: Wed, 18 Nov 2026 12:03:13 +1100 Subject: [PATCH 4/5] UID2-8289: Reject non-HTTP opt-out locations and normalise query-only paths Co-Authored-By: Claude Opus 5.5 --- src/main/java/com/uid2/shared/attest/UidOptOutClient.java | 4 ++-- src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java index 3381d95c..751aa55b 100644 --- a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java +++ b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java @@ -76,7 +76,7 @@ public static URL buildOptOutUrl(String optOutBaseUrl, String configuredLocation } catch (URISyntaxException e) { throw new MalformedURLException("Invalid opt-out path: " + e.getReason() + " at index " + e.getIndex()); } - if (location.isOpaque()) { + if (location.isOpaque() || (location.getScheme() != null && !location.getScheme().matches("(?i)https?"))) { throw new MalformedURLException("Invalid opt-out path"); } String rawPath = location.getRawPath(); @@ -84,7 +84,7 @@ public static URL buildOptOutUrl(String optOutBaseUrl, String configuredLocation pathAndQuery = rawPath.startsWith("/") ? rawPath : "/" + rawPath; } if (location.getRawQuery() != null) { - pathAndQuery += "?" + location.getRawQuery(); + pathAndQuery = (pathAndQuery.isEmpty() ? "/" : pathAndQuery) + "?" + location.getRawQuery(); } } return new URL(base.getProtocol(), base.getHost(), base.getPort(), pathAndQuery); diff --git a/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java b/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java index 89fc4cce..f0c66c75 100644 --- a/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java +++ b/src/test/java/com/uid2/shared/attest/UidOptOutClientTest.java @@ -64,7 +64,7 @@ void getJwtReturnsOptOutToken() { "https://core.example.com;https://a//other.example/x;https://core.example.com//other.example/x", "https://core.example.com;optout/refresh;https://core.example.com/optout/refresh", "https://core.example.com;other.example/x;https://core.example.com/other.example/x", - "https://core.example.com;?x=1;https://core.example.com?x=1", + "https://core.example.com;?x=1;https://core.example.com/?x=1", "http://localhost:8081;https://other.example/optout/refresh;http://localhost:8081/optout/refresh", "https://core.example.com;' /optout/refresh ';https://core.example.com/optout/refresh", }, delimiter = ';') @@ -99,6 +99,7 @@ void returnsEmptyStreamWhenNoOptOutUrl() throws CloudStorageException, IOExcepti "nowhere;/path", "https://core.example.com;other.example:8081/path", "https://core.example.com;/path with space", + "https://core.example.com;file:/tmp/optout/refresh", }, delimiter = ';') void returnsEmptyStreamWhenMalformedUrl(String optOutUrl, String path) throws CloudStorageException, IOException { when(mockAttestationResponseHandler.attested()).thenReturn(true); From 995a960a0766af07a73f4b6b47ffcaa8badb16ed Mon Sep 17 00:00:00 2001 From: Behnam Mozafari Date: Wed, 18 Nov 2026 12:07:09 +1100 Subject: [PATCH 5/5] UID2-8289: Avoid regex in opt-out scheme check Co-Authored-By: Claude Opus 5.5 --- src/main/java/com/uid2/shared/attest/UidOptOutClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java index 751aa55b..0e637748 100644 --- a/src/main/java/com/uid2/shared/attest/UidOptOutClient.java +++ b/src/main/java/com/uid2/shared/attest/UidOptOutClient.java @@ -76,7 +76,8 @@ public static URL buildOptOutUrl(String optOutBaseUrl, String configuredLocation } catch (URISyntaxException e) { throw new MalformedURLException("Invalid opt-out path: " + e.getReason() + " at index " + e.getIndex()); } - if (location.isOpaque() || (location.getScheme() != null && !location.getScheme().matches("(?i)https?"))) { + String scheme = location.getScheme(); + if (location.isOpaque() || (scheme != null && !"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme))) { throw new MalformedURLException("Invalid opt-out path"); } String rawPath = location.getRawPath();