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,ListandMathhelpers - beans you mark
@TemplateAccessible request,principalanderrors
Blocked, whatever the template says
T(...)andnewclassandgetClass()- 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 model
Ada <script>alert(1)</script>Sent to the browser
Ada <script>alert(1)</script>The visitor sees textAda <script>alert(1)</script>
Security model¶
{{ }}and@langHTML-escape; only{!! !!}, component slots and$attributesemit 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 onClass/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 acceptsjavascript:...if the URL comes from a user, so validate URLs (allowhttp/httpsonly). Always quote attributes (title="{{ $x }}", nevertitle={{ $x }}). For data in scripts use@json, never{{ }}.@stylewith user input can inject CSS.
Operations¶
- Parsed templates are immutable and cached per
LoomaEngine(thread-safe); keeplooma.cache=truein 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/@whilestop 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.