Skip to content

Commit

Permalink
Limit the strings which can be eval'd (#165)
Browse files Browse the repository at this point in the history
When processing the schema, each line is run through Python's eval
function to make the validator available. A well constructed string
within the schema rules can execute system commands. This change limits
the string to those that begin with the known validators.
  • Loading branch information
Chris Mildebrandt authored Aug 3, 2021
1 parent 7886642 commit 6017300
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions yamale/syntax/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

def parse(validator_string, validators=None):
validators = validators or val.DefaultValidators

if validator_string:
for validator in validators.keys():
if validator_string.startswith(validator):
break
else:
raise SyntaxError(
'Invalid schema expression: \'%s\'. ' % validator_string
)

try:
tree = ast.parse(validator_string, mode='eval')
# evaluate with access to a limited global scope only
Expand Down

0 comments on commit 6017300

Please sign in to comment.