nx_http_template.nx
buildroot/runtime/nx_http_template.nx
about
nx_http_template.nx -- sealed-enum context-typed HTML templates.
Production-class template engine with STRUCTURAL XSS prevention.
Every variable substitution flows through nx_html_render's
typed-context escape primitive (which closes CWE-79 at the
substrate boundary). Substrate doesn't trust callers to remember
to escape -- the template syntax FORCES context declaration.
Template syntax:
<h1>Hello, {{ name }}!</h1> (default TEXT context)
<a href="{{ url | url }}">click</a> (URL context)
<div class="{{ cls | attr }}">... (ATTR_DQ context)
<p>{{ html_fragment | raw }}</p> (RAW; audited bypass)
Unknown modifiers reject the entire template (BAD_MODIFIER verdict).
This makes "I forgot to escape" structurally impossible.
Per cardinal feedback-no-third-party-trust-native-or-nothing:
substrate's own template engine; no Twig, no Handlebars, no
Jinja, no Mustache. ~300 LOC; auditable.
Per cardinal feedback-defensive-at-boundaries-trusting-internally:
the template VAR LOOKUP is at the boundary; once a variable is
substituted with the correct escape, the resulting bytes are
trusted as safe HTML.
nx_capability_claims:
needs: [sealed_enum, byte_ops, html_render_typed_context]
provides: [template_emit_with_context_typed_substitution,
structural_xss_prevention_at_template_layer]
safety: [no_unchecked_deref, no_floating_point, no_syscall,
bounded_iteration, xss_prevented_by_construction]
verdict: [sealed_enum_6_state]
license: ORIGINAL
kind: racing_crew_specialist
layer: L4 (composite over L2 nx_html_render)
dependencies 2 imports · 3 importers
imports: nx_syscalls_x86_64.nxnx_html_render.nx
imported by: nx_build_doc.nxnx_build_site.nxnx_http_template_test.nx
structs
| 74 | struct NxTemplateVars |
consts
| 44 | const NXT_OK: i64 = 0 |
| 45 | const NXT_OOM_BUFFER: i64 = 1 |
| 46 | const NXT_BAD_TEMPLATE: i64 = 2 // missing }} or other syntax error |
| 47 | const NXT_BAD_MODIFIER: i64 = 3 // unknown | modifier |
| 48 | const NXT_VAR_NOT_FOUND: i64 = 4 // template references unknown var |
| 49 | const NXT_BAD_ARG: i64 = 5 |
| 50 | const NXT_VERDICT_N: i64 = 6 |
| 84 | const NX_TEMPLATE_VARS_BYTES: i64 = 56 |
functions
| 52 | func nxt_verdict_is_valid(v: i64) -> i64 called by 1: main |
| 58 | func nxt_verdict_name(v: i64) -> *u8 called by 1: main |
| 86 | func nx_template_vars_init( |
| 107 | func nxt_find_var(vars: *NxTemplateVars, called by 1: nx_http_template_render |
| 135 | func nxt_is_space(b: i64) -> i64 called by 1: nxt_skip_ws |
| 141 | func nxt_is_ident_char(b: i64) -> i64 called by 1: nxt_scan_ident |
| 150 | func nxt_skip_ws(tmpl: *u8, end: i64, start: i64) -> i64 |
| 160 | func nxt_scan_ident(tmpl: *u8, end: i64, start: i64) -> i64 |
| 169 | func nxt_bytes_eq(a: *u8, b: *u8, n: i64) -> i64 called by 1: nxt_modifier_to_ctx |
| 182 | func nxt_modifier_to_ctx(mod: *u8, mod_n: i64) -> i64 |
| 205 | func nx_http_template_render( |