code
stringlengths 14
2.05k
| label
int64 0
1
| programming_language
stringclasses 7
values | cwe_id
stringlengths 6
14
| cwe_name
stringlengths 5
98
⌀ | description
stringlengths 36
379
⌀ | url
stringlengths 36
48
⌀ | label_name
stringclasses 2
values |
---|---|---|---|---|---|---|---|
public void testForCountIsNotEqualToInsensitiveDebugEnabledEscaping() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) = :value0) /* [ name = FOO*\\/BAR ] */\n)";
Filter filter =
FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("FOO*/BAR"), false);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIncludeWithOffSetDebugDisabled() {
dialect.setDebugMode(false);
String expected =
"SELECT id FROM object WHERE type_id IN (:types) ORDER BY oid LIMIT 2147483647 OFFSET 5";
String actual =
QueryBuilder.forIds(dialect, WorkspaceInfo.class, dbMappings).offset(5).build();
assertEquals(expected, actual);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeInsensitiveDebugDisabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0)";
Filter filter = FACTORY.like(FACTORY.property("name"), "%quux%", "%", "_", "\\", false);
verifyForCount(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsNullDebugEnabled() {
String expected =
"(oid IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0) AND value IS NULL) OR oid NOT IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0))) /* [ name IS NULL ] */";
verifyForCount(expected, true, Predicates.isNull("name"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsEqualToInsensitiveDebugEnabledEscaping() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) = :value0) /* [ name = FOO*\\/BAR ] */";
Filter filter = FACTORY.equal(FACTORY.property("name"), FACTORY.literal("FOO*/BAR"), false);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeInsensitiveDebugEnabledEscaping1() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0) /* [ name is like %\\'FOO% ] */";
Filter filter = FACTORY.like(FACTORY.property("name"), "%\\'FOO%", "%", "_", "\\", false);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsEqualToInsensitiveDebugEnabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) = :value0) /* [ name = quux ] */";
Filter filter = FACTORY.equal(FACTORY.property("name"), FACTORY.literal("quux"), false);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIncludeDebugEnabled() {
String expected =
"SELECT COUNT(oid) FROM object WHERE type_id IN (:types) /* org.geoserver.catalog.WorkspaceInfo */";
verifyForCount(expected, true, Predicates.acceptAll());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
private void verifyForCount(String expectedSQL, boolean debugMode, Filter filter) {
String expected = expectedSQL;
if (!expected.startsWith("SELECT")) {
expected =
"SELECT COUNT(oid) FROM object WHERE type_id IN (:types) "
+ (debugMode ? "/* org.geoserver.catalog.WorkspaceInfo */\n" : "")
+ "AND "
+ expectedSQL;
}
QueryBuilder<?> builder = QueryBuilder.forCount(dialect, WorkspaceInfo.class, dbMappings);
verifyQuery(builder, expected, debugMode, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsNullDebugDisabled() {
String expected =
"(oid IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0) AND value IS NULL) OR oid NOT IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0))) ";
verifyForIds(expected, false, Predicates.isNull("name"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountOrIsInstanceofDebugDisabled() {
String expected = "(type_id = 14 OR 0 = 1)";
Filter filter =
Predicates.or(
Predicates.isInstanceOf(LayerInfo.class),
Predicates.isInstanceOf(String.class));
verifyForCount(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsLikeSensitiveDebugDisabledEscaping() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value LIKE :value0) ";
Filter filter = FACTORY.like(FACTORY.property("name"), "%\\'FOO%", "%", "_", "\\", true);
verifyForIds(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeSensitiveDebugDisabledEscaping() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value LIKE :value0)";
Filter filter = FACTORY.like(FACTORY.property("name"), "%\\'FOO%", "%", "_", "\\", true);
verifyForCount(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsNotEqualToInsensitiveDebugDisabled() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) = :value0))";
Filter filter = FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("quux"), false);
verifyForCount(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsSort3WithFilterDebugDisabled() {
String expected =
"SELECT id FROM (SELECT oid, id FROM object WHERE type_id IN (:types) AND oid IN "
+ "(SELECT oid FROM object_property WHERE property_type IN (:ptype0) AND value = :value0)) object "
+ "LEFT JOIN (SELECT oid, value prop0 FROM object_property "
+ "WHERE property_type IN (:sortProperty0)) subSelect0 ON object.oid = subSelect0.oid "
+ "LEFT JOIN (SELECT oid, value prop1 FROM object_property "
+ "WHERE property_type IN (:sortProperty1)) subSelect1 ON object.oid = subSelect1.oid "
+ "LEFT JOIN (SELECT oid, value prop2 FROM object_property "
+ "WHERE property_type IN (:sortProperty2)) subSelect2 ON object.oid = subSelect2.oid "
+ "ORDER BY prop0 ASC, prop1 DESC, prop2 ASC";
verifyForIds(
expected,
false,
Predicates.equal("name", "quux"),
Predicates.asc("foo"),
Predicates.desc("bar"),
Predicates.asc("baz"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountSimplifiedInclude() {
dialect.setDebugMode(false);
String expected = "SELECT COUNT(oid) FROM object WHERE type_id IN (:types)";
Filter filter = Predicates.and(Predicates.acceptAll(), Predicates.acceptAll());
QueryBuilder<?> builder =
QueryBuilder.forCount(dialect, WorkspaceInfo.class, dbMappings).filter(filter);
String actual = builder.build();
assertEquals(expected, actual);
assertEquals(Filter.INCLUDE, builder.getSupportedFilter());
assertEquals(Filter.INCLUDE, builder.getUnsupportedFilter());
assertFalse(builder.isOffsetLimitApplied());
assertEquals(1, builder.getNamedParameters().size());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsLikeInsensitiveDebugEnabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0) /* [ name is like %quux% ] */\n";
Filter filter = FACTORY.like(FACTORY.property("name"), "%quux%", "%", "_", "\\", false);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsNotEqualToSensitiveDebugEnabled() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0) /* [ name = quux ] */\n)";
Filter filter = FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("quux"), true);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsEqualToSensitiveDebugEnabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0) /* [ name = quux ] */\n";
Filter filter = FACTORY.equal(FACTORY.property("name"), FACTORY.literal("quux"), true);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeSensitiveDebugEnabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value LIKE :value0) /* [ name is like %quux% ] */";
Filter filter = FACTORY.like(FACTORY.property("name"), "%quux%", "%", "_", "\\", true);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsNotNullDebugDisabled() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0) AND value IS NULL) OR oid NOT IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0))) ";
verifyForIds(expected, false, Predicates.not(Predicates.isNull("name")));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsNotEqualToSensitiveDebugEnabledEscaping() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0) /* [ name = FOO*\\/BAR ] */\n)";
Filter filter =
FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("FOO*/BAR"), true);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsLikeInsensitiveDebugEnabledEscaping1() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0) /* [ name is like %\\'FOO% ] */\n";
Filter filter = FACTORY.like(FACTORY.property("name"), "%\\'FOO%", "%", "_", "\\", false);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeInsensitiveDebugEnabledEscaping2() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0) /* [ name is like %FOO*\\/BAR% ] */";
Filter filter = FACTORY.like(FACTORY.property("name"), "%FOO*/BAR%", "%", "_", "\\", false);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsSort1DebugEnabled() {
String expected =
"SELECT id FROM"
+ "\n (SELECT oid, id FROM object WHERE type_id IN (:types) /* org.geoserver.catalog.WorkspaceInfo */"
+ "\n) object"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop0 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty0)) subSelect0 /* foo ASC */"
+ "\n ON object.oid = subSelect0.oid"
+ "\n ORDER BY prop0 ASC";
verifyForIds(expected, true, Predicates.acceptAll(), Predicates.asc("foo"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeInsensitiveDebugEnabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0) /* [ name is like %quux% ] */";
Filter filter = FACTORY.like(FACTORY.property("name"), "%quux%", "%", "_", "\\", false);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIncludeWithOffSetDebugEnabled() {
dialect.setDebugMode(true);
String expected =
"SELECT id FROM object WHERE type_id IN (:types) /* org.geoserver.catalog.WorkspaceInfo */"
+ "\nORDER BY oid LIMIT 2147483647 OFFSET 5";
String actual =
QueryBuilder.forIds(dialect, WorkspaceInfo.class, dbMappings).offset(5).build();
assertEquals(expected, actual);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsEqualToSensitiveDebugDisabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0)";
Filter filter = FACTORY.equal(FACTORY.property("name"), FACTORY.literal("quux"), true);
verifyForCount(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsSort3DebugEnabled() {
String expected =
"SELECT id FROM"
+ "\n (SELECT oid, id FROM object WHERE type_id IN (:types) /* org.geoserver.catalog.WorkspaceInfo */"
+ "\n) object"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop0 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty0)) subSelect0 /* foo ASC */"
+ "\n ON object.oid = subSelect0.oid"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop1 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty1)) subSelect1 /* bar DESC */"
+ "\n ON object.oid = subSelect1.oid"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop2 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty2)) subSelect2 /* baz ASC */"
+ "\n ON object.oid = subSelect2.oid"
+ "\n ORDER BY prop0 ASC, prop1 DESC, prop2 ASC";
verifyForIds(
expected,
true,
Predicates.acceptAll(),
Predicates.asc("foo"),
Predicates.desc("bar"),
Predicates.asc("baz"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsNotEqualToInsensitiveDebugEnabled() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) = :value0) /* [ name = quux ] */\n) ";
Filter filter = FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("quux"), false);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
private void verifyForIds(
String expectedSQL, boolean debugMode, Filter filter, SortBy... order) {
String expected = expectedSQL;
if (!expected.startsWith("SELECT")) {
expected =
"SELECT id FROM object WHERE type_id IN (:types) "
+ (debugMode ? "/* org.geoserver.catalog.WorkspaceInfo */\n" : "")
+ "AND "
+ expectedSQL
+ "ORDER BY oid";
}
QueryBuilder<?> builder = QueryBuilder.forIds(dialect, WorkspaceInfo.class, dbMappings);
verifyQuery(builder, expected, debugMode, filter, order);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsNotEqualToSensitiveDebugDisabled() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0)) ";
Filter filter = FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("quux"), true);
verifyForIds(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeInsensitiveDebugDisabledEscaping() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0)";
Filter filter = FACTORY.like(FACTORY.property("name"), "%\\'FOO%", "%", "_", "\\", false);
verifyForCount(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountUnknownProperty() {
dialect.setDebugMode(false);
String expected = "SELECT COUNT(oid) FROM object WHERE type_id IN (:types)";
Filter filter = Predicates.equal("foo.bar.baz", "quux");
QueryBuilder<?> builder =
QueryBuilder.forCount(dialect, WorkspaceInfo.class, dbMappings).filter(filter);
String actual = builder.build();
assertEquals(expected, actual);
assertEquals(Filter.INCLUDE, builder.getSupportedFilter());
assertEquals(filter, builder.getUnsupportedFilter());
assertFalse(builder.isOffsetLimitApplied());
assertEquals(1, builder.getNamedParameters().size());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsAndIsInstanceofDebugEnabled() {
String expected =
"(\n type_id = 14 /* isInstanceOf org.geoserver.catalog.LayerInfo */"
+ "\n AND\n 0 = 1 /* EXCLUDE */\n) ";
Filter filter =
Predicates.and(
Predicates.isInstanceOf(LayerInfo.class),
Predicates.isInstanceOf(String.class));
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsNotNullDebugDisabled() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0) AND value IS NULL) OR oid NOT IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0)))";
verifyForCount(expected, false, Predicates.not(Predicates.isNull("name")));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsLikeInsensitiveDebugEnabledEscaping2() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0) /* [ name is like %FOO*\\/BAR% ] */\n";
Filter filter = FACTORY.like(FACTORY.property("name"), "%FOO*/BAR%", "%", "_", "\\", false);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIncludeDebugDisabled() {
String expected = "SELECT COUNT(oid) FROM object WHERE type_id IN (:types)";
verifyForCount(expected, false, Predicates.acceptAll());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsEqualToSensitiveDebugDisabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0) ";
Filter filter = FACTORY.equal(FACTORY.property("name"), FACTORY.literal("quux"), true);
verifyForIds(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsLikeInsensitiveDebugDisabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0) ";
Filter filter = FACTORY.like(FACTORY.property("name"), "%quux%", "%", "_", "\\", false);
verifyForIds(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsAndIsInstanceofDebugDisabled() {
String expected = "(type_id = 14 AND 0 = 1) ";
Filter filter =
Predicates.and(
Predicates.isInstanceOf(LayerInfo.class),
Predicates.isInstanceOf(String.class));
verifyForIds(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsNotEqualToSensitiveDebugEnabled() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0) /* [ name = quux ] */\n) ";
Filter filter = FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("quux"), true);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountOrIsInstanceofDebugEnabled() {
String expected =
"(\n type_id = 14 /* isInstanceOf org.geoserver.catalog.LayerInfo */"
+ "\n OR\n 0 = 1 /* EXCLUDE */\n)";
Filter filter =
Predicates.or(
Predicates.isInstanceOf(LayerInfo.class),
Predicates.isInstanceOf(String.class));
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsEqualToSensitiveDebugEnabledEscaping() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0) /* [ name = FOO*\\/BAR ] */";
Filter filter = FACTORY.equal(FACTORY.property("name"), FACTORY.literal("FOO*/BAR"), true);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsNullDebugDisabled() {
String expected =
"(oid IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0) AND value IS NULL) OR oid NOT IN (SELECT oid FROM object_property WHERE property_type IN (:"
+ "ptype0)))";
verifyForCount(expected, false, Predicates.isNull("name"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsSort2DebugEnabled() {
String expected =
"SELECT id FROM"
+ "\n (SELECT oid, id FROM object WHERE type_id IN (:types) /* org.geoserver.catalog.WorkspaceInfo */"
+ "\n) object"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop0 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty0)) subSelect0 /* foo ASC */"
+ "\n ON object.oid = subSelect0.oid"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop1 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty1)) subSelect1 /* bar DESC */"
+ "\n ON object.oid = subSelect1.oid"
+ "\n ORDER BY prop0 ASC, prop1 DESC";
verifyForIds(
expected,
true,
Predicates.acceptAll(),
Predicates.asc("foo"),
Predicates.desc("bar"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsLikeSensitiveDebugDisabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value LIKE :value0) ";
Filter filter = FACTORY.like(FACTORY.property("name"), "%quux%", "%", "_", "\\", true);
verifyForIds(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsSort1DebugDisabled() {
String expected =
"SELECT id FROM (SELECT oid, id FROM object WHERE type_id IN (:types)) object "
+ "LEFT JOIN (SELECT oid, value prop0 FROM object_property "
+ "WHERE property_type IN (:sortProperty0)) subSelect0 ON object.oid = subSelect0.oid "
+ "ORDER BY prop0 ASC";
verifyForIds(expected, false, Predicates.acceptAll(), Predicates.asc("foo"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsLikeInsensitiveDebugDisabledEscaping() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) LIKE :value0) ";
Filter filter = FACTORY.like(FACTORY.property("name"), "%\\'FOO%", "%", "_", "\\", false);
verifyForIds(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeSensitiveDebugEnabledEscaping1() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value LIKE :value0) /* [ name is like %\\'FOO% ] */";
Filter filter = FACTORY.like(FACTORY.property("name"), "%\\'FOO%", "%", "_", "\\", true);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsEqualToInsensitiveDebugDisabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) = :value0)";
Filter filter = FACTORY.equal(FACTORY.property("name"), FACTORY.literal("quux"), false);
verifyForCount(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIncludeDebugEnabled() {
String expected =
"SELECT id FROM object WHERE type_id IN (:types) /* org.geoserver.catalog.WorkspaceInfo */"
+ "\nORDER BY oid";
verifyForIds(expected, true, Predicates.acceptAll());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsOrIsInstanceofDebugEnabled() {
String expected =
"(\n type_id = 14 /* isInstanceOf org.geoserver.catalog.LayerInfo */"
+ "\n OR\n 0 = 1 /* EXCLUDE */\n) ";
Filter filter =
Predicates.or(
Predicates.isInstanceOf(LayerInfo.class),
Predicates.isInstanceOf(String.class));
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountAndIsInstanceofDebugEnabled() {
String expected =
"(\n type_id = 14 /* isInstanceOf org.geoserver.catalog.LayerInfo */"
+ "\n AND\n 0 = 1 /* EXCLUDE */\n)";
Filter filter =
Predicates.and(
Predicates.isInstanceOf(LayerInfo.class),
Predicates.isInstanceOf(String.class));
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIncludeDebugDisabled() {
String expected = "SELECT id FROM object WHERE type_id IN (:types) ORDER BY oid";
verifyForIds(expected, false, Predicates.acceptAll());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsEqualToInsensitiveDebugEnabledEscaping() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) = :value0) /* [ name = FOO*\\/BAR ] */\n";
Filter filter = FACTORY.equal(FACTORY.property("name"), FACTORY.literal("FOO*/BAR"), false);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsLikeSensitiveDebugEnabledEscaping2() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value LIKE :value0) /* [ name is like %FOO*\\/BAR% ] */";
Filter filter = FACTORY.like(FACTORY.property("name"), "%FOO*/BAR%", "%", "_", "\\", true);
verifyForCount(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsSort2DebugDisabled() {
String expected =
"SELECT id FROM (SELECT oid, id FROM object WHERE type_id IN (:types)) object "
+ "LEFT JOIN (SELECT oid, value prop0 FROM object_property "
+ "WHERE property_type IN (:sortProperty0)) subSelect0 ON object.oid = subSelect0.oid "
+ "LEFT JOIN (SELECT oid, value prop1 FROM object_property "
+ "WHERE property_type IN (:sortProperty1)) subSelect1 ON object.oid = subSelect1.oid "
+ "ORDER BY prop0 ASC, prop1 DESC";
verifyForIds(
expected,
false,
Predicates.acceptAll(),
Predicates.asc("foo"),
Predicates.desc("bar"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsSort3WithFilterDebugEnabled() {
String expected =
"SELECT id FROM"
+ "\n (SELECT oid, id FROM object WHERE type_id IN (:types) /* org.geoserver.catalog.WorkspaceInfo */"
+ "\n AND oid IN (SELECT oid FROM object_property WHERE property_type IN (:ptype0) AND value = :value0) /* [ name = quux ] */"
+ "\n) object"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop0 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty0)) subSelect0 /* foo ASC */"
+ "\n ON object.oid = subSelect0.oid"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop1 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty1)) subSelect1 /* bar DESC */"
+ "\n ON object.oid = subSelect1.oid"
+ "\n LEFT JOIN"
+ "\n (SELECT oid, value prop2 FROM"
+ "\n object_property WHERE property_type IN (:sortProperty2)) subSelect2 /* baz ASC */"
+ "\n ON object.oid = subSelect2.oid"
+ "\n ORDER BY prop0 ASC, prop1 DESC, prop2 ASC";
verifyForIds(
expected,
true,
Predicates.equal("name", "quux"),
Predicates.asc("foo"),
Predicates.desc("bar"),
Predicates.asc("baz"));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsLikeSensitiveDebugEnabled() {
String expected =
"oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value LIKE :value0) /* [ name is like %quux% ] */\n";
Filter filter = FACTORY.like(FACTORY.property("name"), "%quux%", "%", "_", "\\", true);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForCountIsNotEqualToSensitiveDebugDisabled() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND value = :value0))";
Filter filter = FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("quux"), true);
verifyForCount(expected, false, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIncludeWithOffSetAndLimitDebugEnabled() {
dialect.setDebugMode(true);
String expected =
"SELECT id FROM object WHERE type_id IN (:types) /* org.geoserver.catalog.WorkspaceInfo */"
+ "\nORDER BY oid LIMIT 10 OFFSET 5";
String actual =
QueryBuilder.forIds(dialect, WorkspaceInfo.class, dbMappings)
.offset(5)
.limit(10)
.build();
assertEquals(expected, actual);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsIsNotEqualToInsensitiveDebugEnabledEscaping() {
String expected =
"NOT (oid IN (SELECT oid FROM object_property WHERE property_type "
+ "IN (:ptype0) AND UPPER(value) = :value0) /* [ name = FOO*\\/BAR ] */\n) ";
Filter filter =
FACTORY.notEqual(FACTORY.property("name"), FACTORY.literal("FOO*/BAR"), false);
verifyForIds(expected, true, filter);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testForIdsSimplifiedInclude() {
dialect.setDebugMode(false);
String expected = "SELECT id FROM object WHERE type_id IN (:types) ORDER BY oid";
Filter filter = Predicates.and(Predicates.acceptAll(), Predicates.acceptAll());
QueryBuilder<?> builder =
QueryBuilder.forIds(dialect, WorkspaceInfo.class, dbMappings).filter(filter);
String actual = builder.build();
assertEquals(expected, actual);
assertEquals(Filter.INCLUDE, builder.getSupportedFilter());
assertEquals(Filter.INCLUDE, builder.getUnsupportedFilter());
assertTrue(builder.isOffsetLimitApplied());
assertEquals(1, builder.getNamedParameters().size());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public Object visit(PropertyIsLike filter, Object extraData) {
char esc = filter.getEscape().charAt(0);
char multi = filter.getWildCard().charAt(0);
char single = filter.getSingleChar().charAt(0);
boolean matchCase = filter.isMatchingCase();
String literal = filter.getLiteral();
Expression att = filter.getExpression();
// JD: hack for date values, we append some additional padding to handle
// the matching of time/timezone/etc...
Class attributeType = getExpressionType(att);
// null check if returnType of expression is Object, null is returned
// from getExpressionType
if (attributeType != null && Date.class.isAssignableFrom(attributeType)) {
literal += multi;
}
String pattern =
LikeFilterImpl.convertToSQL92(esc, multi, single, matchCase, literal, false);
try {
if (!matchCase) {
out.write(" UPPER(");
}
att.accept(this, extraData);
if (!matchCase) {
out.write(") LIKE ");
} else {
out.write(" LIKE ");
}
writeLiteral(pattern);
} catch (java.io.IOException ioe) {
throw new RuntimeException(IO_ERROR, ioe);
}
return extraData;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
protected void writeLiteral(Object literal) throws IOException {
if (literal == null) {
out.write("NULL");
} else if (literal instanceof Number || literal instanceof Boolean) {
out.write(String.valueOf(literal));
} else if (literal instanceof java.sql.Date || literal instanceof java.sql.Timestamp) {
// java.sql.date toString declares to always format to yyyy-mm-dd
// (and TimeStamp uses a similar approach)
out.write("'" + literal + "'");
} else if (literal instanceof java.util.Date) {
// get back to the previous case
Timestamp ts = new java.sql.Timestamp(((Date) literal).getTime());
out.write("'" + ts + "'");
} else if (literal instanceof Instant) {
java.util.Date date = ((Instant) literal).getPosition().getDate();
Timestamp ts = new java.sql.Timestamp(date.getTime());
out.write("'" + ts + "'");
} else if (literal.getClass().isArray()) {
// write as a SQL99 array
out.write("ARRAY[");
int length = Array.getLength(literal);
for (int i = 0; i < length; i++) {
writeLiteral(Array.get(literal, i));
if (i < length - 1) {
out.write(", ");
}
}
out.write("]");
} else {
// we don't know the type...just convert back to a string
String encoding = Converters.convert(literal, String.class, null);
if (encoding == null) {
// could not convert back to string, use original l value
encoding = literal.toString();
}
// single quotes must be escaped to have a valid sql string
String escaped = escapeLiteral(encoding);
out.write("'" + escaped + "'");
}
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void setEscapeBackslash(boolean escapeBackslash) {
this.escapeBackslash = escapeBackslash;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public boolean isEscapeBackslash() {
return escapeBackslash;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public String escapeLiteral(String literal) {
return EscapeSql.escapeLiteral(literal, escapeBackslash, false);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public Object visit(Id filter, Object extraData) {
if (primaryKey == null) {
throw new RuntimeException("Must set primary key before trying to encode FIDFilters");
}
Set ids = filter.getIdentifiers();
LOGGER.finer("Exporting FID=" + ids);
try {
if (ids.size() > 1) {
out.write("(");
}
List<PrimaryKeyColumn> columns = primaryKey.getColumns();
for (Iterator i = ids.iterator(); i.hasNext(); ) {
Identifier id = (Identifier) i.next();
List<Object> attValues = JDBCDataStore.decodeFID(primaryKey, id.toString(), false);
out.write("(");
for (int j = 0; j < attValues.size(); j++) {
// in case of join the pk columns need to be qualified with alias
if (filter instanceof JoinId) {
out.write(escapeName(((JoinId) filter).getAlias()));
out.write(".");
}
out.write(escapeName(columns.get(j).getName()));
out.write(" = ");
writeLiteral(attValues.get(j));
if (j < (attValues.size() - 1)) {
out.write(" AND ");
}
}
out.write(")");
if (i.hasNext()) {
out.write(" OR ");
}
}
if (ids.size() > 1) {
out.write(")");
}
} catch (java.io.IOException e) {
throw new RuntimeException(IO_ERROR, e);
}
return extraData;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public static String escapeLiteral(
String literal, boolean escapeBackslash, boolean escapeDoubleQuote) {
// ' --> ''
String escaped = SINGLE_QUOTE_PATTERN.matcher(literal).replaceAll("''");
if (escapeBackslash) {
// \ --> \\
escaped = BACKSLASH_PATTERN.matcher(escaped).replaceAll("\\\\\\\\");
}
if (escapeDoubleQuote) {
// " --> \"
escaped = DOUBLE_QUOTE_PATTERN.matcher(escaped).replaceAll("\\\\\"");
}
return escaped;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
protected <T extends Connection> T unwrapConnection(Connection cx, Class<T> clazz)
throws SQLException {
if (clazz.isInstance(cx)) {
return clazz.cast(cx);
}
try {
// Unwrap the connection multiple levels as necessary to get at the underlying
// connection. Maintain a map of UnWrappers to avoid searching the registry
// every time we need to unwrap.
Connection testCon = cx;
Connection toUnwrap;
do {
UnWrapper unwrapper = uwMap.get(testCon.getClass());
if (unwrapper == null) {
unwrapper = DataSourceFinder.getUnWrapper(testCon);
if (unwrapper == null) {
unwrapper = UNWRAPPER_NOT_FOUND;
}
uwMap.put(testCon.getClass(), unwrapper);
}
if (unwrapper == UNWRAPPER_NOT_FOUND) {
// give up and do Java unwrap below
break;
}
toUnwrap = testCon;
testCon = unwrapper.unwrap(testCon);
if (clazz.isInstance(testCon)) {
return clazz.cast(cx);
}
} while (testCon != null && testCon != toUnwrap);
// try to use Java unwrapping
try {
if (cx.isWrapperFor(clazz)) {
return cx.unwrap(clazz);
}
} catch (Throwable t) {
// not a mistake, old DBCP versions will throw an Error here, we need to catch it
LOGGER.log(Level.FINER, "Failed to unwrap connection using Java facilities", t);
}
} catch (IOException e) {
throw new SQLException(
"Could not obtain " + clazz.getName() + " from " + cx.getClass(), e);
}
throw new SQLException("Could not obtain " + clazz.getName() + " from " + cx.getClass());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
new UnWrapper() {
@Override
public Statement unwrap(Statement statement) {
throw new UnsupportedOperationException();
}
@Override
public Connection unwrap(Connection conn) {
throw new UnsupportedOperationException();
}
@Override
public boolean canUnwrap(Statement st) {
return false;
}
@Override
public boolean canUnwrap(Connection conn) {
return false;
}
}; | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testIdEscaping() throws Exception {
Id id = ff.id(Collections.singleton(ff.featureId("'FOO")));
encoder.encode(id);
Assert.assertEquals("WHERE (id = '''FOO')", output.toString());
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testLikeEscaping() throws Exception {
Filter filter = ff.like(ff.property("testString"), "\\'FOO", "%", "-", "\\", true);
FilterToSQL encoder = new FilterToSQL(output);
Assert.assertEquals("WHERE testString LIKE '''FOO'", encoder.encodeToString(filter));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public static String convertToSQL92(
char escape,
char multi,
char single,
boolean matchCase,
String pattern,
boolean escapeSingleQuote) {
if ((escape == '\'') || (multi == '\'') || (single == '\''))
throw new IllegalArgumentException("do not use single quote (') as special char!");
StringBuilder result = new StringBuilder(pattern.length() + 5);
for (int i = 0; i < pattern.length(); i++) {
char chr = pattern.charAt(i);
if (chr == escape) {
// emit the next char and skip it
if (i != (pattern.length() - 1)) result.append(pattern.charAt(i + 1)); //
i++; // skip next char
} else if (chr == single) {
result.append('_');
} else if (chr == multi) {
result.append('%');
} else if (chr == '\'' && escapeSingleQuote) {
result.append('\'');
result.append('\'');
} else {
result.append(matchCase ? chr : Character.toUpperCase(chr));
}
}
return result.toString();
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public static String convertToSQL92(
char escape, char multi, char single, boolean matchCase, String pattern)
throws IllegalArgumentException {
return convertToSQL92(escape, multi, single, matchCase, pattern, true);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public String getSQL92LikePattern() throws IllegalArgumentException {
if (escape.length() != 1) {
throw new IllegalArgumentException(
"Like Pattern --> escape char should be of length exactly 1");
}
if (wildcardSingle.length() != 1) {
throw new IllegalArgumentException(
"Like Pattern --> wildcardSingle char should be of length exactly 1");
}
if (wildcardMulti.length() != 1) {
throw new IllegalArgumentException(
"Like Pattern --> wildcardMulti char should be of length exactly 1");
}
return LikeFilterImpl.convertToSQL92(
escape.charAt(0),
wildcardMulti.charAt(0),
wildcardSingle.charAt(0),
matchingCase,
pattern,
true);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testLikeToSQL() {
Assert.assertEquals(
"BroadWay%", LikeFilterImpl.convertToSQL92('!', '*', '.', true, "BroadWay*", true));
Assert.assertEquals(
"broad#ay", LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broad#ay", true));
Assert.assertEquals(
"broadway", LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broadway", true));
Assert.assertEquals(
"broad_ay", LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broad.ay", true));
Assert.assertEquals(
"broad.ay", LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broad!.ay", true));
Assert.assertEquals(
"broa''dway",
LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broa'dway", true));
Assert.assertEquals(
"broa''''dway",
LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broa" + "''dway", true));
Assert.assertEquals(
"broa'dway",
LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broa'dway", false));
Assert.assertEquals(
"broa''dway",
LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broa" + "''dway", false));
Assert.assertEquals(
"broadway_", LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broadway.", true));
Assert.assertEquals(
"broadway", LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broadway!", true));
Assert.assertEquals(
"broadway!",
LikeFilterImpl.convertToSQL92('!', '*', '.', true, "broadway!!", true));
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public FilterToSQL createFilterToSQL() {
MySQLFilterToSQL fts = new MySQLFilterToSQL(delegate.getUsePreciseSpatialOps());
// see https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_no_backslash_escapes
// NOTE: for future enhancement, do not escape backslashes when the NO_BACKSLASH_ESCAPES
// mode is enabled since that would create an incorrect string in the SQL
fts.setEscapeBackslash(true);
return fts;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void setUp() throws SchemaException {
filterToSql = (MySQLFilterToSQL) new MySQLDialectBasic(null).createFilterToSQL();
filterToSql.setFeatureType(testSchema);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testEncodeEqualToWithSpecialCharacters() throws Exception {
PropertyIsEqualTo expr = ff.equals(ff.property("testString"), ff.literal("\\'FOO"));
String actual = filterToSql.encodeToString(expr);
assertEquals("WHERE testString = '\\\\''FOO'", actual);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
OracleConnection unwrapConnection(Connection cx) throws SQLException {
return unwrapConnection(cx, OracleConnection.class);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public String jsonExists(Function function) {
PropertyName columnName = (PropertyName) getParameter(function, 0, true);
Literal jsonPath = (Literal) getParameter(function, 1, true);
Expression expected = getParameter(function, 2, true);
String[] pointers = jsonPath.getValue().toString().split("/");
if (pointers.length > 0) {
String strJsonPath = escapeLiteral(String.join(".", pointers));
String strExpected = escapeLiteral(expected.evaluate(null, String.class));
return String.format(
"json_exists(%s, '$%s?(@ == \"%s\")')", columnName, strJsonPath, strExpected);
} else {
throw new IllegalArgumentException(
"Cannot encode filter Invalid pointer " + jsonPath.getValue());
}
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
protected void doSDODistance(
BinarySpatialOperator filter, Expression e1, Expression e2, Object extraData)
throws IOException {
double distance = ((DistanceBufferOperator) filter).getDistance();
String unit = getSDOUnitFromOGCUnit(((DistanceBufferOperator) filter).getDistanceUnits());
String within = filter instanceof DWithin ? "TRUE" : "FALSE";
out.write("SDO_WITHIN_DISTANCE(");
e1.accept(this, extraData);
out.write(",");
e2.accept(this, extraData);
// encode the unit verbatim when available
if (unit != null && !"".equals(unit.trim())) {
unit = escapeLiteral(unit);
out.write(",'distance=" + distance + " unit=" + unit + "') = '" + within + "' ");
} else out.write(",'distance=" + distance + "') = '" + within + "' ");
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testDWithinFilterWithUnitEscaping() throws Exception {
Coordinate coordinate = new Coordinate();
DWithin dwithin =
ff.dwithin(
ff.property("GEOM"), ff.literal(gf.createPoint(coordinate)), 10.0, "'FOO");
String encoded = encoder.encodeToString(dwithin);
assertEquals(
"WHERE SDO_WITHIN_DISTANCE(\"GEOM\",?,'distance=10.0 unit=''FOO') = 'TRUE' ",
encoded);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testFunctionJsonArrayContainsEscapingExpected() throws Exception {
Function function =
ff.function(
"jsonArrayContains",
ff.property("operations"),
ff.literal("/operations/parameters"),
ff.literal("'FOO"));
Filter filter = ff.equals(function, ff.literal(true));
String encoded = encoder.encodeToString(filter);
assertEquals(
"WHERE json_exists(operations, '$.operations.parameters?(@ == \"''FOO\")')",
encoded);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testFunctionJsonArrayContainsEscapingPointer() throws Exception {
Function function =
ff.function(
"jsonArrayContains",
ff.property("operations"),
ff.literal("/'FOO"),
ff.literal(1));
Filter filter = ff.equals(function, ff.literal(true));
String encoded = encoder.encodeToString(filter);
assertEquals("WHERE json_exists(operations, '$.''FOO?(@ == \"1\")')", encoded);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
private static String escapeJsonLiteral(String literal) {
return EscapeSql.escapeLiteral(literal, true, true);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
private void encodeJsonArrayContains(Function jsonArrayContains) throws IOException {
PropertyName column = (PropertyName) getParameter(jsonArrayContains, 0, true);
Literal jsonPath = (Literal) getParameter(jsonArrayContains, 1, true);
Expression expected = getParameter(jsonArrayContains, 2, true);
String[] strJsonPath = escapeJsonLiteral(jsonPath.getValue().toString()).split("/");
if (strJsonPath.length > 0) {
column.accept(delegate, null);
out.write("::jsonb @> '{ ");
out.write(buildJsonFromStrPointer(strJsonPath, 0, expected));
out.write(" }'::jsonb");
} else {
throw new IllegalArgumentException(
"Cannot encode filter Invalid pointer " + jsonPath.getValue());
}
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public String buildJsonFromStrPointer(String[] pointers, int index, Expression expected) {
if (pointers[index].isEmpty()) {
return buildJsonFromStrPointer(pointers, index + 1, expected);
} else if (index == pointers.length - 1) {
String strExpected = escapeJsonLiteral(expected.evaluate(null, String.class));
if (getBaseType(expected).isAssignableFrom(String.class)) {
strExpected = '"' + strExpected + '"';
}
return String.format("\"%s\": [%s]", pointers[index], strExpected);
} else {
String jsonPointers = buildJsonFromStrPointer(pointers, index + 1, expected);
return String.format("\"%s\": { %s }", pointers[index], jsonPointers);
}
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
private void checkStandardConformingStrings(Connection conn) throws SQLException {
Boolean escape = null;
// first, try to determine the setting from a native connection object
try {
PgConnection bc = unwrapConnection(conn, PgConnection.class);
escape = !bc.getStandardConformingStrings();
} catch (SQLException e) {
LOGGER.log(Level.FINER, "Unable to get native connection; falling back to query", e);
}
// otherwise, try to determine the setting from a database query
if (escape == null) {
Statement st = null;
ResultSet rs = null;
try {
st = conn.createStatement();
rs = st.executeQuery("SHOW standard_conforming_strings");
escape = !rs.next() || !"on".equals(rs.getString(1));
} catch (SQLException e) {
LOGGER.warning(
"Unable to check standard_conforming_strings setting: " + e.getMessage());
} finally {
dataStore.closeSafe(rs);
dataStore.closeSafe(st);
}
}
// default to escape backslashes if both checks failed
escapeBackslash = !Boolean.FALSE.equals(escape);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public FilterToSQL createFilterToSQL() {
PostgisFilterToSQL sql = new PostgisFilterToSQL(this);
sql.setLooseBBOXEnabled(looseBBOXEnabled);
sql.setEncodeBBOXFilterAsEnvelope(encodeBBOXFilterAsEnvelope);
sql.setFunctionEncodingEnabled(functionEncodingEnabled);
sql.setEscapeBackslash(escapeBackslash);
return sql;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public boolean isEscapeBackslash() {
return escapeBackslash;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void initializeConnection(Connection cx) throws SQLException {
super.initializeConnection(cx);
getPostgreSQLVersion(cx);
getVersion(cx);
checkStandardConformingStrings(cx);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public PreparedFilterToSQL createPreparedFilterToSQL() {
PostgisPSFilterToSql fts = new PostgisPSFilterToSql(this);
fts.setFunctionEncodingEnabled(delegate.isFunctionEncodingEnabled());
fts.setLooseBBOXEnabled(delegate.isLooseBBOXEnabled());
fts.setEncodeBBOXFilterAsEnvelope(delegate.isEncodeBBOXFilterAsEnvelope());
fts.setEscapeBackslash(delegate.isEscapeBackslash());
return fts;
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testFunctionStrEndsWithEscaping() throws Exception {
filterToSql.setFeatureType(testSchema);
Filter filter =
ff.equals(
ff.literal(true),
ff.function("strEndsWith", ff.property("testString"), ff.literal("'FOO")));
filterToSql.encode(filter);
String sql = writer.toString();
assertEquals("WHERE true = (testString LIKE ('%' || '''FOO'))", sql);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testFunctionJsonArrayContainsEscapingPointer() throws Exception {
filterToSql.setFeatureType(testSchema);
Function pointer =
ff.function(
"jsonArrayContains",
ff.property("OPERATIONS"),
ff.literal("/\"'FOO"),
ff.literal("OP1"));
filterToSql.encode(pointer);
String sql = writer.toString().trim();
assertEquals("OPERATIONS::jsonb @> '{ \"\\\"''FOO\": [\"OP1\"] }'::jsonb", sql);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testFunctionStrStartsWithEscaping() throws Exception {
filterToSql.setFeatureType(testSchema);
Filter filter =
ff.equals(
ff.literal(true),
ff.function(
"strStartsWith", ff.property("testString"), ff.literal("'FOO")));
filterToSql.encode(filter);
String sql = writer.toString();
assertEquals("WHERE true = (testString LIKE ('''FOO' || '%'))", sql);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
public void testFunctionJsonArrayContainsNumber() throws Exception {
filterToSql.setFeatureType(testSchema);
Function pointer =
ff.function(
"jsonArrayContains",
ff.property("OPERATIONS"),
ff.literal("/operations"),
ff.literal(1));
filterToSql.encode(pointer);
String sql = writer.toString().trim();
assertEquals("OPERATIONS::jsonb @> '{ \"operations\": [1] }'::jsonb", sql);
} | 1 | Java | CWE-89 | Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') | The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. | https://cwe.mitre.org/data/definitions/89.html | safe |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.