Skip to content

base_geoengine: indirect geo-domain key interpolates an unvalidated column name into SQL #472

Open

Description

@lesdekock

Summary

In the indirect (dict) form of a geo domain, the column half of the caller-supplied key is interpolated into SQL without validation or quoting. Because domains routinely arrive from client RPC, an authenticated user who can search/search_read a model carrying a GeoField can influence the generated SQL.

Where

base_geoengine/expressions.py, the dict-value branch:

i = key.rfind(".")
rel_model = key[0:i]
rel_col = key[i + 1 :]          # ← caller-controlled
rel_model = model.env[rel_model]
...
rel_query.add_where(
    f'"{alias}"."{left}" {GEO_OPERATORS[operator]} {rel_alias}.{rel_col}'   # ← raw
)

rfind(".") splits on the last dot, so a key like res.partner.<payload> resolves rel_model to a real model (env[...] succeeds) while rel_col carries the payload straight into the f-string.

Why it is reachable

The module extends the operator allowlist at import (TERM_OPERATORS), so a domain containing e.g. geo_intersect passes Odoo's operator validation and reaches this code. Record rules do not help — the interpolation happens while the query is being built, before row filtering.

Affected

Present on 16.0, 17.0, 18.0 (expressions.py, the rel_col = key[i+1:] line on each), and carried into the 19.0 migration in #465.

Fix (proven downstream)

Validate that the column names a GeoField of the related model before it can reach SQL — an allowlist by construction:

rel_field = rel_model._fields.get(rel_col)
if rel_field is None or not isinstance(rel_field, GeoField):
    raise ValueError(
        f"Invalid geo reference {key!r}: {rel_col!r} is not a"
        f" geo field of {rel_model._name!r}"
    )

We carry a vendored derivative and shipped this with a regression test (a crafted non-GeoField suffix must raise rather than reach SQL). Happy to PR against whichever branches the maintainers want; flagging first in case you prefer to coordinate the fix across the stable series.

Activity

  1. leNeo commented on Nov 6, 2026

    @leNeo

    Thanks @lesdekock for flagging this.
    I’ve opened #495 on 16.0, following your allowlist approach: the column must be an actual GeoField of the related model, otherwise a ValueError is raised. It comes with regression tests for a non-geo column and an injection attempt.
    Forward-ports to 17.0, 18.0 and 19.0 will follow once merged.

    Your review would be very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions