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

Python: XML RPC Dotted Names #3910

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dilanbhalla
Copy link
Contributor

This query warns against enabling the allow_dotted_names option when registering an instance of SimpleXMLRPCServer, as this allows intruders to access your module’s global variables and may execute arbitrary code on your machine. This should only be used within a secure, closed network.

@dilanbhalla dilanbhalla requested a review from a team as a code owner July 6, 2020 21:16
@adityasharad adityasharad changed the base branch from master to main August 14, 2020 18:33
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

This seems to not have been touched in a long time. By the referenced documentation, this might still be relevant, though. I guess this query is mostly to guard against user who did not read the very explicit warning in the documentation, but I can see how that can easily happen when copying examples or working with existing code, so this is probably a fine query at least for experimental. If we want it, it should be updated to modern standards; I made a suggestion to that effect.

Comment on lines +11 to +24
import python

from CallNode call, ControlFlowNode allow_dotted_names, Attribute a
where
a.getLocation().getStartLine() = call.getLocation().getStartLine() and
a.getName() = "register_instance" and
not call.getLocation().getFile().inStdlib() and
(
allow_dotted_names = call.getArgByName("allow_dotted_names") or
allow_dotted_names = call.getArg(1)
) and
allow_dotted_names.getNode().toString() = "True"
select a,
"Enabling the allow_dotted_names option allows intruders to access your module’s global variables and may allow intruders to execute arbitrary code on your machine."
Copy link
Contributor

Choose a reason for hiding this comment

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

A modern way to write this would be

Suggested change
import python
from CallNode call, ControlFlowNode allow_dotted_names, Attribute a
where
a.getLocation().getStartLine() = call.getLocation().getStartLine() and
a.getName() = "register_instance" and
not call.getLocation().getFile().inStdlib() and
(
allow_dotted_names = call.getArgByName("allow_dotted_names") or
allow_dotted_names = call.getArg(1)
) and
allow_dotted_names.getNode().toString() = "True"
select a,
"Enabling the allow_dotted_names option allows intruders to access your module’s global variables and may allow intruders to execute arbitrary code on your machine."
import python
import semmle.python.ApiGraphs
from API::CallNode call, DataFlow::Node allow_dotted_names
where
call =
API::moduleImport("xmlrpc")
.getMember("server")
.getMember("SimpleXMLRPCServer")
.getReturn()
.getMember("register_instance")
.getACall() and
allow_dotted_names = call.getParameter(1, "allow_dotted_names").getAValueReachingSink() and
allow_dotted_names.asExpr() instanceof True
select allow_dotted_names,
"Enabling the allow_dotted_names option allows intruders to access your module’s global variables and may allow intruders to execute arbitrary code on your machine."

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

Successfully merging this pull request may close these issues.

2 participants