From 07dee61c5fd15631875ec440fd8f23bf6154541c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Siffert?= Date: Fri, 6 Nov 2026 17:10:16 +0000 Subject: [PATCH] [FIX] base_geoengine: validate the column of indirect geo domains In an indirect geo domain such as ("the_point", "geo_intersect", {"dummy.zip.the_geom": [...]}) the part of the key after the last dot was interpolated as is into the generated SQL. Since domains come from RPC calls, any user allowed to search a model with a GeoField could inject SQL through that key, e.g. {"dummy.zip.the_geom) OR (1=1": [...]}. Only accept the name of an actual GeoField of the related model and raise a ValueError otherwise, as Odoo does for an invalid field in a leaf. Add regression tests for a non-geo column and for an injection attempt. Fixes #472 --- base_geoengine/expressions.py | 7 +++++++ base_geoengine/tests/test_model.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/base_geoengine/expressions.py b/base_geoengine/expressions.py index 2a3deccc2..1eff2a575 100644 --- a/base_geoengine/expressions.py +++ b/base_geoengine/expressions.py @@ -51,6 +51,13 @@ def __leaf_to_sql(self, leaf, model, alias): rel_model = key[0:i] rel_col = key[i + 1 :] rel_model = model.env[rel_model] + # rel_col is interpolated into the SQL below: only accept + # the name of an actual GeoField of the related model + if not isinstance(rel_model._fields.get(rel_col), GeoField): + raise ValueError( + f"Invalid geo field {rel_col!r} on model " + f"{rel_model._name!r} in leaf {leaf!r}" + ) # we compute the attributes search on spatial rel if ref_search[key]: rel_alias = ( diff --git a/base_geoengine/tests/test_model.py b/base_geoengine/tests/test_model.py index 12faceb2a..c15570d53 100644 --- a/base_geoengine/tests/test_model.py +++ b/base_geoengine/tests/test_model.py @@ -425,6 +425,34 @@ def test_search_intersect_with_dict_id(self): ) self.assertEqual(len(result.ids), 5) + def test_search_indirect_rejects_non_geo_column(self): + """The column of an indirect geo domain key must be a GeoField""" + retails = self.env["retail.machine"] + with self.assertRaises(ValueError): + retails.search( + [ + ( + "the_point", + "geo_intersect", + {"dummy.zip.name": [("id", "!=", 0)]}, + ) + ] + ) + + def test_search_indirect_rejects_sql_in_column(self): + """SQL injected through an indirect geo domain key must not run""" + retails = self.env["retail.machine"] + with self.assertRaises(ValueError): + retails.search( + [ + ( + "the_point", + "geo_intersect", + {"dummy.zip.the_geom) OR (1=1": [("id", "!=", 0)]}, + ) + ] + ) + def test_search_intersect_for_zip_1169_with_multiple_domain(self): retails = self.env["retail.machine"] result = retails.search(