Skip to content

A feeble attempt to plug a theoretical security hole #6274

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

Merged
merged 1 commit into from
Apr 17, 2016

Conversation

WeatherGod
Copy link
Member

I introduced a security hole when I implemented the property cycle support last year. I should have read this blog posting: http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html that would have scared me off of the current implementation.

What this PR does is tries to plug two possible holes. First, it neuters __builtins__, which is a good step, but as Ned points out in his post, it is insufficient. Second, I reject any cycler strings that have the substring of '.__' in it, as it could be a dunder method access, which is key to the other holes that Ned demonstrates. I don't like that because I can see possible valid uses of that combo of three characters in a property cycler.

@tacaswell and I have discussed some future directions to fix this permanently that should go into v2.0. Essentially, use PyParsing and ast.literal_eval() instead of the unsafe eval(). That would take some time, and given that v2.0 is still in the works, I would suggest releasing v1.5.2 as a security fix release.

# We should replace this eval with a combo of PyParsing and
# ast.literal_eval()
if '.__' in s.replace(' ', ''):
raise ValueError("'%s' seems to have dunder methods. Raising"
Copy link
Member

Choose a reason for hiding this comment

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

This should be put outside the try or it will be caught and re-raised with a different message below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought about that, but I would rather keep all of this logic and comments together in one place. The re-raise includes this exception message, so it isn't like it is getting lost in the shuffle. All of this should be getting replaced anyway come v2.0.

@tacaswell tacaswell added this to the 1.5.2 (Critical bug fix release) milestone Apr 6, 2016
@WeatherGod
Copy link
Member Author

Travis failure doesn't have anything to do with what I am doing here, but doesn't seem transient. I restarted it just in case anyway.

@mdboom
Copy link
Member

mdboom commented Apr 7, 2016

With the exception of the "cycler(" part at the beginning, I think most of these expressions are actually just JSON, aren't they? Maybe we could detect/strip the prefix and then use JSON to parse the rest, which would be much safer.

@WeatherGod
Copy link
Member Author

We allow binary operations, too, in order to gain the full features of
cycler objects.

On Thu, Apr 7, 2016 at 2:16 PM, Michael Droettboom <notifications@github.com

wrote:

With the exception of the "cycler(" part at the beginning, I think most of
these expressions are actually just JSON, aren't they? Maybe we could
detect/strip the prefix and then use JSON to parse the rest, which would be
much safer.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#6274 (comment)

@mdboom
Copy link
Member

mdboom commented Apr 7, 2016

But are those binary operations used in matplotlibrc files?

@WeatherGod
Copy link
Member Author

Not in the ones we package, but anyone else can do that, and we do
advertise that it is possible in the documentation. That's why a PyParsing
approach is appealing, especially since it is already a dependency.

On Thu, Apr 7, 2016 at 2:46 PM, Michael Droettboom <notifications@github.com

wrote:

But are those binary operations used in matplotlibrc files?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#6274 (comment)

@tacaswell
Copy link
Member

I have a super rough pass at this on a computer someplace, but it is at least a few days of work (well, for me, might only take @mdboom an hour 😉 ). In the pyparsing docs there is a 4 function calculator I was using as a template.

@mdboom
Copy link
Member

mdboom commented Apr 8, 2016

Nothing takes an hour with PyParsing ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants