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

Added whitelist for functions available inside of eval() #584

Merged
merged 1 commit into from Mar 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion user_sync/connector/directory_okta.py
Expand Up @@ -309,8 +309,15 @@ def iter_search_result(self, filter_string, attributes):
return users

def filter_users(self, users, filter_string):
# Allow the following builtin functions to be used in eval()
whitelist = {
"len": len, "int": int, "float": float, "str": str, "enumerate": enumerate, "filter": filter,
"getattr": getattr, "hasattr": hasattr, "list": list, "map": map, "max": max, "min": min,
"range": range, "sorted": sorted, "sum": sum, "tuple": tuple, "zip": zip
}

try:
return list(filter(lambda user: eval(filter_string), users))
return list(filter(lambda user: eval(filter_string, {"__builtins__": whitelist}, {"user": user}), users))
except SyntaxError as e:
raise AssertionException("Invalid syntax in predicate (%s): cannot evaluate" % filter_string)
except Exception as e:
Expand Down