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

Is this secure to use with user generated templates? #793

Open
turbobuilt opened this issue Aug 8, 2021 · 2 comments
Open

Is this secure to use with user generated templates? #793

turbobuilt opened this issue Aug 8, 2021 · 2 comments

Comments

@turbobuilt
Copy link

Hi, I'm looking at using this library to render user created templates with data I supply. I'm wondering if this library would work or if there are ways that users could insert malicious code and trick mustache.js into executing it.

The only security issue I could find was the fact that templates could be caused to infinitely load one another, but if I only let users control the top-level template, but not sub-templates, I think I would be OK. I did not see a way to execute raw JS, but I would like to hear from an expert with this before committing to use it.

@phillipj
Copy link
Collaborator

phillipj commented Aug 9, 2021

I did not see a way to execute raw JS

I think you've come to the right conclusion.

I can't think of any way to tell mustache to execute JavaScript code specified in the templates themselves. That would also counteract much of what was the holy grail with mustache back in the day: rendering the exact same templates on different runtimes, be it java or C# on the server and javascript in the browser.

One of mustache' mission was to be logic less and opposite of clever. Allowing whatever code to be provided inside the template, doesn't sound like something that would fit that mission either from my point of view.

I could imagine dynamic code to be executed by mustache upon render when using mustache functions, but those would have to be declared on the data side of things, not inside the templates -- and you've said that you're the only one providing the data for rendering.

@Bessonov
Copy link

@turbobuilt how do your solution looks like?

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
@Bessonov @phillipj @turbobuilt and others