code wiki / _hdl_build / nx_studio_guided_gate.nx

nx_studio_guided_gate.nx source

↩ module page · 86 lines · 6922 B

1import "nx_gate_base.nx" 2// nx_studio_guided_gate.nx -- gate for the GUIDED wizard surface (web_assets/_studio/editor_guided.html), the 3// novice/elderly capability tier. Two kinds of proof: 4// STATIC -- the wizard is a THIN SHIM: it has the answer fields, assembles a `tier|guided` payload, POSTs to 5// a path-relative /build, delegates display via srcdoc, and contains NO built-page block markup or 6// engine logic of its own (it builds nothing). 7// BEHAVIOR -- the EXACT payload format the wizard produces, fed to the same governed endpoint the daemon uses 8// (se_build_tier), yields a governed page; is novice-safe (just a brand -> a complete page); and a 9// hostile answer is escaped. 10// Appends a CMSGATE row to knowledge/status/cms_gate.log on all-pass. license_tier: ORIGINAL 11import "nx_studio_tiers.nx" 12import "nx_syscalls.nx" 13 14func gnum(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); 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}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } 15func gcat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var k: i64=0; while s[k]!=(0 as u8){dst[o]=s[k];o=o+1;k=k+1} return o } 16func gcatnum(dst: *u8, off: i64, v: i64) -> i64 { var o: i64=off; let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; 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}; var i: i64=0; while i<k{dst[o]=t[k-1-i];o=o+1;i=i+1} return o } 17func grow(id: i64, ok: i64, what: *u8) -> i64 { gw("GDROW " as *u8); gnum(id); gw(" " as *u8); if ok==1 { gw("PASS " as *u8) } else { gw("FAIL " as *u8) } gw(what); gw("\n" as *u8); return ok } 18func glen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 19func gslurp(path: *u8, buf: *u8, cap: i64) -> i64 { 20 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } 21 var total: i64 = 0; var go: i64 = 1 22 while go == 1 { let r: i64 = sys_read(fd, buf + total, cap - total); if r <= 0 { go = 0 } if r > 0 { total = total + r } if total >= cap { go = 0 } } 23 sys_close(fd); return total 24} 25func gcontains(hay: *u8, hn: i64, needle: *u8) -> i64 { 26 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 27 if nl==0 { return 1 } if nl>hn { return 0 } 28 let last: i64=hn-nl; var i: i64=0 29 while i<=last { var j: i64=0; var hit: i64=1; while j<nl { if (hay[i+j] as i64)!=(needle[j] as i64){hit=0;j=nl} if hit==1{j=j+1} } if hit==1 { return 1 } i=i+1 } 30 return 0 31} 32 33func main() -> i64 { 34 let html: *u8 = sys_mmap(262144) 35 let hn: i64 = gslurp("web_assets/_studio/editor_guided.html" as *u8, html, 262143) 36 let out: *u8 = sys_mmap(262144) 37 38 var rows: i64 = 0 39 var pass: i64 = 0 40 var ok: i64 = 0 41 42 // R0 (static): the wizard has the guided answer fields 43 ok = 0; if hn > 0 { if gcontains(html,hn,"id=\"brand\"" as *u8)==1 { if gcontains(html,hn,"id=\"headline\"" as *u8)==1 { if gcontains(html,hn,"id=\"cta_href\"" as *u8)==1 { if gcontains(html,hn,"id=\"footer\"" as *u8)==1 { ok=1 } } } } } 44 rows=rows+1; pass=pass+grow(0, ok, "wizard has the guided answer fields (brand/headline/cta_href/footer)" as *u8) 45 46 // R1 (static): it assembles a tier|guided payload 47 ok = 0; if gcontains(html,hn,"tier|guided" as *u8)==1 { ok=1 } 48 rows=rows+1; pass=pass+grow(1, ok, "wizard assembles a tier|guided payload" as *u8) 49 50 // R2 (static): it POSTs to a path-relative /build endpoint 51 ok = 0; if gcontains(html,hn,"location.pathname" as *u8)==1 { if gcontains(html,hn,"/build" as *u8)==1 { if gcontains(html,hn,"POST" as *u8)==1 { ok=1 } } } 52 rows=rows+1; pass=pass+grow(2, ok, "wizard POSTs to a path-relative /build (works at / and /webdev)" as *u8) 53 54 // R3 (static): THIN SHIM -- delegates display (srcdoc), builds no page markup itself, no engine logic 55 ok = 0; if gcontains(html,hn,"srcdoc" as *u8)==1 { if gcontains(html,hn,"<section" as *u8)==0 { if gcontains(html,hn,"sg_build" as *u8)==0 { ok=1 } } } 56 rows=rows+1; pass=pass+grow(3, ok, "THIN SHIM: delegates via srcdoc; no page-block markup or engine logic in the wizard" as *u8) 57 58 // R4 (behavior): the wizard's payload format -> the governed endpoint -> a real governed page 59 let l4: i64 = se_build_tier("tier|guided\nbrand|Andelin West\nheadline|Legal help for Utah families\ncta|Free consult\ncta_href|#c\ncard_title|Family Law\ncard_body|We help.\nstep1|Call us\nstep2|We act\ntrust|Utah State Bar\nfooter|Andelin West\n" as *u8, glen("tier|guided\nbrand|Andelin West\nheadline|Legal help for Utah families\ncta|Free consult\ncta_href|#c\ncard_title|Family Law\ncard_body|We help.\nstep1|Call us\nstep2|We act\ntrust|Utah State Bar\nfooter|Andelin West\n" as *u8), out, 262143) 60 ok = 0; if l4 > 0 { if gcontains(out,l4,"Andelin West" as *u8)==1 { if gcontains(out,l4,"Legal help for Utah families" as *u8)==1 { ok=1 } } } 61 rows=rows+1; pass=pass+grow(4, ok, "BEHAVIOR: the wizard's payload -> governed page (Andelin West + headline)" as *u8) 62 63 // R5 (behavior): novice-safe -- the wizard omits empty answers; just a brand -> a complete publishable page 64 let l5: i64 = se_build_tier("tier|guided\nbrand|Solo Shop\n" as *u8, glen("tier|guided\nbrand|Solo Shop\n" as *u8), out, 262143) 65 ok = 0; if l5 > 0 { if gcontains(out,l5,"Solo Shop" as *u8)==1 { ok=1 } } 66 rows=rows+1; pass=pass+grow(5, ok, "BEHAVIOR novice-safe: just a brand answer -> a complete publishable page" as *u8) 67 68 // R6 (behavior): a hostile answer is escaped 69 let l6: i64 = se_build_tier("tier|guided\nbrand|<script>alert(3)</script>\nheadline|H\n" as *u8, glen("tier|guided\nbrand|<script>alert(3)</script>\nheadline|H\n" as *u8), out, 262143) 70 ok = 0; if l6 > 0 { if gcontains(out,l6,"<script>alert(3)" as *u8)==0 { if gcontains(out,l6,"&lt;script&gt;alert(3)" as *u8)==1 { ok=1 } } } 71 rows=rows+1; pass=pass+grow(6, ok, "BEHAVIOR: a hostile answer is escaped (no raw <script>)" as *u8) 72 73 gw("NX-STUDIO-GUIDED-GATE rows=" as *u8); gnum(rows); gw(" pass=" as *u8); gnum(pass); gw("\n" as *u8) 74 if pass == rows { 75 let line: *u8 = sys_mmap(256) 76 var off: i64 = gcat(line, 0, "CMSGATE row=nx_studio_guided guided-wizard-tier rows=" as *u8) 77 off = gcatnum(line, off, rows); off = gcat(line, off, " pass=" as *u8); off = gcatnum(line, off, pass) 78 off = gcat(line, off, " verdict=PASS (guided wizard thin-shim + payload builds governed)\n" as *u8) 79 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4) 80 if gf >= 0 { sys_write(gf, line, off); sys_close(gf) } 81 gw("NX-STUDIO-GUIDED-GATE verdict=PASS -- guided wizard surface (novice/elderly tier) thin-shim + governed\n" as *u8) 82 sys_exit(0); return 0 83 } 84 gw("NX-STUDIO-GUIDED-GATE verdict=FAIL -- NOT recorded (no fake-green)\n" as *u8) 85 sys_exit(1); return 1 86}