-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Document Remote Code Execution risk for Dataframe.query and computation.eval #58697
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
DOC: Document Remote Code Execution risk for Dataframe.query and computation.eval #58697
Conversation
This reverts commit 79c603e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm @jorisvandenbossche
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
pandas/core/frame.py
Outdated
This function pass the `expr` parameter to :meth:`~pandas.DataFrame.eval`. | ||
This allows `eval` to run arbitrary code, which can make you vulnerable to code | ||
injection if you pass user input to this function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function pass the `expr` parameter to :meth:`~pandas.DataFrame.eval`. | |
This allows `eval` to run arbitrary code, which can make you vulnerable to code | |
injection if you pass user input to this function. | |
This method can run arbitrary code, which can make you vulnerable to code | |
injection if you pass user input to this function. |
I don't think we need to mention the implementation details; it's sufficient to warn that query can run arbitrary code.
pandas/core/computation/eval.py
Outdated
This allows `eval` to run arbitrary code, which can make you vulnerable to code | ||
injection if you pass user input to this function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an internal method, right? In such case, I don't think this is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah - this is exposed at the top level. Agree with including it, but I don't think starting with This
is accurate - it
reads to me like that refers to the previous sentence. Can just say
eval
can run arbitrary code, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thanks @r0rshark! |
TLDR
This diff adds documentation to the Remote Code Execution risk for
Dataframe.query
andcomputation.eval
with the same wording used in Dataframe.evalDetails
The Dataframe.query function is internally calling Dataframe.eval here passing the
expr
parameter.Dataframe.eval is correctly warning in the documentation that this could lead to Code execution risk.
This is possible because using the
@
syntax we can access local variables and by referencing the imported pandas library we can get theos.system
function thanks toos
being imported inside compat/init.py. In this way passing something like@pd.compat.os.system('whoami')
to theexpr
parameter ofDataframe.query
we can achieve code execution.However in Dataframe.query documentation we do not surface this risk we only point out that pandas.eval is called but also there we do not warn about any code execution risks.
The vulnerable code I found and that also surprised the developer who wrote it of the code execution risk can be summarized in UserControlled input flowing into the DataFrame.query expr value similarly to
Calling this api with data:
https://[email protected]('whoami')
will allow code execution.