Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Switch from yaml.load to yaml.safe_load for security #22

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 4 commits into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def install_regexes():
import json
import yaml
json_dest = yaml_dest.replace('.yaml', '.json')
regexes = yaml.load(open(yaml_dest))
regexes = yaml.safe_load(open(yaml_dest))
with open(json_dest, "w") as f:
json.dump(regexes, f)

Expand Down
12 changes: 6 additions & 6 deletions ua_parser/user_agent_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _repl(m):
if index < len(group):
return group[index]
return ''

_string = re.sub(r'\$(\d)', _repl, string)
_string = re.sub(r'^\s+|\s+$', '', _string)
if _string == '':
Expand All @@ -179,7 +179,7 @@ def _repl(m):
def Parse(self, user_agent_string):
device, brand, model = None, None, None
match = self.user_agent_re.search(user_agent_string)
if match:
if match:
if self.device_replacement:
device = self.MultiReplace(self.device_replacement, match)
else:
Expand Down Expand Up @@ -442,9 +442,9 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
else:
import yaml

yamlFile = open(UA_PARSER_YAML)
regexes = yaml.load(yamlFile)
yamlFile.close()
with open(UA_PARSER_YAML) as yamlFile:
regexes = yaml.safe_load(yamlFile)


# If UA_PARSER_YAML is not specified, load regexes from regexes.json before
# falling back to yaml format
Expand All @@ -458,7 +458,7 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
import yaml

with open(yamlPath) as fp:
regexes = yaml.load(fp)
regexes = yaml.safe_load(fp)


USER_AGENT_PARSERS = []
Expand Down