code wiki / _hdl_build / nx_video_embed_gate.nx

nx_video_embed_gate.nx source

↩ module page · 106 lines · 7430 B

1// nx_video_embed_gate.nx -- STRUCTURAL + SECURITY + SOVEREIGNTY gate for the <nishi-video> embed (nx_video_embed). 2// Greps the THREE real emitted artifacts (web_assets/video_embed.html, embed.js, video_embed_demo.html) and 3// proves, by construction: 4// [need] every safety/sovereignty/ergonomics property is present (origin-checked postMessage, least-privilege 5// allow=, sandbox isolation, proven relay routes, CSP, typed CustomEvents, mode handling, the snippet) 6// [deny] none of the "bullshit" is present (NO third-party/CDN, NO trackers, NO cookies, NO eval, NO http://) 7// Liar-kill: a missing file OR a missing required marker OR a present forbidden marker -> RED (exit 1). This is 8// the same cite-or-refuse discipline as nx_embed_exceed -- the gate cannot go GREEN on an absent artifact. 9// license_tier: ORIGINAL 10import "nx_syscalls.nx" 11 12func vg_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13func vg_pn(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 } 14func vg_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 15 16// 1 found / 0 absent / -1 file missing 17func vg_has(path: *u8, needle: *u8) -> i64 { 18 let fd: i64=sys_openat_rd(path); if fd<0 { return 0-1 } 19 let cap: i64=2097152 20 let buf: *u8=sys_mmap(cap+16) 21 var total: i64=0; var nrd: i64=sys_read(fd, buf, cap) 22 while nrd>0 { total=total+nrd; if total>=cap { nrd=0 } else { nrd=sys_read(fd, ((buf as i64)+total) as *u8, cap-total) } } 23 sys_close(fd) 24 let nl: i64=vg_strlen(needle); if nl==0 { return 0 } 25 var i: i64=0 26 while i+nl<=total { var j: i64=0; var ok: i64=1; while j<nl { if buf[i+j]!=needle[j] { ok=0; j=nl } else { j=j+1 } } if ok==1 { return 1 } i=i+1 } 27 return 0 28} 29 30// st[0]=pass st[1]=fail st[2]=missing-file 31func vg_must(name: *u8, path: *u8, needle: *u8, st: *i64) -> i64 { 32 let h: i64=vg_has(path, needle) 33 vg_puts(" [need] " as *u8); vg_puts(name) 34 if h < 0 { vg_puts(" -> FILE MISSING (RED)\n" as *u8); st[2]=st[2]+1; return 2 } 35 if h == 1 { vg_puts(" -> ok\n" as *u8); st[0]=st[0]+1; return 0 } 36 vg_puts(" -> MARKER ABSENT (RED)\n" as *u8); st[1]=st[1]+1; return 1 37} 38func vg_not(name: *u8, path: *u8, needle: *u8, st: *i64) -> i64 { 39 let h: i64=vg_has(path, needle) 40 vg_puts(" [deny] " as *u8); vg_puts(name) 41 if h < 0 { vg_puts(" -> FILE MISSING (RED)\n" as *u8); st[2]=st[2]+1; return 2 } 42 if h == 1 { vg_puts(" -> FORBIDDEN PRESENT (RED)\n" as *u8); st[1]=st[1]+1; return 1 } 43 vg_puts(" -> absent ok\n" as *u8); st[0]=st[0]+1; return 0 44} 45 46func main() -> i64 { 47 let TGT: *u8="web_assets/video_embed.html" as *u8 48 let LDR: *u8="web_assets/embed.js" as *u8 49 let DMO: *u8="web_assets/video_embed_demo.html" as *u8 50 let st: *i64 = sys_mmap(8*4) as *i64 51 st[0]=0; st[1]=0; st[2]=0 52 53 vg_puts("=== NISHI-VIDEO-EMBED GATE (structural + security + sovereignty over the 3 emitted artifacts) ===\n" as *u8) 54 55 vg_puts("-- video_embed.html (the origin-isolated iframe target) --\n" as *u8) 56 vg_must("camera capture (getUserMedia) " as *u8, TGT, "getUserMedia" as *u8, st) 57 vg_must("typed postMessage handshake UP " as *u8, TGT, "postMessage" as *u8, st) 58 vg_must("ready event (nishi:ready) " as *u8, TGT, "nishi:ready" as *u8, st) 59 vg_must("host command channel (nishi:cmd) " as *u8, TGT, "nishi:cmd" as *u8, st) 60 vg_must("INBOUND ORIGIN CHECK (e.origin!==PORIGIN) " as *u8, TGT, "e.origin!==PORIGIN" as *u8, st) 61 vg_must("source check (e.source!==parent) " as *u8, TGT, "e.source!==parent" as *u8, st) 62 vg_must("proven relay send route (post?) " as *u8, TGT, "post?" as *u8, st) 63 vg_must("proven relay recv route (stream?) " as *u8, TGT, "stream?" as *u8, st) 64 vg_must("proven relay audio route (apost?) " as *u8, TGT, "apost?" as *u8, st) 65 vg_must("watch (receive-only) mode supported " as *u8, TGT, "MODE==='watch'" as *u8, st) 66 vg_must("resource CSP hardening " as *u8, TGT, "Content-Security-Policy" as *u8, st) 67 vg_must("no-credential cross-fetch (credentials:omit) " as *u8, TGT, "credentials:'omit'" as *u8, st) 68 vg_not ("NO cookies (document.cookie) " as *u8, TGT, "document.cookie" as *u8, st) 69 vg_not ("NO insecure/third-party absolute (http://) " as *u8, TGT, "http://" as *u8, st) 70 vg_not ("NO google tracker " as *u8, TGT, "googletag" as *u8, st) 71 vg_not ("NO doubleclick ad-tech " as *u8, TGT, "doubleclick" as *u8, st) 72 73 vg_puts("-- embed.js (the <nishi-video> publisher loader) --\n" as *u8) 74 vg_must("registers <nishi-video> custom element " as *u8, LDR, "customElements.define('nishi-video'" as *u8, st) 75 vg_must("shadow-DOM host wrapper (attachShadow) " as *u8, LDR, "attachShadow" as *u8, st) 76 vg_must("sandboxed iframe (allow-same-origin) " as *u8, LDR, "allow-same-origin" as *u8, st) 77 vg_must("scripts sandboxed (allow-scripts) " as *u8, LDR, "allow-scripts" as *u8, st) 78 vg_must("LEAST-PRIVILEGE allow= (camera; microphone) " as *u8, LDR, "camera; microphone" as *u8, st) 79 vg_must("BRIDGE ORIGIN CHECK (e.origin!==self._host) " as *u8, LDR, "e.origin!==self._host" as *u8, st) 80 vg_must("typed comms to host (CustomEvent) " as *u8, LDR, "CustomEvent" as *u8, st) 81 vg_must("host allowlist (https://nishifamily.com) " as *u8, LDR, "https://nishifamily.com" as *u8, st) 82 vg_must("referrer suppressed (no-referrer) " as *u8, LDR, "no-referrer" as *u8, st) 83 vg_not ("NO eval " as *u8, LDR, "eval(" as *u8, st) 84 vg_not ("NO cookies " as *u8, LDR, "document.cookie" as *u8, st) 85 vg_not ("NO ad-tech " as *u8, LDR, "doubleclick" as *u8, st) 86 87 vg_puts("-- video_embed_demo.html (third-party host demo) --\n" as *u8) 88 vg_must("drops <nishi-video> element " as *u8, DMO, "<nishi-video" as *u8, st) 89 vg_must("loads the sovereign loader (embed.js) " as *u8, DMO, "embed.js" as *u8, st) 90 vg_must("listens to typed events (addEventListener) " as *u8, DMO, "addEventListener" as *u8, st) 91 vg_must("shows the copy-paste snippet " as *u8, DMO, "&lt;nishi-video" as *u8, st) 92 93 vg_puts("----\nGATE: pass=" as *u8); vg_pn(st[0]) 94 vg_puts(" fail=" as *u8); vg_pn(st[1]) 95 vg_puts(" missing-file=" as *u8); vg_pn(st[2]); vg_puts("\n" as *u8) 96 97 let lg: i64=sys_openat_append("knowledge/status/video_embed_gate.log" as *u8, 0x1a4) 98 if lg>=0 { var w: *u8="VIDEO-EMBED-GATE pass=" as *u8; var n: i64=0; while w[n]!=(0 as u8){n=n+1} sys_write(lg,w,n); sys_close(lg) } 99 100 if st[1]==0 { if st[2]==0 { 101 vg_puts("VIDEO-EMBED-GATE GREEN: every safety/sovereignty marker present, zero bullshit, all 3 artifacts real.\n" as *u8) 102 sys_exit(0); return 0 103 } } 104 vg_puts("VIDEO-EMBED-GATE RED: a required marker is absent, a forbidden marker is present, or an artifact is missing.\n" as *u8) 105 sys_exit(1); return 1 106}