Skip to content

Commit 63a9dd0

Browse files
committed
fix: apply PostgreSQL dangerous-function rules to Excel and Kingbase
1 parent d540309 commit 63a9dd0

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎backend/apps/db/db.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,9 @@ def get_dangerous_functions(ds_type: str) -> set:
12251225
"""获取危险函数(通用 + 特定数据源)"""
12261226
functions = COMMON_DANGEROUS_FUNCTIONS.copy()
12271227
ds_key = ds_type.lower() if ds_type else ''
1228+
# Excel 使用内部 PostgreSQL,Kingbase 使用 PostgreSQL 兼容的文件函数规则。
1229+
if ds_key in {'excel', 'kingbase'}:
1230+
ds_key = 'pg'
12281231
if ds_key in DS_SPECIFIC_DANGEROUS_FUNCTIONS:
12291232
functions.update(DS_SPECIFIC_DANGEROUS_FUNCTIONS[ds_key])
12301233
return functions

‎backend/tests/test_postgres_denylist.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def test_every_dialect_key_is_a_db_type():
4444
assert not unknown, f"denylist keys that no DB type uses: {sorted(unknown)}"
4545

4646

47-
def test_postgres_functions_are_resolved_from_the_pg_type():
48-
functions = get_dangerous_functions(DB.pg.type)
47+
@pytest.mark.parametrize("db", [DB.pg, DB.excel, DB.kingbase])
48+
def test_postgres_functions_are_resolved_from_pg_backed_types(db):
49+
functions = get_dangerous_functions(db.type)
50+
assert PG_FILE_FUNCTIONS <= get_dangerous_functions(db.type.upper())
4951
assert PG_FILE_FUNCTIONS <= functions
5052
assert COMMON_DANGEROUS_FUNCTIONS <= functions
5153

@@ -62,8 +64,9 @@ def test_postgres_functions_are_resolved_from_the_pg_type():
6264
"SELECT lo_export(1, '/tmp/out')",
6365
],
6466
)
65-
def test_postgres_file_functions_are_rejected(sql):
66-
is_safe, reason = check_sql_read(sql, _ds(DB.pg))
67+
@pytest.mark.parametrize("db", [DB.pg, DB.excel, DB.kingbase])
68+
def test_postgres_file_functions_are_rejected(sql, db):
69+
is_safe, reason = check_sql_read(sql, _ds(db))
6770
assert not is_safe
6871
assert "dangerous function" in reason
6972

@@ -84,8 +87,9 @@ def test_postgres_write_statements_are_rejected(sql):
8487
assert not is_safe
8588

8689

87-
def test_ordinary_postgres_select_is_still_allowed():
88-
is_safe, reason = check_sql_read("SELECT id, name FROM users", _ds(DB.pg))
90+
@pytest.mark.parametrize("db", [DB.pg, DB.excel, DB.kingbase])
91+
def test_ordinary_postgres_select_is_still_allowed(db):
92+
is_safe, reason = check_sql_read("SELECT id, name FROM users", _ds(db))
8993
assert is_safe, reason
9094

9195

0 commit comments

Comments
 (0)