Postgres Security Patches Related to the Search Path
What is the search path?
What is search_path? Postgres has a database/schema/table hierarchy. If you specify a table without the schema, then Postgres will look for the table within the schemas listed in the search path. See https://www.postgresql.org/docs/12/runtime-config-client.html Here's the default search_path:postgres=# show search_path; search_path ----------------- "$user", publicExample of not using schema name in query:
postgres=# select * from firstname limit 5; first_name ------------ Aach Aachie Aachje Aacht Aachte (5 rows)
Exploit Pathways and Remediations
Functions are one way malicious users can exploit default search paths. After the first security hole was found, here were some remediations. (And these continue to inform best practices.) https://wiki.postgresql.org/wiki/A_Guide_to_CVE-2018-1058%3A_Protect_Your_Search_Path The patch to that CVE https://github.com/postgres/postgres/commit/582edc369cdbd348d68441fc50fa26a84afd0c1a forced an empty search path for some users/backend processes. Here's the code to empty the search path: https://github.com/postgres/postgres/blob/cec57b1a0fbcd3833086ba686897c5883e0a2afc/src/include/common/connect.h#L25 If you do that on your command line, the schema is required in queries:postgres=# SELECT pg_catalog.set_config('search_path', '', false);
postgres=# select * from firstname limit 5;
ERROR: relation "firstname" does not exist
LINE 1: select * from firstname limit 5;
^
postgres=# select * from public.firstname limit 5;
first_name
------------
Aach
Aachie
Aachje
Aacht
Aachte
(5 rows) This "empty search path" has been extended this week to cover an additional security hole, in logical replication and extensions:
https://github.com/postgres/postgres/commit/11da97024abbe76b8c81e3f2375b2a62e9717c67
Recommendations
Security patches available should be applied, especially for users of logical replication. The patch unfortunately doesn't cover all pathways to malicious use of extensions, but should be done anyway. As a stopgap (especially, for example on managed cloud installations) until this can be updated, follow the tips in https://wiki.postgresql.org/wiki/A_Guide_to_CVE-2018-1058%3A_Protect_Your_Search_PathOn this page
Share this
Share this
More resources
Learn more about Pythian by reading the following blogs and articles.
Oracle Database 12c Patching: DBMS_QOPATCH, OPATCH_XML_INV, and datapatch
Oracle Database 12c Patching: DBMS_QOPATCH, OPATCH_XML_INV, and datapatch
Jan 20, 2015 12:00:00 AM
12
min read
Postgres partial indexes on email address domains
Postgres partial indexes on email address domains
Aug 20, 2020 12:00:00 AM
3
min read
SQL for Pattern Matching in Oracle 12c
SQL for Pattern Matching in Oracle 12c
Jul 5, 2013 12:00:00 AM
5
min read
Ready to unlock value from your data?
With Pythian, you can accomplish your data transformation goals and more.