Repository navigation
fix: apply the PostgreSQL dangerous-function denylist under the pg datasource type - #1439
Open
compiler-segfault wants to merge 1 commit into
Open
compiler-segfault wants to merge 1 commit into
compiler-segfault wants to merge 1 commit into
Conversation
…tasource type DS_SPECIFIC_DANGEROUS_FUNCTIONS is looked up with ds.type, and PostgreSQL datasources carry the DB enum value 'pg' (apps/db/constant.py), not 'postgresql'. The table was keyed 'postgresql', so pg_read_file, pg_write_file, lo_import and lo_export were never blocked for PostgreSQL datasources. Key the entry by the DB type, and cover the rest of the server-side file readers that belong to the same family (pg_read_binary_file, pg_ls_dir, pg_stat_file). Regression coverage drives check_sql_read instead of the table alone, pins every denylist key to a DB type so a mismatch cannot silently disable a dialect again, and checks that INSERT/UPDATE/DELETE/TRUNCATE/COPY/DROP stay rejected on PostgreSQL. Refs dataease#1438
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
check_sql_readresolves the dangerous-function denylist throughget_dangerous_functions(ds.type), andds.typefor a PostgreSQL datasource is theDBenum valuepg(backend/apps/db/constant.py:29). The table itself was keyedpostgresql, so the lookup never matched and the whole PostgreSQL entry was dead:SELECT pg_read_file('/etc/passwd')therefore passed the read-only guard on a PostgreSQL datasource, as reported in #1438.Fix
Key the entry by the datasource type that is actually used, and note in the table that keys must be
DB.typevalues so the next dialect cannot drift the same way.While fixing the mapping, the entry also picks up the rest of the server-side file readers that belong to the same family —
pg_read_binary_file,pg_ls_dir,pg_stat_file— which were never listed at all. Drop that part of the hunk if you would rather keep this patch to the reported four.No behaviour change for any other dialect.
Verification
New
backend/tests/test_postgres_denylist.pydrives the real guard rather than the table alone:check_sql_readwith adangerous functionreason,INSERT/UPDATE/DELETE/TRUNCATE/COPY/DROPstay rejected on PostgreSQL,SELECTis still allowed,DS_SPECIFIC_DANGEROUS_FUNCTIONSis aDB.typevalue, so a key mismatch cannot silently disable a dialect again,Same suite against the unpatched file: 9 failed, 8 passed.
Fixes #1438