Skip to content

fix: apply the PostgreSQL dangerous-function denylist under the pg datasource type - #1439

Open
compiler-segfault wants to merge 1 commit into
dataease:mainfrom
compiler-segfault:fix/postgres-denylist-dialect-key
Open

compiler-segfault wants to merge 1 commit into
dataease:mainfrom
compiler-segfault:fix/postgres-denylist-dialect-key

Conversation

@compiler-segfault

Copy link
Copy Markdown

What's wrong

check_sql_read resolves the dangerous-function denylist through get_dangerous_functions(ds.type), and ds.type for a PostgreSQL datasource is the DB enum value pg (backend/apps/db/constant.py:29). The table itself was keyed postgresql, so the lookup never matched and the whole PostgreSQL entry was dead:

get_dangerous_functions("pg")          # {'version', 'current_user', 'user', 'database'}
get_dangerous_functions("postgresql")  # + pg_read_file, pg_write_file, lo_import, lo_export

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.type values 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.py drives the real guard rather than the table alone:

  • the seven PostgreSQL file functions resolve and are rejected by check_sql_read with a dangerous function reason,
  • INSERT / UPDATE / DELETE / TRUNCATE / COPY / DROP stay rejected on PostgreSQL,
  • an ordinary SELECT is still allowed,
  • every key in DS_SPECIFIC_DANGEROUS_FUNCTIONS is a DB.type value, so a key mismatch cannot silently disable a dialect again,
  • the SQL Server / MySQL entries are unchanged and do not leak across dialects.
pytest backend/tests/test_postgres_denylist.py   17 passed
ruff check / ruff format --check                 clean

Same suite against the unpatched file: 9 failed, 8 passed.

Fixes #1438

…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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL denylist missed because dialect key lookup is wrong

1 participant