Skip to content

Commit 9e45c8a

Browse files
committed
URLValidator usage fix
1 parent 745fc5d commit 9e45c8a

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

http-tests/proxy/GET-proxied-internal-403.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ add-agent-to-group.sh \
1717

1818
# LNK-009: Test that internal Docker services are blocked via SSRF protection
1919
# Attempt to access the internal fuseki-admin SPARQL endpoint via the proxy
20-
# This should be blocked and return 403 Forbidden
20+
# This should be blocked and return 400 Bad Request
2121

2222
http_status=$(curl -k -s -o /dev/null -w "%{http_code}" \
2323
-G \
@@ -26,8 +26,8 @@ http_status=$(curl -k -s -o /dev/null -w "%{http_code}" \
2626
--data-urlencode "uri=http://fuseki-admin:3030/ds" \
2727
"$END_USER_BASE_URL" || true)
2828

29-
# Verify that access was forbidden (403)
30-
if [ "$http_status" != "403" ]; then
31-
echo "Expected HTTP 403 Forbidden for internal service access, got: $http_status"
29+
# Verify that access was rejected (400)
30+
if [ "$http_status" != "400" ]; then
31+
echo "Expected HTTP 400 Bad Request for internal service access, got: $http_status"
3232
exit 1
3333
fi

http-tests/proxy/GET-proxied-rfc1918-403.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ http_status=$(curl -k -s -o /dev/null -w "%{http_code}" \
2525
--data-urlencode "uri=http://10.0.0.1:8080/test" \
2626
"$END_USER_BASE_URL" || true)
2727

28-
if [ "$http_status" != "403" ]; then
29-
echo "Expected HTTP 403 Forbidden for 10.0.0.1 access, got: $http_status"
28+
if [ "$http_status" != "400" ]; then
29+
echo "Expected HTTP 400 Bad Request for 10.0.0.1 access, got: $http_status"
3030
exit 1
3131
fi
3232

@@ -39,8 +39,8 @@ http_status=$(curl -k -s -o /dev/null -w "%{http_code}" \
3939
--data-urlencode "uri=http://172.16.0.1:8080/test" \
4040
"$END_USER_BASE_URL" || true)
4141

42-
if [ "$http_status" != "403" ]; then
43-
echo "Expected HTTP 403 Forbidden for 172.16.0.1 access, got: $http_status"
42+
if [ "$http_status" != "400" ]; then
43+
echo "Expected HTTP 400 Bad Request for 172.16.0.1 access, got: $http_status"
4444
exit 1
4545
fi
4646

@@ -53,7 +53,7 @@ http_status=$(curl -k -s -o /dev/null -w "%{http_code}" \
5353
--data-urlencode "uri=http://192.168.1.1:8080/test" \
5454
"$END_USER_BASE_URL" || true)
5555

56-
if [ "$http_status" != "403" ]; then
57-
echo "Expected HTTP 403 Forbidden for 192.168.1.1 access, got: $http_status"
56+
if [ "$http_status" != "400" ]; then
57+
echo "Expected HTTP 400 Bad Request for 192.168.1.1 access, got: $http_status"
5858
exit 1
5959
fi

src/main/java/com/atomgraph/linkeddatahub/server/model/impl/ProxiedGraph.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ protected ProxiedGraph(@Context UriInfo uriInfo, @Context Request request, @Cont
165165
{
166166
super(uriInfo, request, httpHeaders, mediaTypes, uri, endpoint, query, accept, mode, system.getExternalClient(), httpServletRequest);
167167

168-
// LNK-009: Validate that proxied URI is not internal/private (SSRF protection)
169-
if (uri != null) new URLValidator(uri).validate();
170-
171168
this.uriInfo = uriInfo;
172169
this.application = application;
173170
this.service = service.get();
@@ -311,6 +308,8 @@ public Response get(WebTarget target, Invocation.Builder builder)
311308
}
312309

313310
if (!getSystem().isEnableLinkedDataProxy()) throw new NotAllowedException("Linked Data proxy not enabled");
311+
// LNK-009: Validate that proxied URI is not internal/private (SSRF protection)
312+
new URLValidator(target.getUri()).validate();
314313

315314
return super.get(target, builder);
316315
}
@@ -326,6 +325,8 @@ public Response get(WebTarget target, Invocation.Builder builder)
326325
public Response post(String sparqlQuery)
327326
{
328327
if (getWebTarget() == null) throw new NotFoundException("Resource URI not supplied");
328+
// LNK-009: Validate that proxied URI is not internal/private (SSRF protection)
329+
new URLValidator(getWebTarget().getUri()).validate();
329330

330331
if (log.isDebugEnabled()) log.debug("POSTing SPARQL query to URI: {}", getWebTarget().getUri());
331332

@@ -358,6 +359,8 @@ public Response post(String sparqlQuery)
358359
public Response postForm(String formData)
359360
{
360361
if (getWebTarget() == null) throw new NotFoundException("Resource URI not supplied");
362+
// LNK-009: Validate that proxied URI is not internal/private (SSRF protection)
363+
new URLValidator(getWebTarget().getUri()).validate();
361364

362365
if (log.isDebugEnabled()) log.debug("POSTing form data to URI: {}", getWebTarget().getUri());
363366

@@ -390,6 +393,8 @@ public Response postForm(String formData)
390393
public Response patch(String sparqlUpdate)
391394
{
392395
if (getWebTarget() == null) throw new NotFoundException("Resource URI not supplied");
396+
// LNK-009: Validate that proxied URI is not internal/private (SSRF protection)
397+
new URLValidator(getWebTarget().getUri()).validate();
393398

394399
if (log.isDebugEnabled()) log.debug("PATCHing SPARQL update to URI: {}", getWebTarget().getUri());
395400

@@ -423,6 +428,8 @@ public Response postMultipart(FormDataMultiPart multiPart)
423428
{
424429
if (!getSystem().isEnableLinkedDataProxy()) throw new NotAllowedException("Linked Data proxy not enabled");
425430
if (getWebTarget() == null) throw new NotFoundException("Resource URI not supplied"); // cannot throw Exception in constructor: https://github.com/eclipse-ee4j/jersey/issues/4436
431+
// LNK-009: Validate that proxied URI is not internal/private (SSRF protection)
432+
new URLValidator(getWebTarget().getUri()).validate();
426433

427434
try (Response cr = getWebTarget().request().
428435
accept(getMediaTypes().getReadable(Model.class).toArray(jakarta.ws.rs.core.MediaType[]::new)).
@@ -445,6 +452,8 @@ public Response putMultipart(FormDataMultiPart multiPart)
445452
{
446453
if (!getSystem().isEnableLinkedDataProxy()) throw new NotAllowedException("Linked Data proxy not enabled");
447454
if (getWebTarget() == null) throw new NotFoundException("Resource URI not supplied"); // cannot throw Exception in constructor: https://github.com/eclipse-ee4j/jersey/issues/4436
455+
// LNK-009: Validate that proxied URI is not internal/private (SSRF protection)
456+
new URLValidator(getWebTarget().getUri()).validate();
448457

449458
try (Response cr = getWebTarget().request().
450459
accept(getMediaTypes().getReadable(Model.class).toArray(jakarta.ws.rs.core.MediaType[]::new)).

0 commit comments

Comments
 (0)