Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Naksha_2.2.29
- Fixed SQL injection via property names in property search by whitelisting allowed characters.

## Naksha_2.2.28
- Fixed the HTTP storage circuit-breaker configuration property name to `circuitBreakerConfig`.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ mavenPassword=YourPassword
# - here-naksha-lib-core/src/main/com/here/naksha/lib/core/NakshaVersion (static property: latest)
# - here-naksha-app-service/src/main/resources/swagger/openapi.yaml (info.version property)
# - CHANGELOG.md
version=2.2.28
version=2.2.29

Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
import com.here.naksha.lib.core.models.storage.*;
import com.here.naksha.lib.core.util.ValueList;
import java.util.*;
import java.util.regex.Pattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class PropertySearchUtil {

private static final String NULL_PROP_VALUE = ".null";
private static final Pattern ALLOWED_PROPERTY_NAME = Pattern.compile("[a-zA-Z0-9@:_-]+");

private static final String SHORT_PROP_PREFIX = "p.";
private static final String FULL_PROP_PREFIX = XyzFeature.PROPERTIES + ".";
Expand Down Expand Up @@ -117,6 +119,13 @@ private PropertySearchUtil() {}
// expand key if needed (e.g. p.prop_1 should be properties.prop_1)
final String[] propPath = expandKeyToRealJsonPath(propKey);
if (propPath == null) return null;
// whitelist allowed characters in each path segment to prevent SQL injection through property names
for (final String segment : propPath) {
if (!ALLOWED_PROPERTY_NAME.matcher(segment).matches()) {
throw new XyzErrorException(
XyzError.ILLEGAL_ARGUMENT, "Unsupported prop key supplied: %s".formatted(propKey));
}
}

// iterate through all given values for a key
int delimIdx = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ servers:
info:
title: "Naksha Hub-API"
description: "Naksha Hub-API is a REST API to provide simple access to geo data."
version: "2.2.28"
version: "2.2.29"

security:
- AccessToken: [ ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.here.naksha.app.common.CommonApiTestSetup.setupSpaceAndRelatedResources;
import static com.here.naksha.app.common.TestUtil.loadFileOrFail;
import static com.here.naksha.app.common.TestUtil.urlEncoded;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.here.naksha.app.common.ApiTest;
import com.here.naksha.app.common.NakshaTestWebClient;
Expand All @@ -29,7 +30,7 @@
import java.net.URISyntaxException;
import java.net.http.HttpResponse;
import java.util.UUID;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -254,4 +255,23 @@ void tc1009_testSearchWithArrayBasedPropPathFilter() throws URISyntaxException,
.hasStreamIdHeader(streamId)
.hasJsonBody(expectedBodyPart, "Get Feature response body doesn't match");
}

@Test
void tc1010_testSearchRejectsSqlInjectionInPropertyKey() throws Exception {
final String streamId = UUID.randomUUID().toString();
final String query = "limit=1&p.a.b%5C.%29%20IS%20NULL%20AND%20%28%3F%20IS%20NOT%20NULL%29%20AND%20%281%3D1%29%29--%20=1";

final HttpResponse<String> response = nakshaClient.get("hub/spaces/" + SPACE_ID + "/search?" + query, streamId);

ResponseAssertions.assertThat(response)
.hasStatus(400)
.hasStreamIdHeader(streamId)
.hasJsonBody("""
{"type":"ErrorResponse", "error":"IllegalArgument"}
""");
assertEquals(
"Unsupported prop key supplied: p.a.b\\.) IS NULL AND (? IS NOT NULL) AND (1=1))-- ",
new JSONObject(response.body()).getString("errorMessage"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ public static Stream<Arguments> queryParams() {
),
Pair.of("properties.long_or=1,2,3,4,4,4,3,2,1,true,false", "properties.long_or=1,2,3,4,4,4,3,2,1,true,false"),
Pair.of("properties.very.very.very.nested.even.more=1", "properties.very.very.very.nested.even.more=1"),
Pair.of(
// Naksha does not interpret encoded %3E (">" sign) as a gt operation and passes it as properties.prop_> path with "=" operation
"properties.prop%3E=value_2,value_22",
// Http storege actually sends request with ">" reencoded to %3E, but Wiremock expects decoded string in verify matcher
"properties.prop>=value_2,value_22"
),
Pair.of("properties.prop=gte=2,22", "properties.prop=gte=2,22"),
Pair.of("properties.prop=lte=1", "properties.prop=lte=1"),
Pair.of("properties.prop=.null", "properties.prop=.null"),
Pair.of("properties.prop=null", "properties.prop=null"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,14 @@ private static Stream<Arguments> propQueriesWithException() {
propQuerySpec("p.prop_1=gt=false", "Exception for invalid boolean operation =gt="),
propQuerySpec("p.prop_1=lt=false", "Exception for invalid boolean operation =lt="),
propQuerySpec("p.prop_1=gte=false", "Exception for invalid boolean operation =gte="),
propQuerySpec("p.prop_1=lte=false", "Exception for invalid boolean operation =lte=")
propQuerySpec("p.prop_1=lte=false", "Exception for invalid boolean operation =lte="),
// SQL injection attempts in property key
propQuerySpec(urlEncoded("p.a.b\\.) IS NULL AND (? IS NOT NULL) AND (1=1))-- ") + "=1",
"Exception for SQL injection payload in key"),
propQuerySpec(urlEncoded("p.a') OR 1=1--") + "=1", "Exception for quote and parenthesis in key"),
propQuerySpec("p.a%20b=1", "Exception for space in key"),
propQuerySpec(urlEncoded("f.a;DROP TABLE x") + "=1", "Exception for semicolon in xyz key"),
propQuerySpec(urlEncoded("properties.a\"b") + "=1", "Exception for double quote in full key")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ public class NakshaVersion implements Comparable<NakshaVersion> {
public static final String v2_2_26 = "2.2.26";
public static final String v2_2_27 = "2.2.27";
public static final String v2_2_28 = "2.2.28";
public static final String v2_2_29 = "2.2.29";

/**
* The latest version of the naksha-extension stored in the resources.
*/
@AvailableSince(v2_0_5)
public static final NakshaVersion latest = of(v2_2_27);
public static final NakshaVersion latest = of(v2_2_29);

private final int major;
private final int minor;
Expand Down
Loading