Skip to content
Open
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
7 changes: 7 additions & 0 deletions base_geoengine/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
28 changes: 28 additions & 0 deletions base_geoengine/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading