code wiki / _hdl_build / nx_web_render_gate.nx

nx_web_render_gate.nx source

↩ module page · 68 lines · 4582 B

1// nx_web_render_gate.nx -- GATE: the WEB loop closed. Teach a temp catalog the web components, compose a PAGE 2// from them, and assert: components render (nav/hero/footer), {KEY} bindings substituted, an injected brand is 3// ESCAPED (no raw <script), NO leftover placeholders, and sovereignty (0 third-party JS). Emits a preview to 4// knowledge/staging/web/page.html. license_tier: ORIGINAL 5import "nx_web_render.nx" 6import "nx_nishi_builder.nx" 7import "nx_ad_serve.nx" 8import "nx_syscalls.nx" 9 10const WG_PATH: *u8 = "/tmp/nishi_web_gate.tsv" 11 12func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 13func g_i(v: i64) -> i64 { let t: *u8 = sys_mmap(24); var m: i64 = v; var k: i64 = 0; if m == 0 { t[0]=48 as u8; k=1 } while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } let o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1; while q>=0 { o[w]=t[q]; w=w+1; q=q-1 } sys_write(1,o,w); return 0 } 14 15func main(argc: i64, argv: *i64) -> i64 { 16 g_p("=== nx_web_render_gate ===\n" as *u8) 17 let fd: i64 = sys_openat_wr(WG_PATH, 420); if fd >= 0 { sys_close(fd) } 18 nb_register(WG_PATH, "web" as *u8, "nav" as *u8, "topbar" as *u8, "Top navbar" as *u8, "<nav class='topbar'><a class='brand' href='/'>{BRAND}</a><div class='links'>{LINKS}</div></nav>" as *u8) 19 nb_register(WG_PATH, "web" as *u8, "section" as *u8, "hero" as *u8, "Hero" as *u8, "<section class='hero'><h1>{TITLE}</h1><p>{SUB}</p><a class='btn' href='{LINK}'>{CTA}</a></section>" as *u8) 20 nb_register(WG_PATH, "web" as *u8, "section" as *u8, "footer" as *u8, "Footer" as *u8, "<footer class='ftr'><p>{COPY}</p><nav>{LINKS}</nav></footer>" as *u8) 21 22 let page: *u8 = sys_mmap(32768) 23 let n: i64 = nw_emit_page(WG_PATH, "Andelin & West" as *u8, "Estate planning, done right" as *u8, 24 "Wills, trusts & probate for Utah families." as *u8, "Book a consult" as *u8, "/contact" as *u8, 25 "(c) Andelin & West" as *u8, page) 26 let wfd: i64 = sys_openat_wr("knowledge/staging/web/page.html" as *u8, 420); if wfd >= 0 { sys_write(wfd, page, n); sys_close(wfd) } 27 g_p("composed a " as *u8); g_i(n); g_p("-byte page from catalog components [nav/hero/footer]\n" as *u8) 28 29 var pass: i64 = 0; var tot: i64 = 0 30 31 // T1 components rendered 32 tot = tot + 1; var ok1: i64 = 1 33 if as_contains(page, n, "class='topbar'" as *u8) != 1 { ok1 = 0 } 34 if as_contains(page, n, "class='hero'" as *u8) != 1 { ok1 = 0 } 35 if as_contains(page, n, "class='ftr'" as *u8) != 1 { ok1 = 0 } 36 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 page composed from nav + hero + footer components\n" as *u8) } else { g_p("FAIL T1\n" as *u8) } 37 38 // T2 bindings substituted 39 tot = tot + 1; var ok2: i64 = 1 40 if as_contains(page, n, "Book a consult" as *u8) != 1 { ok2 = 0 } 41 if as_contains(page, n, "Estate planning, done right" as *u8) != 1 { ok2 = 0 } 42 if as_contains(page, n, "href='/contact'" as *u8) != 1 { ok2 = 0 } 43 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 bindings substituted (CTA/title/link)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) } 44 45 // T3 no leftover placeholders 46 tot = tot + 1; var ok3: i64 = 1 47 if as_contains(page, n, "{TITLE}" as *u8) != 0 { ok3 = 0 } 48 if as_contains(page, n, "{BRAND}" as *u8) != 0 { ok3 = 0 } 49 if as_contains(page, n, "{CTA}" as *u8) != 0 { ok3 = 0 } 50 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 all {KEY} placeholders resolved\n" as *u8) } else { g_p("FAIL T3\n" as *u8) } 51 52 // T4 escaping: brand '&' -> '&amp;', AND an injected <script> brand stays escaped 53 let page2: *u8 = sys_mmap(32768) 54 let n2: i64 = nw_emit_page(WG_PATH, "<script>alert(1)</script>" as *u8, "Hi" as *u8, "x" as *u8, "Go" as *u8, "/x" as *u8, "c" as *u8, page2) 55 tot = tot + 1; var ok4: i64 = 1 56 if as_contains(page, n, "Andelin &amp; West" as *u8) != 1 { ok4 = 0 } // '&' escaped 57 if as_contains(page2, n2, "<script>alert" as *u8) != 0 { ok4 = 0 } // injected brand neutralised 58 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 boundary-escaped: '&' -> &amp;, injected <script> neutralised\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } 59 60 // T5 sovereignty 61 tot = tot + 1 62 if as_has_thirdparty_js(page, n) == 0 { pass = pass + 1; g_p("PASS T5 sovereignty: 0 third-party JS in the rendered page\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } 63 64 g_p("nx_web_render_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 65 if pass == tot { g_p(" verdict=GREEN (web domain loop CLOSED: catalog -> live page)\n" as *u8); return 0 } 66 g_p(" verdict=RED\n" as *u8) 67 return 1 68}