liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Does liquid prevent include filenames from traversing directories?

Open gitleet opened this issue 7 years ago • 3 comments

Does liquid somehow prevent users from doing this:

{% include '../../header' %}

Also, is it possible to analyze a template to see how many if statements, loops, tag usages, etc the template contains?

gitleet avatar Jan 16 '19 03:01 gitleet

There is some protection against directory traversal - see the local file system code

noahpryor avatar Jan 23 '19 18:01 noahpryor

Also, is it possible to analyze a template to see how many if statements, loops, tag usages, etc the template contains?

You can traverse the AST starting from Liquid::Template#root, but this API is not guaranteed to remain stable between major Liquid versions. If you are trying to prevent excessive resource use, it's better to set Liquid::Template.default_resource_limits or Liquid::Template#resource_limits. It needs better documentation, but this is essentially how it should be used: https://github.com/Shopify/liquid/blob/2b3c81cfd05ef23869d88cde03faafa1d393ac5b/test/integration/template_test.rb#L104-L140

This is what Shopify does to safely run customer Liquid in production.

pushrax avatar Jan 23 '19 19:01 pushrax

thanks!

gitleet avatar Jan 24 '19 03:01 gitleet