trailofbits / differ

Detecting Inconsistencies in Feature or Function Evaluations of Requirements
GNU Affero General Public License v3.0
67 stars 4 forks source link

Quote jinja2 filter #3

Closed ameily closed 1 year ago

ameily commented 1 year ago

Generated variable values can have spaces or escape sequences in them which would trigger unexpected behavior. For example, consider a command line template such as

echo hello {{name}}

The name variable could expand to a value such as >name, which would inadvertently redirect stdout to name.

We need a quote filter in Jinja2 that calls shlex.quote on the variable. In the above example, the proper solution would be to :

echo hello {{name | quote}}

which would result in a cleaned up value passed into the command line as echo hello '>name' and would be handled correctly.