Skip to content

Security & operations

At a glance

A template can use

  • model attributes, records, getters and maps
  • methods on values, such as $name.toUpperCase()
  • the String, Number, Date, List and Math helpers
  • beans you mark @TemplateAccessible
  • request, principal and errors

Blocked, whatever the template says

  • T(...) and new
  • class and getClass()
  • reflection: Class, Method, ClassLoader
  • Runtime, Process, Thread
  • beans you did not opt in
  • assigning variables

Escaping, step by step. What happens to a value that contains markup when a template prints it with {{ }}:

In the modelAda <script>alert(1)</script>
Sent to the browserAda &lt;script&gt;alert(1)&lt;/script&gt;
The visitor sees textAda <script>alert(1)</script>

Security model

  • {{ }} and @lang HTML-escape; only {!! !!}, component slots and $attributes emit markup as-is. Never put untrusted input in {!! !!}.
  • Templates are trusted code written by developers, not by end users. The expression sandbox is defense in depth (no T(), new, bean references, class/getClass(), or calls on Class/ClassLoader/Method/Runtime/Process); it is not meant for running user-submitted templates.
  • Do not build @include / @extends / <x-...> names from request input.
  • Template names are validated ([A-Za-z0-9_-./], no ..), so view names cannot escape the template folder.
  • Rendering is buffered, so an error produces a normal error response instead of half a page.
  • Escaping is for HTML text and quoted attributes. It does not make a value safe as a URL or as JavaScript: <a href="{{ $url }}"> still accepts javascript:... if the URL comes from a user, so validate URLs (allow http/https only). Always quote attributes (title="{{ $x }}", never title={{ $x }}). For data in scripts use @json, never {{ }}. @style with user input can inject CSS.

Operations

  • Parsed templates are immutable and cached per LoomaEngine (thread-safe); keep looma.cache=true in production.
  • Errors are LoomaExceptions naming the template and line, e.g. In template 'home' at line 12: ....
  • @include/@extends/components may nest 100 deep before failing, which stops accidental recursion, and blocks may be nested 200 deep in one template (deeper fails with the line instead of overflowing the stack).
  • @for/@while stop with an error after 100,000 passes, so a condition that never turns false cannot hang a request.
  • looma.* properties have IDE auto-completion through the generated configuration metadata.