Skip to content
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

Merged
merged 8 commits into from
May 22, 2024
2 changes: 2 additions & 0 deletions pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def eval(
corresponding bitwise operators. :class:`~pandas.Series` and
:class:`~pandas.DataFrame` objects are supported and behave as they would
with plain ol' Python evaluation.
This allows `eval` to run arbitrary code, which can make you vulnerable to code
injection if you pass user input to this function.
Copy link
Member

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.

Copy link
Member

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, ...


Parameters
----------
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4473,6 +4473,10 @@ def query(self, expr: str, *, inplace: bool = False, **kwargs) -> DataFrame | No
"""
Query the columns of a DataFrame with a boolean expression.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.


Parameters
----------
expr : str
Expand Down
Loading