ckan/ckan — pull request #1871 by amercader (2014-08-05 07:42:29+00:00)
Title: Prevent reading system tables on DataStore SQL search

When querying `datastore_search_sql` we need to make sure that only DataStore related tables can be accessed. If permissions are properly set users should not be able to act on other tables, but it gives away information about the database.

This implementation calls `EXPLAIN` and parses the output to get all tables involved in the provided statement, and disallows any request that accesses restricted tables.

Eventhough the SQL search is not supported on PG 8.x, there is a fallback function to parse the output of a plain EXPLAIN statement (JSON output is not supported)