code wiki / _hdl_build / nx_brand_assets_gate.nx
nx_brand_assets_gate.nx source
↩ module page · 68 lines · 3436 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"
7import "nx_gate_verdict.nx"
8
9
10func g_has(s: *u8, n: i64, lit: *u8) -> i64 { if bt_find(s, n, lit, bt_len(lit)) >= 0 { return 1 } return 0 }
11func g_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
12// build a brand to /tmp and read it back
13func g_build(brand: *u8, out: *u8, cap: i64) -> i64 {
14 let fd: i64 = sys_openat_wr("/tmp/nx_assets.html" as *u8, 0x1a4)
15 wb_doc_open_branded(fd, "Assets" as *u8, brand, g_len(brand))
16 wb_w(fd, "<p>x</p>\n" as *u8)
17 wb_doc_close(fd)
18 sys_close(fd)
19 let lp: *i64 = sys_mmap(16) as *i64
20 let pg: *u8 = sys_read_file("/tmp/nx_assets.html" as *u8, lp)
21 let pn: i64 = lp[0]
22 var i: i64 = 0
23 while i < pn { if i < cap { out[i] = pg[i] } i = i + 1 }
24 return pn
25}
26
27func main() -> i64 {
28 let tot: *i64 = sys_mmap(32) as *i64
29 tot[0]=0; tot[1]=0
30 let cap: i64 = 16384
31 let a: *u8 = sys_mmap(cap)
32 gw("=== nx_brand_assets_gate -- brand asset slots (favicon/logo/og) into <head> ===\n" as *u8)
33
34 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
35 let an: i64 = g_build(ab, a, cap)
36 var t1: i64 = 0
37 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 } }
38 t_row("AS1 asset brand -> favicon + og:image tags in <head>" as *u8, t1, tot)
39
40 var t2: i64 = 0
41 if g_has(a, an, "apple-touch-icon" as *u8) == 1 { t2 = 1 }
42 t_row("AS2 logo slot -> apple-touch-icon link" as *u8, t2, tot)
43
44 // default brand (no asset tokens) -> no asset tags (backward-compatible)
45 let dn: i64 = g_build(bt_default_brand(), a, cap)
46 var t3: i64 = 0
47 if g_has(a, dn, "rel=\"icon\"" as *u8) == 0 { t3 = 1 }
48 t_row("AS3 default brand (no assets) emits no asset tags (backward-compatible)" as *u8, t3, tot)
49
50 // sovereignty: a hostile asset value is attribute-escaped (no breakout)
51 let hb: *u8 = "token|color|bg|#ffffff\nasset|og-title|Hi\" onload=evil\n" as *u8
52 let hn: i64 = g_build(hb, a, cap)
53 var t4: i64 = 0
54 // the value's own quote is escaped -> the escaped form appears verbatim (no early attribute close -> no breakout)
55 if g_has(a, hn, "Hi" onload=evil" as *u8) == 1 { t4 = 1 }
56 t_row("AS4 sovereignty: hostile asset value attribute-escaped (no breakout)" as *u8, t4, tot)
57
58 gw("\nrows pass=" as *u8); gn(tot[0]); gw(" fail=" as *u8); gn(tot[1]); gw("\n" as *u8)
59 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
60 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
61 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
62 let ctr__dry: *i64 = gv_ctr()
63 ctr__dry[0] = tot[0]
64 ctr__dry[1] = tot[0] + tot[1]
65 let rc__dry: i64 = gv_verdict("BRAND-ASSETS-GATE" as *u8, ctr__dry, "brand asset slots (favicon/logo/og) work, escaped, additive (full DAM = separate arc)" as *u8)
66 sys_exit(rc__dry)
67 return rc__dry
68}