



In a template, a block is simply a “block” of Pug that a child template may replace. Template inheritance works via the block and extends keywords. Consider a marketing application that sends bulk emails, and uses a Twig template to greet recipients by name.Pug supports template inheritance. Template Injection occurs when user input is embedded in a template in an unsafe manner. Web applications frequently use template systems such as Twig and FreeMarker to embed dynamic content in web pages and emails. This research is also available as printable whitepaper, and you can find an overview with interactive labs in our Web Security Academy. Generic exploits are demonstrated for five of the most popular template engines, including escapes from sandboxes whose entire purpose is to handle user-supplied templates in a safe way.įor a slightly less dry account of this research, you may prefer to watch my Black Hat USA presentation on this topic. This paper defines a methodology for detecting and exploiting template injection, and shows it being applied to craft RCE zerodays for two widely deployed enterprise web applications. Intentional template injection is such a common use-case that many template engines offer a 'sandboxed' mode for this express purpose. Template Injection can arise both through developer error, and through the intentional exposure of templates in an attempt to offer rich functionality, as commonly done by wikis, blogs, marketing applications and content management systems. Unlike XSS, Template Injection can be used to directly attack web servers' internals and often obtain Remote Code Execution (RCE), turning every vulnerable application into a potential pivot point. Unsafely embedding user input in templates enables Server-Side Template Injection, a frequently critical vulnerability that is extremely easy to mistake for Cross-Site Scripting (XSS), or miss entirely. Template engines are widely used by web applications to present dynamic data via web pages and emails.
