code wiki / _hdl_build / nx_pub_bypass_gate.nx

nx_pub_bypass_gate.nx source

↩ module page · 52 lines · 3599 B

1// nx_pub_bypass_gate.nx -- R7 proof for THE NISHI PUBLISHER no-bypass LAW. A small corpus of source files is 2// audited: (1) a workstream that calls the raw transport nx_aw_send directly is FLAGGED; (2) likewise nx_aw_push; 3// (3) a workstream that publishes via pub_submit is NOT flagged; (4) the publisher itself (which legitimately 4// wraps the transport) is allowlisted -> NOT flagged. Clean passing + bypass catching = the audit is content- 5// driven, not always-pass/always-flag. This makes "no more direct publishing from workstreams" MECHANICAL. 6// Sovereign, per-wsid isolated. license_tier: ORIGINAL expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_publisher.nx" 9import "nx_runpath.nx" 10 11func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); 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; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 13func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" " as *u8); g_w(id); g_w(": " as *u8); if ok==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } return 0 } 14func dg_make(path: *u8, content: *u8) -> i64 { 15 let fd: i64 = sys_openat_wr(path, 0x1a4); if fd < 0 { return 0 } 16 var n: i64 = 0; while content[n]!=(0 as u8){n=n+1} 17 sys_write(fd, content, n); sys_close(fd); return 1 18} 19 20func main() -> i64 { 21 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0 22 g_w("=== NX-PUBLISHER BYPASS GATE (no-bypass LAW: publish via pub_submit ONLY) ===\n" as *u8) 23 let wsid: *u8 = sys_mmap(64); rp_wsid(wsid); rp_ensure(wsid) 24 let fa: *u8 = sys_mmap(512); rp_path(wsid, "byp_send" as *u8, fa) 25 let fb: *u8 = sys_mmap(512); rp_path(wsid, "byp_push" as *u8, fb) 26 let fc: *u8 = sys_mmap(512); rp_path(wsid, "byp_clean" as *u8, fc) 27 let fd_: *u8 = sys_mmap(512); rp_path(wsid, "byp_pub" as *u8, fd_) 28 29 // a workstream that calls the raw transport directly (the violation we forbid) 30 dg_make(fa, "func deploy_my_page() { nx_aw_send(host, mypage_html) }\n" as *u8) 31 dg_make(fb, "func ship() { nx_aw_push(target_path) }\n" as *u8) 32 // a compliant workstream: requests through the publisher 33 dg_make(fc, "import nx_publisher\nfunc ship() { pub_submit(art, dest, site, ws, policy) }\n" as *u8) 34 // the publisher itself: legitimately references the transport, but it IS the sanctioned single writer 35 dg_make(fd_, "func pub_do_deploy() { nx_aw_send(host, staged) }\n" as *u8) 36 37 let v_send: i64 = pub_audit_file(fa, 0) 38 let v_push: i64 = pub_audit_file(fb, 0) 39 let v_clean: i64 = pub_audit_file(fc, 0) 40 let v_pub: i64 = pub_audit_file(fd_, 1) 41 42 g_w(" audit: direct-nx_aw_send="); g_n(v_send); g_w(" direct-nx_aw_push="); g_n(v_push); g_w(" pub_submit-user="); g_n(v_clean); g_w(" publisher(allowlisted)="); g_n(v_pub); g_w("\n") 43 44 g_row("BYPASS CAUGHT: a workstream calling nx_aw_send directly is FLAGGED" as *u8, (v_send==1) as i64, pass) 45 g_row("BYPASS CAUGHT: a workstream calling nx_aw_push directly is FLAGGED" as *u8, (v_push==1) as i64, pass) 46 g_row("CLEAN PASSES: a workstream publishing via pub_submit is NOT flagged" as *u8, (v_clean==0) as i64, pass) 47 g_row("ALLOWLIST: the publisher itself (sanctioned single writer) is NOT flagged" as *u8, (v_pub==0) as i64, pass) 48 49 g_w("PUB-BYPASS rows=4 pass="); g_n(pass[0]) 50 if pass[0]==4 { g_w(" verdict=GREEN\n"); sys_exit(0); return 0 } 51 g_w(" verdict=RED\n"); sys_exit(1); return 1 52}