Skip to content

Commit a6d71b5

Browse files
namedgraphclaude
andcommitted
Use ParameterizedSparqlString for proxy namespace DESCRIBE query
Bind the target URI via setIri() instead of string-concatenating it into the query text, eliminating the SPARQL injection surface on a URI containing metacharacters. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2b2cc67 commit a6d71b5

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import java.util.List;
3939
import java.util.Optional;
4040
import java.util.Set;
41+
import org.apache.jena.query.ParameterizedSparqlString;
4142
import org.apache.jena.query.QueryExecution;
42-
import org.apache.jena.query.QueryFactory;
4343
import jakarta.annotation.Priority;
4444
import jakarta.inject.Inject;
4545
import jakarta.ws.rs.NotAllowedException;
@@ -192,9 +192,10 @@ public void filter(ContainerRequestContext requestContext) throws IOException
192192
// ?term where STR(?term) starts with "<targetURI>#")
193193
if (isSafeMethod && getOntology().isPresent())
194194
{
195-
String describeQueryStr = "DESCRIBE <" + targetURI + "> ?term " +
196-
"WHERE { ?term ?p ?o FILTER(STRSTARTS(STR(?term), CONCAT(STR(<" + targetURI + ">), \"#\"))) }";
197-
try (QueryExecution qe = QueryExecution.create(QueryFactory.create(describeQueryStr), getOntology().get().getOntModel()))
195+
ParameterizedSparqlString pss = new ParameterizedSparqlString(
196+
"DESCRIBE ?doc ?term WHERE { ?term ?p ?o FILTER(STRSTARTS(STR(?term), CONCAT(STR(?doc), \"#\"))) }");
197+
pss.setIri("doc", targetURI.toString());
198+
try (QueryExecution qe = QueryExecution.create(pss.asQuery(), getOntology().get().getOntModel()))
198199
{
199200
Model description = qe.execDescribe();
200201
if (!description.isEmpty())

0 commit comments

Comments
 (0)