code wiki / (root) / nx_http_template.nx

nx_http_template.nx

buildroot/runtime/nx_http_template.nx

10688 B292 linesdepth 3pulls 4 transitivereach 3 importersview sourcekind librarytopic http
docsdependenciesstructsconstsfunctions

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

nx_syscalls_x86_64.nx nx_html_render.nx nx_http_template.nx nx_build_doc.nx nx_build_site.nx nx_http_template_test.nx

imports: nx_syscalls_x86_64.nxnx_html_render.nx

imported by: nx_build_doc.nxnx_build_site.nxnx_http_template_test.nx

structs

74struct NxTemplateVars

consts

44const NXT_OK: i64 = 0
45const NXT_OOM_BUFFER: i64 = 1
46const NXT_BAD_TEMPLATE: i64 = 2 // missing }} or other syntax error
47const NXT_BAD_MODIFIER: i64 = 3 // unknown | modifier
48const NXT_VAR_NOT_FOUND: i64 = 4 // template references unknown var
49const NXT_BAD_ARG: i64 = 5
50const NXT_VERDICT_N: i64 = 6
84const NX_TEMPLATE_VARS_BYTES: i64 = 56

functions

52func nxt_verdict_is_valid(v: i64) -> i64
called by 1: main
58func nxt_verdict_name(v: i64) -> *u8
called by 1: main
86func nx_template_vars_init(
107func nxt_find_var(vars: *NxTemplateVars,
135func nxt_is_space(b: i64) -> i64
called by 1: nxt_skip_ws
141func nxt_is_ident_char(b: i64) -> i64
called by 1: nxt_scan_ident
150func nxt_skip_ws(tmpl: *u8, end: i64, start: i64) -> i64
160func nxt_scan_ident(tmpl: *u8, end: i64, start: i64) -> i64
169func nxt_bytes_eq(a: *u8, b: *u8, n: i64) -> i64
called by 1: nxt_modifier_to_ctx
182func nxt_modifier_to_ctx(mod: *u8, mod_n: i64) -> i64
205func nx_http_template_render(