Refine search
@Test public void test_param_string_bug_03() { // Tests a bug reported with setting literals String str = "SELECT * WHERE { ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("o", "has$5sign"); pss.toString(); }
ParameterizedSparqlString pss = new ParameterizedSparqlString(); pss.setCommandText(builder.toString()); pss.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pss.setIri("msgUri", msg.getUri()); pss.setLiteral("crawlDate", msg.getCrawlDate()); pss.setLiteral("crawlStatus", msg.getStatus().toString()); pss.setIri("crawlBaseUri", msg.getBaseUri()); if (msg.getWonNodeUri() != null) { int i = 0; for (String etagValue : msg.getResourceETagHeaderValues()) { pss.setLiteral(i, etagValue); i++;
@Test public void test_param_string_positional_non_injection_01() { // This test checks that a legitimate injection of a literal to a // variable that occurs between two other literals is permitted // Btw this is not a valid query but it serves to illustrate the case String str = "SELECT * { \"subject\" ? \"object\" . }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral(0, "predicate"); pss.toString(); }
" LIMIT ?limit"; ParameterizedSparqlString pps = new ParameterizedSparqlString(); pps.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pps.setCommandText(queryTemplate); pps.setLiteral("fromDate", fromDate); pps.setLiteral("toDate", toDate); pps.setLiteral("offset", offset); pps.setLiteral("limit", limit);
@Test public void test_param_string_bug_02() { // Tests a bug reported with setting literals String str = "SELECT * WHERE { ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("o", "has$1sign"); pss.toString(); }
public Collection<TensorEntry> generateTensorEntries() { ParameterizedSparqlString pss = new ParameterizedSparqlString(); pss.setCommandText(query); for (String key : parameterBindings.keySet()) { pss.setLiteral(key, (String) value); } else if (value instanceof Long || value instanceof Integer) { pss.setLiteral(key, (Long) value); } else if (value instanceof Float || value instanceof Double) { pss.setLiteral(key, (Double) value); } else { throw new IllegalArgumentException("Variable must be of type String/Long/Integer/Float/Double");
@Test public void test_param_string_bug_01() { // Tests a bug reported with setting literals String str = "SELECT * WHERE { ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("o", "has$sign"); pss.toString(); }
" GROUP BY ?uri ?base ?wonNode\n"; ParameterizedSparqlString pps = new ParameterizedSparqlString(); pps.setNsPrefix("won", "http://purl.org/webofneeds/model#"); pps.setCommandText(queryString); pps.setLiteral("status", status.toString());
@Test public void test_param_string_non_injection_01() { // This test checks that a legitimate injection of a literal to a // variable that occurs between two other literals is permitted // Btw this is not a valid query but it serves to illustrate the case String str = "SELECT * { \"subject\" ?var \"object\" . }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("var", "predicate"); pss.toString(); }
@Test public void test_param_string_bug_04() { // Tests a bug reported with setting literals String str = "SELECT * WHERE { ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("o", "has $9 sign"); pss.toString(); }
@Test(expected = ARQException.class) public void test_param_string_injection_15() { // This injection attempt tries to chain together injections to achieve // an attack, the first injection appears innocuous and is an attempt to // set up an actual injection vector // Since we not check out delimiters we are not able to detect and // prevent this String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> ?var }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("var", "a"); pss.setLiteral("var2", "b"); // Figure out which variable will be injected first @SuppressWarnings("deprecation") String first = pss.getVars().next(); String second = first.equals("var") ? "var2" : "var"; pss.setLiteral(first, " ?" + second + " "); pss.setLiteral(second, " . } ; DROP ALL ; INSERT DATA { <s> <p> "); pss.asUpdate(); Assert.fail("Attempt to do SPARQL injection should result in an exception"); }
@Test(expected = ARQException.class) public void test_param_string_injection_10() { // This injection attempt tries to chain together injections to achieve // an attack, the first // injection appears innocuous and is an attempt to set up an actual // injection vector // The injection is prevented because a ?var directly surrounded by // quotes is always flagged as // subject to injection because pre-injection validation happens before // each variable is injected String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> ?var }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("var", "a"); pss.setLiteral("var2", "b"); // Figure out which variable will be injected first @SuppressWarnings("deprecation") String first = pss.getVars().next(); String second = first.equals("var") ? "var2" : "var"; pss.setLiteral(first, "?" + second); pss.setLiteral(second, " . } ; DROP ALL ; INSERT DATA { <s> <p> "); pss.asUpdate(); Assert.fail("Attempt to do SPARQL injection should result in an exception"); }
@Test public void test_param_string_positional_injection_07() { // This injection attempt is prevented by forbidding injection of // variable parameters immediately surrounded by quotes String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> \"?\" }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral(0, " . } ; DROP ALL ; INSERT DATA { <s> <p> "); // In the positional case this does not work because the "?" is not // considered an eligible positional parameter due to the lack of // subsequent white space or punctuation Assert.assertFalse(pss.getEligiblePositionalParameters().hasNext()); }
@Test public void test_param_string_positional_injection_06() { // This injection attempt is prevented by forbidding injection to a // variable parameter immediately surrounded by quotes String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> '?' }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral(0, "hello' . } ; DROP ALL ; INSERT DATA { <s> <p> \"goodbye"); // In the positional case this does not work because the '?' is not // considered an eligible positional parameter due to the lack of // subsequent white space or punctuation Assert.assertFalse(pss.getEligiblePositionalParameters().hasNext()); }
@Test public void test_param_string_lang_3() { // Test lang literal injection String cmdText = "SELECT * WHERE { ?s ?p ? }"; ParameterizedSparqlString query = new ParameterizedSparqlString(cmdText); query.setLiteral(0, "hello", "en"); test(query, new String[] { "hello", "@en" }, new String[] { "? " }); testAsQuery(query); }
@Test(expected = ARQException.class) public void test_param_string_injection_08() { // This injection attempt results in an invalid SPARQL update because // you end up with a double quoted literal inside a single quoted // literal String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> '?var' }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("var", "' . } ; DROP ALL ; INSERT DATA { <s> <p> <o> }#"); pss.asUpdate(); Assert.fail("Attempt to do SPARQL injection should result in an exception"); }
@Test(expected = ARQException.class) public void test_param_string_injection_12() { // This is a variant on placing a variable bound to a literal inside a // literal resulting in an injection, we are now able to detect and // prevent this String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> \"some text ?var other text\" }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setLiteral("var", " . } ; DROP ALL ; INSERT DATA { <s> <p> "); pss.asUpdate(); Assert.fail("Attempt to do SPARQL injection should result in an exception"); }
@Test public void test_param_string_boolean_2() { // Test boolean injection String cmdText = "SELECT * WHERE { ?s ?p ?o }"; ParameterizedSparqlString query = new ParameterizedSparqlString(cmdText); query.setLiteral("o", false); // We don't expect #boolean as booleans should be formatted as plain // literals test(query, new String[] { "false" }, new String[] { "?o", XSD.xboolean.toString() }); }
@Test public void test_param_string_boolean_5() { // Test boolean injection String cmdText = "SELECT * WHERE { ?s ?p ? }"; ParameterizedSparqlString query = new ParameterizedSparqlString(cmdText); query.setLiteral(0, false); // We don't expect #boolean as booleans should be formatted as plain // literals test(query, new String[] { "false" }, new String[] { "? ", XSD.xboolean.toString() }); }
@Test public void test_param_string_lang_1() { // Test lang literal injection String cmdText = "SELECT * WHERE { ?s ?p ?o }"; ParameterizedSparqlString query = new ParameterizedSparqlString(cmdText); query.setLiteral("o", "hello", "en"); test(query, new String[] { "hello", "@en" }, new String[] { "?o" }); testAsQuery(query); }