You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the changes made in #7546 there is I think too much escaping being used in JOINs using PostgreSQL.
Before that change it was possible to define TABLE for the join including a schema name, e.g. JOIN ... TABLE "my_schema.my_table", which would be turned into SQL ... FROM myschema.mytable.
Since #7546, the TABLE is sent through msDefaultEscapePropertyName(), turning the generated SQL into ... FROM "myschema.mytable". Since msDefaultEscapePropertyName() functions thoroughly, it is not possible to persuade Mapserver to generate the SQL as previously.
My proposed fix is to revert the changes made in #7546 w.r.t. the escaping for TABLE. It would imho then be consistent to also revert the changes made w.r.t. escaping for TO. There should then be a documentation note added, that the author of the mapfile is responsible for providing TABLE and TO as suitably escaped strings for direct use in SQL.
Basically I'm proposing to effectively remove the following in mappostgresql.c which was added in #7546:
In my view this doesn't have any security impact as both these items can only be controlled by the author of the mapfile - neither the data contents nor the request parameters are relevant here and so an attacker cannot use them for SQL-injection.
The changes for escaping of joininfo->from_value must of course remain.
Any thoughts on this before I prepare a PR? Have I missed something in my analysis?
I believe that JOIN ... TABLE "my_schema.my_table" should be JOIN ... TABLE "my_schema"."my_table" in proper SQL. But I do not know how MapServer alters the query.
@jratike80 precisely, the problem is that myschema.mytable gets escaped as a single simple name, when it's actually a scoped name or two names ([schema name].[table name]).
The problem with doing anything between "escape as a single name" and "nothing" is that things like "my.schema"."my.table" (a table my.table in a schema my.schema) or just "my.table" (table my.table in some schema such as public on the search path) is completely valid, so any attempt to split a string at . and escape each part separately is doomed to failure at some point.
Activity
jratike80 commentedon Dec 1, 2026
I believe that
JOIN ... TABLE "my_schema.my_table"should beJOIN ... TABLE "my_schema"."my_table"in proper SQL. But I do not know how MapServer alters the query.ejn commentedon Dec 1, 2026
@jratike80 precisely, the problem is that
myschema.mytablegets escaped as a single simple name, when it's actually a scoped name or two names ([schema name].[table name]).The problem with doing anything between "escape as a single name" and "nothing" is that things like
"my.schema"."my.table"(a tablemy.tablein a schemamy.schema) or just"my.table"(tablemy.tablein some schema such aspublicon the search path) is completely valid, so any attempt to split a string at.and escape each part separately is doomed to failure at some point.ejn commentedon Dec 1, 2026
Note that if we are escaping names in PostgreSQL then we should be really using the function PQescapeIdentifier (available since PG9)...