code wiki / _hdl_build / nx_brand_assets_gate.nx

nx_brand_assets_gate.nx source

↩ module page · 61 lines · 3018 B

1// nx_brand_assets_gate.nx -- brand asset slots (favicon/logo/og) emit into <head>, escaped, additive (default brand 2// unaffected). 100% sovereign. expect_exit: 0 3import "nx_syscalls.nx" 4import "nx_sitegate_emit_lib.nx" 5import "nx_web_builder.nx" 6import "nx_brand_tokens.nx" 7 8 9func g_has(s: *u8, n: i64, lit: *u8) -> i64 { if bt_find(s, n, lit, bt_len(lit)) >= 0 { return 1 } return 0 } 10func g_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 11// build a brand to /tmp and read it back 12func g_build(brand: *u8, out: *u8, cap: i64) -> i64 { 13 let fd: i64 = sys_openat_wr("/tmp/nx_assets.html" as *u8, 0x1a4) 14 wb_doc_open_branded(fd, "Assets" as *u8, brand, g_len(brand)) 15 wb_w(fd, "<p>x</p>\n" as *u8) 16 wb_doc_close(fd) 17 sys_close(fd) 18 let lp: *i64 = sys_mmap(16) as *i64 19 let pg: *u8 = sys_read_file("/tmp/nx_assets.html" as *u8, lp) 20 let pn: i64 = lp[0] 21 var i: i64 = 0 22 while i < pn { if i < cap { out[i] = pg[i] } i = i + 1 } 23 return pn 24} 25 26func main() -> i64 { 27 let tot: *i64 = sys_mmap(32) as *i64 28 tot[0]=0; tot[1]=0 29 let cap: i64 = 16384 30 let a: *u8 = sys_mmap(cap) 31 gw("=== nx_brand_assets_gate -- brand asset slots (favicon/logo/og) into <head> ===\n" as *u8) 32 33 let ab: *u8 = "token|color|primary|#0b2545\ntoken|color|bg|#ffffff\ntoken|color|ink|#16202e\nasset|favicon|/favicon.ico\nasset|logo|/logo.svg\nasset|og-image|/og.png\nasset|og-title|My Brand\n" as *u8 34 let an: i64 = g_build(ab, a, cap) 35 var t1: i64 = 0 36 if g_has(a, an, "<link rel=\"icon\" href=\"/favicon.ico\"" as *u8) == 1 { if g_has(a, an, "<meta property=\"og:image\" content=\"/og.png\"" as *u8) == 1 { t1 = 1 } } 37 t_row("AS1 asset brand -> favicon + og:image tags in <head>" as *u8, t1, tot) 38 39 var t2: i64 = 0 40 if g_has(a, an, "apple-touch-icon" as *u8) == 1 { t2 = 1 } 41 t_row("AS2 logo slot -> apple-touch-icon link" as *u8, t2, tot) 42 43 // default brand (no asset tokens) -> no asset tags (backward-compatible) 44 let dn: i64 = g_build(bt_default_brand(), a, cap) 45 var t3: i64 = 0 46 if g_has(a, dn, "rel=\"icon\"" as *u8) == 0 { t3 = 1 } 47 t_row("AS3 default brand (no assets) emits no asset tags (backward-compatible)" as *u8, t3, tot) 48 49 // sovereignty: a hostile asset value is attribute-escaped (no breakout) 50 let hb: *u8 = "token|color|bg|#ffffff\nasset|og-title|Hi\" onload=evil\n" as *u8 51 let hn: i64 = g_build(hb, a, cap) 52 var t4: i64 = 0 53 // the value's own quote is escaped -> the escaped form appears verbatim (no early attribute close -> no breakout) 54 if g_has(a, hn, "Hi&quot; onload=evil" as *u8) == 1 { t4 = 1 } 55 t_row("AS4 sovereignty: hostile asset value attribute-escaped (no breakout)" as *u8, t4, tot) 56 57 gw("\nrows pass=" as *u8); gn(tot[0]); gw(" fail=" as *u8); gn(tot[1]); gw("\n" as *u8) 58 if tot[1] == 0 { gw("VERDICT=GREEN -- brand asset slots (favicon/logo/og) work, escaped, additive (full DAM = separate arc)\n" as *u8); return 0 } 59 gw("VERDICT=RED\n" as *u8) 60 return 1 61}