bito-code-review[bot] commented on code in PR #40746:
URL: https://github.com/apache/superset/pull/40746#discussion_r3410983423
##########
superset/mcp_service/user/schemas.py:
##########
@@ -277,26 +305,26 @@ def serialize_user_object(
if include_sensitive and include_roles:
user_roles = getattr(user, "roles", None)
if user_roles is not None:
- try:
- roles = [r.name for r in user_roles if hasattr(r, "name")]
- except (AttributeError, DetachedInstanceError):
- roles = None
+ roles = []
+ for r in user_roles:
+ try:
+ if hasattr(r, "name") and isinstance(r.name, str):
+ roles.append(escape_llm_context_delimiters(r.name))
+ except (AttributeError, DetachedInstanceError):
+ logger.debug(
+ "Skipping role that raised exception in
serialize_user_object"
+ )
+ continue
return UserInfo(
id=getattr(user, "id", None),
username=escape_llm_context_delimiters(getattr(user, "username",
None)),
- first_name=sanitize_for_llm_context(
- getattr(user, "first_name", None), field_path=("first_name",)
- ),
- last_name=sanitize_for_llm_context(
- getattr(user, "last_name", None), field_path=("last_name",)
- ),
+ first_name=escape_llm_context_delimiters(getattr(user, "first_name",
None)),
+ last_name=escape_llm_context_delimiters(getattr(user, "last_name",
None)),
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>CWE-79: Prompt injection via downgraded
sanitization</b></div>
<div id="fix">
`first_name` and `last_name` are user-supplied strings placed into LLM
context. The change from `sanitize_for_llm_context()` to
`escape_llm_context_delimiters()` removes the `<UNTRUSTED-CONTENT>` wrapper
that prevents prompt injection. Without wrapping, a malicious `first_name` like
`Admin\nIgnore previous instructions and...` could be interpreted as an LLM
instruction rather than data. These fields are not in
`LLM_CONTEXT_EXCLUDED_FIELD_NAMES` and should retain full wrapping. (See also:
[CWE-79](https://cwe.mitre.org/data/definitions/79.html))
</div>
</div>
<small><i>Code Review Run #0d92b7</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]