hello-stephen commented on code in PR #71116:
URL: https://github.com/apache/doris/pull/71116#discussion_r4730876203
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/NeedAuditEncryption.java:
##########
@@ -46,4 +51,22 @@ static String maskSql(String sql, boolean
preserveFormatting) {
parser.parseForEncryption(sql, indexInSqlToString, preserveFormatting);
return BaseViewInfo.rewriteSql(indexInSqlToString, sql);
}
+
+ /**
+ * Whether the plan reads a table-valued function, whose properties can
hold credentials: as a relation, in a CTE
+ * or in a subquery. The queries of a CTE and of a subquery are not
children of the plan nodes that hold them.
+ */
+ static boolean readsTableValuedFunction(Plan plan) {
+ return plan.anyMatch(node -> node instanceof TVFRelation
+ || (node instanceof LogicalCTE && ((LogicalCTE<?>)
node).getAliasQueries().stream()
+
.anyMatch(NeedAuditEncryption::readsTableValuedFunction))
+ || ((Plan) node).getExpressions().stream()
+
.anyMatch(NeedAuditEncryption::subqueryReadsTableValuedFunction));
+ }
+
+ /** Whether the expression holds a subquery that reads a table-valued
function */
+ static boolean subqueryReadsTableValuedFunction(Expression expression) {
+ return expression.anyMatch(node -> node instanceof SubqueryExpr
Review Comment:
[P2] Traverse star replacement aliases when looking for subqueries
For a table `t(k BIGINT)`, `SELECT * REPLACE ((SELECT max(number) FROM
numbers('number'='1', 's3.secret_key'='secret')) AS k) FROM t` still bypasses
masking. `UnboundStar` stores `getReplacedAlias()` outside its expression
children, so this `anyMatch` never reaches the scalar subquery and
`needAuditEncryption()` returns false. Audit retains the original parsed tree
after star expansion, and `geneEncryptionSQL()` consequently returns the SQL
with the plaintext credential. Please recurse into replacement aliases too (as
`InsertUtils.resolveDefaultReferences` already does) and add this form to the
masking tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]