Skip to content

Commit 7661a2e

Browse files
committed
URI resolution fix in AuthorizationFilter
Test fixes
1 parent f6e0f72 commit 7661a2e

5 files changed

Lines changed: 28 additions & 8 deletions

File tree

http-tests/document-hierarchy/PATCH-non-existing-403.sh renamed to http-tests/document-hierarchy/PATCH-404.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ curl -k -w "%{http_code}\n" -o /dev/null -s \
3737
"${END_USER_BASE_URL}non-existing/" \
3838
--data-binary "$update"
3939
) \
40-
| grep -q "$STATUS_FORBIDDEN"
40+
| grep -q "$STATUS_NOT_FOUND"

http-tests/document-hierarchy/PATCH-empty-item.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ curl -k -w "%{http_code}\n" -o /dev/null -s \
5555
-E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \
5656
-H "Accept: application/n-triples" \
5757
"$item" \
58-
| grep -q "$STATUS_FORBIDDEN"
58+
| grep -q "$STATUS_NOT_FOUND"

http-tests/document-hierarchy/POST-404.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ curl -k -w "%{http_code}\n" -o /dev/null -s \
2727
<http://s> <http://p> <http://o> .
2828
EOF
2929
) \
30-
| grep -q "$STATUS_NOT_FOUND"
30+
| grep -q "$STATUS_NOT_FOUND"

http-tests/document-hierarchy/PUT-no-slash-308.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ purge_cache "$END_USER_VARNISH_SERVICE"
77
purge_cache "$ADMIN_VARNISH_SERVICE"
88
purge_cache "$FRONTEND_VARNISH_SERVICE"
99

10+
# add agent to the writers group
11+
12+
add-agent-to-group.sh \
13+
-f "$OWNER_CERT_FILE" \
14+
-p "$OWNER_CERT_PWD" \
15+
--agent "$AGENT_URI" \
16+
"${ADMIN_BASE_URL}acl/groups/writers/"
17+
18+
# create test container
19+
20+
container=$(create-container.sh \
21+
-f "$AGENT_CERT_FILE" \
22+
-p "$AGENT_CERT_PWD" \
23+
-b "$END_USER_BASE_URL" \
24+
--title "Test Container" \
25+
--slug "test-container" \
26+
--parent "$END_USER_BASE_URL")
27+
1028
# add an explicit read/write authorization for the parent since the child document will inherit it
1129

1230
create-authorization.sh \
@@ -15,14 +33,14 @@ create-authorization.sh \
1533
-p "$OWNER_CERT_PWD" \
1634
--label "Write base" \
1735
--agent "$AGENT_URI" \
18-
--to "$END_USER_BASE_URL" \
36+
--to "$container" \
1937
--read \
2038
--write
2139

22-
invalid_item="${END_USER_BASE_URL}no-slash"
23-
2440
# check URI without trailing slash gets redirected
2541

42+
invalid_item="${container}no-slash"
43+
2644
(
2745
curl -k -w "%{http_code}\n" -o /dev/null -s \
2846
-E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \

src/main/java/com/atomgraph/linkeddatahub/server/filter/request/AuthorizationFilter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import jakarta.ws.rs.container.ContainerRequestFilter;
4444
import jakarta.ws.rs.container.PreMatching;
4545
import jakarta.ws.rs.core.Response;
46-
import java.net.URI;
46+
import org.apache.jena.irix.IRIx;
4747
import java.util.HashSet;
4848
import java.util.Set;
4949
import org.apache.jena.query.ParameterizedSparqlString;
@@ -170,7 +170,9 @@ public Model authorize(ContainerRequestContext request, Resource agent, Resource
170170
// special case for PUT requests to non-existing document: allow if the agent has acl:Write acess to the *parent* URI
171171
if (request.getMethod().equals(HttpMethod.PUT) && accessMode.equals(ACL.Write))
172172
{
173-
URI parentURI = URI.create(accessTo.getURI()).resolve("..");
173+
// Use Jena's IRIx for RFC 3986-compliant resolution - java.net.URI.resolve("..") is non-compliant
174+
// (RFC 3986 section 5.2.4 step 2D requires ".." to be removed, but java.net.URI leaves it literal)
175+
IRIx parentURI = IRIx.create(accessTo.getURI()).resolve("..");
174176
Resource parent = ResourceFactory.createResource(parentURI.toString());
175177
log.debug("Requested document <{}> not found, falling back to parent URI <{}>", parent, parentURI);
176178

0 commit comments

Comments
 (0)