Skip to content

Commit 4f1a9c6

Browse files
Hotfix v0.2429.3 (#1433)
* fix: BI-6865 Fix YDB DB_CALL vulnerability (#1432) fix * fix: BI-6865 Fix function name collisions between source and sqlalchemy for DB_CALL (#1430) fix --------- Co-authored-by: Denis Khamitov <khamitovdr@yandex-team.ru>
1 parent 8b3cd15 commit 4f1a9c6

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

lib/dl_connector_clickhouse/dl_connector_clickhouse_tests/db/formula/test_functions_native.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_native_functions(self, dbe: DbEvaluator) -> None:
2222
assert dbe.eval('DB_CALL_INT("sign", -5)') == -1
2323
assert dbe.eval('DB_CALL_INT("sign", 5)') == 1
2424
assert dbe.eval('DB_CALL_INT("positionCaseInsensitive", "Hello", "l")') == 3
25+
assert dbe.eval('DB_CALL_INT("CAST", "3", "UInt32")') == 3
2526

2627
# DB_CALL_FLOAT
2728
assert dbe.eval('DB_CALL_FLOAT("sign", -5.0)') == -1.0
@@ -30,6 +31,7 @@ def test_native_functions(self, dbe: DbEvaluator) -> None:
3031

3132
# DB_CALL_STRING
3233
assert dbe.eval('DB_CALL_STRING("reverse", "hello")') == "olleh"
34+
assert dbe.eval('DB_CALL_STRING("CAST", 3, "String")') == "3"
3335

3436
# DB_CALL_BOOL
3537
assert dbe.eval('DB_CALL_BOOL("isFinite", 5)') == True

lib/dl_connector_ydb/dl_connector_ydb/formula/definitions/functions_native.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

3-
import sqlalchemy as sa
43
from sqlalchemy.sql.elements import ClauseElement
4+
from sqlalchemy.sql.functions import Function as SqlFunction
55

66
from dl_formula.core.nodes import LiteralString
77
from dl_formula.definitions.base import (
@@ -24,11 +24,7 @@ def _call_native_impl_yql(func_name_ctx: TranslationCtx, *args: TranslationCtx)
2424
# Validate function name
2525
if re.match(r"^[a-zA-Z0-9_]+::[a-zA-Z0-9_]+$", func_name):
2626
namespace, function = func_name.split("::")
27-
28-
namespace = getattr(sa.func, namespace)
29-
function = getattr(namespace, function)
30-
31-
return function(*(arg.expression for arg in args))
27+
return SqlFunction(function, *(arg.expression for arg in args), packagenames=(namespace,))
3228

3329
return base._call_native_impl(func_name_ctx, *args)
3430

lib/dl_formula/dl_formula/definitions/functions_native.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

3-
import sqlalchemy as sa
43
from sqlalchemy.sql.elements import ClauseElement
4+
from sqlalchemy.sql.functions import Function as SqlFunction
55

66
from dl_formula.core import exc
77
from dl_formula.core.datatype import DataType
@@ -28,7 +28,7 @@ def _call_native_impl(func_name_ctx: TranslationCtx, *args: TranslationCtx) -> C
2828
if not re.match(r"^[a-zA-Z0-9_]+$", func_name):
2929
raise exc.NativeFunctionForbiddenInputError(func_name)
3030

31-
return getattr(sa.func, func_name)(*(arg.expression for arg in args))
31+
return SqlFunction(func_name, *(arg.expression for arg in args))
3232

3333

3434
class DBCall(Function):

0 commit comments

Comments
 (0)