From b009b93906eff53a883436468dbb59f5e1820b85 Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Fri, 13 Nov 2026 10:43:31 +0100 Subject: [PATCH 1/7] NAKSHA-293: fix sql injectin bulnerability Signed-off-by: Marcin-Here --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- .../naksha/app/service/http/ops/PropertySearchUtil.java | 6 ++++++ .../src/main/resources/swagger/openapi.yaml | 2 +- .../naksha/app/service/util/PropertySearchUtilTest.java | 9 ++++++++- .../java/com/here/naksha/lib/core/NakshaVersion.java | 3 ++- 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25cabde74b..79f8027ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/gradle.properties b/gradle.properties index 65da4b7329..46d4ad7a27 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java b/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java index 7651d5ada1..72470d5aba 100644 --- a/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java +++ b/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java @@ -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_PATH = Pattern.compile("[a-zA-Z0-9@:._-]+"); private static final String SHORT_PROP_PREFIX = "p."; private static final String FULL_PROP_PREFIX = XyzFeature.PROPERTIES + "."; @@ -101,6 +103,10 @@ private PropertySearchUtil() {} } else { return null; // excluding non-supported prop-search key } + // whitelist allowed characters to prevent SQL injection through property names + if (!ALLOWED_PROPERTY_PATH.matcher(str).matches()) { + throw new XyzErrorException(XyzError.ILLEGAL_ARGUMENT, "Property path contains unsupported characters"); + } return str.toString().split("\\."); } diff --git a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml index bdef4f1606..2eaf0f52ea 100644 --- a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml +++ b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml @@ -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: [ ] diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/util/PropertySearchUtilTest.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/util/PropertySearchUtilTest.java index 864ec698ba..196ac9f0d5 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/util/PropertySearchUtilTest.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/util/PropertySearchUtilTest.java @@ -229,7 +229,14 @@ private static Stream 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") ); } diff --git a/here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java b/here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java index 8211b1a8d4..6bd3ca13be 100644 --- a/here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java +++ b/here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java @@ -86,12 +86,13 @@ public class NakshaVersion implements Comparable { 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; From b6a4ee634961ce8943c222af0a2d069343dec8c4 Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Fri, 13 Nov 2026 11:07:14 +0100 Subject: [PATCH 2/7] NAKSHA-293: moved check and added info in exception. Signed-off-by: Marcin-Here --- .../app/service/http/ops/PropertySearchUtil.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java b/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java index 72470d5aba..302ff01827 100644 --- a/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java +++ b/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java @@ -41,7 +41,7 @@ public class PropertySearchUtil { private static final String NULL_PROP_VALUE = ".null"; - private static final Pattern ALLOWED_PROPERTY_PATH = Pattern.compile("[a-zA-Z0-9@:._-]+"); + 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 + "."; @@ -103,10 +103,6 @@ private PropertySearchUtil() {} } else { return null; // excluding non-supported prop-search key } - // whitelist allowed characters to prevent SQL injection through property names - if (!ALLOWED_PROPERTY_PATH.matcher(str).matches()) { - throw new XyzErrorException(XyzError.ILLEGAL_ARGUMENT, "Property path contains unsupported characters"); - } return str.toString().split("\\."); } @@ -123,6 +119,14 @@ 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, + "Invalid key %s, allowed characters: [a-zA-Z0-9@:._-]".formatted(propKey)); + } + } // iterate through all given values for a key int delimIdx = 0; From 2770d11f68f039ce82ad3eba031a7f257853f621 Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Fri, 13 Nov 2026 16:46:13 +0100 Subject: [PATCH 3/7] NAKSHA-293: adjusted test and fix docs Signed-off-by: Marcin-Here --- .../src/main/resources/swagger/openapi.yaml | 19 +++++++++---------- .../testutil/PropertySearchSamples.java | 7 +------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml index 2eaf0f52ea..804e9bc14b 100644 --- a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml +++ b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml @@ -1160,21 +1160,20 @@ components: Additionally, to the operators used in the examples above, the query can be written, with the same semantic, by using the long operators: "=gte=", "=lte=", "=gt=", "=lt=" and "=cs=". - The following queries yield the same result: - * ?p.property_name_1>=10 + For example: * ?p.property_name_1=gte=10 The available operators are: - - "=" - equals - - "!=" - not equals + - "=" or "=eq=" - equals + - "=ne=" - not equals - "=.null" - is null - - "!=.null" - is not null - - ">=" or "=gte=" - greater than or equals - - "<=" or "=lte=" - less than or equals - - ">" or "=gt=" - greater than - - "<" or "=lt=" - less than - - "@>" or "=cs=" - Array contains + - "=ne=.null" - is not null + - "=gte=" - greater than or equals + - "=lte=" - less than or equals + - "=gt=" - greater than + - "=lt=" - less than + - "=cs=" - Array contains explode: true schema: type: object diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/testutil/PropertySearchSamples.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/testutil/PropertySearchSamples.java index 5d0f69bf1d..b399e126a9 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/testutil/PropertySearchSamples.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/testutil/PropertySearchSamples.java @@ -22,12 +22,7 @@ public static Stream 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"), From 518b4f38d4a19700c6a5fd190ba991a0c2a19d0e Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Mon, 16 Nov 2026 10:02:06 +0100 Subject: [PATCH 4/7] NAKSHA-293: updated docs Signed-off-by: Marcin-Here --- .../src/main/resources/swagger/openapi.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml index 804e9bc14b..04f7135205 100644 --- a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml +++ b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml @@ -1166,9 +1166,9 @@ components: The available operators are: - "=" or "=eq=" - equals - - "=ne=" - not equals + - "!=" or "=ne=" - not equals - "=.null" - is null - - "=ne=.null" - is not null + - "!=.null" or "=ne=.null" - is not null - "=gte=" - greater than or equals - "=lte=" - less than or equals - "=gt=" - greater than From 2c8746685f4729c8640fb1e6f5f7a02d87ab7240 Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Mon, 16 Nov 2026 10:34:41 +0100 Subject: [PATCH 5/7] NAKSHA-293: added service test. Signed-off-by: Marcin-Here --- .../app/service/SearchFeaturesTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/SearchFeaturesTest.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/SearchFeaturesTest.java index a18484ab73..0c4884f978 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/SearchFeaturesTest.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/SearchFeaturesTest.java @@ -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; @@ -30,6 +31,7 @@ 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; @@ -254,4 +256,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 response = nakshaClient.get("hub/spaces/" + SPACE_ID + "/search?" + query, streamId); + + ResponseAssertions.assertThat(response) + .hasStatus(400) + .hasStreamIdHeader(streamId) + .hasJsonBody(""" + {"type":"ErrorResponse", "error":"IllegalArgument"} + """); + assertEquals( + "Invalid key p.a.b\\.) IS NULL AND (? IS NOT NULL) AND (1=1))-- , allowed characters: [a-zA-Z0-9@:._-]", + new JSONObject(response.body()).getString("errorMessage")); + } + } From 8237533c0fea4225ca93079e8607b6b2f0de5b8c Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Mon, 16 Nov 2026 11:34:17 +0100 Subject: [PATCH 6/7] NAKSHA-293: updated swagger docs. Signed-off-by: Marcin-Here --- .../src/main/resources/swagger/openapi.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml index 04f7135205..2eaf0f52ea 100644 --- a/here-naksha-app-service/src/main/resources/swagger/openapi.yaml +++ b/here-naksha-app-service/src/main/resources/swagger/openapi.yaml @@ -1160,20 +1160,21 @@ components: Additionally, to the operators used in the examples above, the query can be written, with the same semantic, by using the long operators: "=gte=", "=lte=", "=gt=", "=lt=" and "=cs=". - For example: + The following queries yield the same result: + * ?p.property_name_1>=10 * ?p.property_name_1=gte=10 The available operators are: - - "=" or "=eq=" - equals - - "!=" or "=ne=" - not equals + - "=" - equals + - "!=" - not equals - "=.null" - is null - - "!=.null" or "=ne=.null" - is not null - - "=gte=" - greater than or equals - - "=lte=" - less than or equals - - "=gt=" - greater than - - "=lt=" - less than - - "=cs=" - Array contains + - "!=.null" - is not null + - ">=" or "=gte=" - greater than or equals + - "<=" or "=lte=" - less than or equals + - ">" or "=gt=" - greater than + - "<" or "=lt=" - less than + - "@>" or "=cs=" - Array contains explode: true schema: type: object From 5fb9d885b2e512289ce89aa7f18d70ea39eb1ed1 Mon Sep 17 00:00:00 2001 From: Marcin-Here Date: Wed, 18 Nov 2026 09:45:53 +0100 Subject: [PATCH 7/7] NAKSHA-293: adjusted exception message. Signed-off-by: Marcin-Here --- .../here/naksha/app/service/http/ops/PropertySearchUtil.java | 3 +-- .../java/com/here/naksha/app/service/SearchFeaturesTest.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java b/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java index 302ff01827..a247c946dc 100644 --- a/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java +++ b/here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/PropertySearchUtil.java @@ -123,8 +123,7 @@ private PropertySearchUtil() {} for (final String segment : propPath) { if (!ALLOWED_PROPERTY_NAME.matcher(segment).matches()) { throw new XyzErrorException( - XyzError.ILLEGAL_ARGUMENT, - "Invalid key %s, allowed characters: [a-zA-Z0-9@:._-]".formatted(propKey)); + XyzError.ILLEGAL_ARGUMENT, "Unsupported prop key supplied: %s".formatted(propKey)); } } diff --git a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/SearchFeaturesTest.java b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/SearchFeaturesTest.java index 0c4884f978..f84a04815b 100644 --- a/here-naksha-app-service/src/test/java/com/here/naksha/app/service/SearchFeaturesTest.java +++ b/here-naksha-app-service/src/test/java/com/here/naksha/app/service/SearchFeaturesTest.java @@ -30,7 +30,6 @@ 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; @@ -271,7 +270,7 @@ void tc1010_testSearchRejectsSqlInjectionInPropertyKey() throws Exception { {"type":"ErrorResponse", "error":"IllegalArgument"} """); assertEquals( - "Invalid key p.a.b\\.) IS NULL AND (? IS NOT NULL) AND (1=1))-- , allowed characters: [a-zA-Z0-9@:._-]", + "Unsupported prop key supplied: p.a.b\\.) IS NULL AND (? IS NOT NULL) AND (1=1))-- ", new JSONObject(response.body()).getString("errorMessage")); }