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

Clarification Request: Why are template layout no longer being cloned? #216

Open
preslavrachev opened this issue Jan 17, 2023 · 1 comment

Comments

@preslavrachev
Copy link

Hi,

I was trying to adapt the template loading and embedding logic for my Echo-based project when I noticed this part here:

lay := e.Templates.Lookup(layout[0])

I expected to see lay.Clone() being called here, because the current solution attaches the embed func globally. This could be a potential security threat, if someone ends up rendering main.html by mistake.

Checking the history, I saw that there was a version that cloned the template, but it was replaced, because a cloned template cannot be executed multiple times. But if you are always only executing the copy, why would the original template get executed in the first place?

I would love to hear your thoughts.

@preslavrachev
Copy link
Author

The real reason of what was causing gofiber/fiber#818 is that Engine uses a *template.Template instance to store and lookup all templates. If you replace that single instance with a map[string]*template.Template and use the map for lookup, you won't have this issue anymore, and you should be able to bring template cloning back.

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

1 participant