http://dwoo.org/what-dwoo.html
from jinja2 import Environment, FileSystemLoader
import os
# current directory
my_dir = os.path.dirname(os.path.abspath(__file__))
def render_html_page():
# jinja2 environment
env = Environment(loader=FileSystemLoader(my_dir),\
trim_blocks=True)
print env.get_template('template.html').render\
(title='Hello gdieu from Confoo Montreal')
if __name__ == '__main__':
render_html_page()<html>
<head>
<title>Template Example</title>
</head>
<body>
{{ title }}
</body>
</html>
http://blog.portswigger.net/2015/08/server-side-template-injection.html
http://www.tornadoweb.org/en/stable/template.html?highlight=templating#syntax-reference
MY_TEMPLATE = '''
<html>
<head><title> Hello World! </title></head>
<body> Hello yourName </body>
</html>
'''
class myMainHandler(tornado.web.RequestHandler):
def get(self):
name = self.get_argument('name', '')
vuln_template = MY_TEMPLATE.replace("yourName",name)
t = tornado.template.Template(vuln_template)
self.write(t.generate(name=name))
class my404Handler(tornado.web.RequestHandler):
def prepare(self):
self.set_status(404)
self.render("404.html")
application = tornado.web.Application([
(r"/", myMainHandler),], default_handler_class=my404Handler,
debug=False, static_path=None, template_path=None)
if __name__ == '__main__':
application.listen(8000, address='0.0.0.0')
tornado.ioloop.IOLoop.instance().start()
850 public function getFilter($name)
{
...
...
foreach ($this->filterCallbacks as $callback) {
if (false !== $filter = call_user_func($callback, $name)) {
return $filter;
}
}
return false;
}
public function registerUndefinedFilterCallback($callable)
{
$this->filterCallbacks[] = $callable;
}https://github.com/twigphp/Twig/blob/e22fb8728b395b306a06785a3ae9b12f3fbc0294/lib/Twig/Environment.php
http://php.net/manual/en/function.call-user-func.php
<?php
if (isset($_GET['submit'])) {
$name=$_GET['name'];
...
...
Twig_Autoloader::register();
try {
$loader = new Twig_Loader_String();
$twig = new Twig_Environment($loader);
// render template
$result= $twig->render($name);
echo "Hello $result";
}
catch (Exception $e) {
die ('ERROR: ' . $e->getMessage());}
}
?>
https://freemarker.apache.org/docs/ref_builtins_expert.html#ref_builtin_new
private static final String s = "<#escape x as x?html>Hello %s</#escape>";
private Configuration templateEngine = null;
@PostConstruct
public void init() {
this.templateEngine = new Configuration(new Version("2.3.23"));
this.templateEngine.setDefaultEncoding("UTF-8");
this.templateEngine.setLocale(Locale.US);
...
...
}
@PostMapping("/display")
public void display(@RequestParam final String name,
final HttpServletResponse response) throws Exception {
final String input = String.format(s, ((name == null) ? "" : name));
Template t = new Template(UUID.randomUUID().toString(),
new StringReader(input), this.templateEngine);
try (Writer result = new OutputStreamWriter(response.getOutputStream())) {
t.process(null, result);
}
}