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

Disable partials? #263

Open
seandilda opened this issue Oct 20, 2020 · 11 comments
Open

Disable partials? #263

seandilda opened this issue Oct 20, 2020 · 11 comments

Comments

@seandilda
Copy link

Is there a way to disable partial rendering? If not, can I request it?

I'd like to use mustache to render a template entered by a user. In order to do this safely, I need partials disable to that users can't access any data off of disk.

@yorickpeterse
Copy link
Contributor

yorickpeterse commented Jan 7, 2021

A hack is to extend Mustache and redefine partial like so:

class SafeMustache < Mustache
  def partial(*args)
    ''
  end
end

SafeMustache.render('{{> foo}}') # => ''

@WuMingIT
Copy link

WuMingIT commented Nov 10, 2022

Following up, is this the best way to harden the renderer? I want to allow variables expansion only. Any helpful configuration parameter available?

@bobthecow
Copy link
Member

I remember there was a "safe mustache" a while back, though I've never used it: https://github.com/thelucid/tache

@WuMingIT
Copy link

Thank you for the reference. But has not received commits in seven years. Is so uncommon to look for a stripped down, safe templating system to accept user generated templates?

@bobthecow
Copy link
Member

I mean

image

@WuMingIT
Copy link

Latest official release. Don’t get it, sorry.

@bobthecow
Copy link
Member

The latest release of Tache was December 2015. The latest release of Mustache (this project) was June 2015 🙂

@WuMingIT
Copy link

WuMingIT commented Nov 10, 2022

Ah. Yes. I believe github release feature is not used by many. Official release in this case is a release by tag https://rubygems.org/gems/mustache

@bobthecow
Copy link
Member

Oh gotcha. That's a bit better.

@WuMingIT
Copy link

Could you explain why Spotify Liquid, expanding on Mustache’s footsteps, is self-described as safe to use with user generated templates? If allows any numbers of functions to execute on backend logic. And Mustache itself scares with “If there is no name key, the parent contexts will be checked recursively”. What is safe to use with just variables?

@WuMingIT
Copy link

Solution to this problem are GNU Recutils:

recsel values.rec | recfmt -f complex.html

performs keywords replacement without regard of regex or shell expansion characters (& . - * / \ $ etc.).

The most a user can add are selection expressions within templates. Themselves a powerful option.

Also they are very fast.

Unfortunately no Ruby wrapper gem is available yet. So you will need to call out for shell execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants