Skip to content

Commit 8714801

Browse files
committed
Graph::put does not allow double slashes in request URIs
Added HTTP test for that as well
1 parent 5bf7992 commit 8714801

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL"
5+
initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL"
6+
purge_cache "$END_USER_VARNISH_SERVICE"
7+
purge_cache "$ADMIN_VARNISH_SERVICE"
8+
purge_cache "$FRONTEND_VARNISH_SERVICE"
9+
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+
# creating new document fails because URIs with double slashes are not allowed
19+
20+
item="${END_USER_BASE_URL}new-item//"
21+
22+
(
23+
curl -k -w "%{http_code}\n" -o /dev/null -s \
24+
-E "$AGENT_CERT_FILE":"$AGENT_CERT_PWD" \
25+
-X PUT \
26+
-H "Accept: application/n-triples" \
27+
-H "Content-Type: application/n-triples" \
28+
--data-binary @- \
29+
"$item" <<EOF
30+
<http://example.com/named-subject-put> <http://example.com/default-predicate> "named object PUT" .
31+
<http://example.com/named-subject-put> <http://example.com/another-predicate> "another named object PUT" .
32+
EOF
33+
) \
34+
| grep -q "$STATUS_BAD_REQUEST"

src/main/java/com/atomgraph/linkeddatahub/resource/Graph.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,17 @@ public Response put(Model model, @QueryParam("default") @DefaultValue("false") B
218218
{
219219
String uriWithSlash = getURI().toString() + "/";
220220

221-
if (log.isDebugEnabled()) log.debug("Redirecting document URI <> to <{}> in order to enforce trailing a slash", getURI(), uriWithSlash);
221+
if (log.isDebugEnabled()) log.debug("Redirecting document URI <{}> to <{}> in order to enforce trailing a slash", getURI(), uriWithSlash);
222222

223223
return Response.status(PERMANENT_REDIRECT).
224224
location(URI.create(uriWithSlash)).
225225
build();
226226
}
227+
if (getURI().getPath().contains("//"))
228+
{
229+
if (log.isDebugEnabled()) log.debug("Rejected document URI <{}> - double slashes are not allowed", getURI());
230+
throw new BadRequestException("Double slashes not allowed in document URIs");
231+
}
227232

228233
new Skolemizer(getURI().toString()).apply(model);
229234
Model existingModel = null;

0 commit comments

Comments
 (0)