codeant-ai-for-open-source[bot] commented on code in PR #43394:
URL: https://github.com/apache/superset/pull/43394#discussion_r3831853671


##########
superset/jinja_context.py:
##########
@@ -118,6 +118,48 @@ class TimeFilter:
     time_range: str | None
 
 
+class SQLSafeList(list[Any]):  # noqa: FURB189
+    """
+    A list of dialect-escaped values whose *whole-container* string
+    rendering cannot re-introduce raw quote characters.
+
+    Rendering a plain Python list in a Jinja template goes through
+    ``str()``/``repr()``, which wraps every string element in fresh quote
+    delimiters (and switches to double-quote delimiters when the element
+    contains a single quote, emitting that single quote raw). Either way
+    the rendered text can contain quote characters that were never
+    escaped for SQL, so a template interpolating the list inside its own
+    quotes -- e.g. ``LIKE '{{ filter.get('escaped_val') }}'`` -- could be
+    broken out of even though every string leaf was individually escaped.
+    This subclass renders as its (already-escaped) elements joined with
+    ``", "``, with no additional delimiters, so every quote in the output
+    is one the dialect's literal processor already escaped.
+    """
+
+    def __str__(self) -> str:
+        return ", ".join(str(element) for element in self)
+
+    __repr__ = __str__
+
+
+class SQLSafeDict(dict[Any, Any]):  # noqa: FURB189
+    """
+    A dict of dialect-escaped values whose *whole-container* string
+    rendering cannot re-introduce raw quote characters. Mirrors
+    :class:`SQLSafeList` for the mapping case.
+
+    Keys are rendered as-is: they are used for member lookups (for
+    example ``{{ get_guest_user_attribute('tenant').id }}``), not
+    interpolated into SQL, and are never passed through
+    ``ExtraCache._escape_value``.
+    """
+
+    def __str__(self) -> str:

Review Comment:
   **Suggestion:** Dictionary keys are emitted without dialect escaping, even 
though guest-token attribute keys are externally supplied and the entire 
dictionary is rendered as SQL text by Jinja. A key containing a quote or SQL 
expression can therefore reintroduce an injection delimiter and contradict the 
class's guarantee that whole-container rendering is safe. Either escape keys 
before rendering or prevent whole-dictionary interpolation rather than emitting 
them directly. [security]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Guest-token attributes can alter whole-dictionary SQL interpolation.
   - ⚠️ Affected templates use `get_guest_user_attribute()` object rendering.
   - ❌ Rendered queries may bypass intended tenant filtering.
   ```
   </details>
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/jinja_context.py
   **Line:** 157:157
   **Comment:**
        *Security: Dictionary keys are emitted without dialect escaping, even 
though guest-token attribute keys are externally supplied and the entire 
dictionary is rendered as SQL text by Jinja. A key containing a quote or SQL 
expression can therefore reintroduce an injection delimiter and contradict the 
class's guarantee that whole-container rendering is safe. Either escape keys 
before rendering or prevent whole-dictionary interpolation rather than emitting 
them directly.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43394&comment_hash=30a2763f218e8a86bd44445bb83429c138e087a3aa9334bbd4b153666e56d790&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43394&comment_hash=30a2763f218e8a86bd44445bb83429c138e087a3aa9334bbd4b153666e56d790&reaction=dislike'>👎</a>



-- 
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]

Reply via email to