code wiki / _hdl_build / nx_gallery_nsfw_gate.nx

nx_gallery_nsfw_gate.nx source

↩ module page · 95 lines · 5979 B

1import "nx_gate_base.nx" 2// nx_gallery_nsfw_gate.nx -- proves the GATED NSFW SECTION for nishifamily.com/gallery (operator 2026-06-17: 3// "only /gallery is nsfw, the rest is fine to expose; don't call out the nsfw till it's gated"). Policy over 4// nx_authz: catch-all "/" -> level 0 (PUBLIC, the rest is exposable) + "/gallery/private/" -> level 2 (the NSFW 5// section). Proves: NSFW is served ONLY to a private-level (2) user; public(0) and family(1) are DENIED; and -- 6// the key non-disclosure property -- the NSFW items are NEVER EVEN LISTED for non-private users (authz_filter 7// omits them), so the public gallery index / wiki / AI front-door cannot surface them. The rest (public items, 8// non-gallery paths) stays exposed. license_tier: ORIGINAL 9import "nx_authz.nx" 10import "nx_syscalls.nx" 11 12func gslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 13func grow(id: i64, ok: i64, what: *u8) -> i64 { gw("GNROW " as *u8); let b: *u8=sys_mmap(8); b[0]=(48+id) as u8; sys_write(1,b,1); gw(" " as *u8); if ok==1 { gw("PASS " as *u8) } else { gw("FAIL " as *u8) } gw(what); gw("\n" as *u8); return ok } 14func gcontains(hay: *u8, hn: i64, needle: *u8) -> i64 { 15 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 16 if nl==0 { return 1 } if nl>hn { return 0 } 17 let last: i64=hn-nl; var i: i64=0 18 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 } 19 return 0 20} 21func gallow(level: i64, paths: *i64, lens: *i64, lvls: *i64, n: i64, req: *u8) -> i64 { 22 return authz_level_allow(level, paths, lens, lvls, n, req, gslen(req)) 23} 24 25func main() -> i64 { 26 gw("gallery NSFW gate: only /gallery/private is gated (private level); the rest is exposed; NSFW never listed\n" as *u8) 27 28 // gallery policy: catch-all public + the gated NSFW section 29 let pp: *i64 = sys_mmap(8*8) as *i64 30 let pl: *i64 = sys_mmap(8*8) as *i64 31 let pv: *i64 = sys_mmap(8*8) as *i64 32 pp[0]="/" as *u8 as i64; pl[0]=gslen("/" as *u8); pv[0]=0 33 pp[1]="/gallery/private/" as *u8 as i64; pl[1]=gslen("/gallery/private/" as *u8); pv[1]=2 34 let np: i64 = 2 35 36 // the gallery's full item list (the NSFW ones live under /gallery/private/) 37 let items: *i64 = sys_mmap(8*8) as *i64 38 let ilen: *i64 = sys_mmap(8*8) as *i64 39 items[0]="/gallery/sunset.jpg" as *u8 as i64; ilen[0]=gslen("/gallery/sunset.jpg" as *u8) 40 items[1]="/gallery/dog.jpg" as *u8 as i64; ilen[1]=gslen("/gallery/dog.jpg" as *u8) 41 items[2]="/gallery/private/p1" as *u8 as i64; ilen[2]=gslen("/gallery/private/p1" as *u8) 42 items[3]="/gallery/private/p2" as *u8 as i64; ilen[3]=gslen("/gallery/private/p2" as *u8) 43 let nit: i64 = 4 44 45 var rows: i64 = 0 46 var pass: i64 = 0 47 var ok: i64 = 0 48 49 // R0: a PUBLIC (level 0) listing shows only the public items -- the NSFW is OMITTED 50 let pubout: *i64 = sys_mmap(8*8) as *i64 51 let pubn: i64 = authz_filter(0, items, ilen, nit, pp, pl, pv, np, pubout) 52 ok = 0; if pubn == 2 { ok = 1 } 53 rows=rows+1; pass=pass+grow(0, ok, "public listing shows 2 public items, NSFW omitted (count)" as *u8) 54 55 // R1: NON-DISCLOSURE -- no item in the public listing mentions the NSFW section path 56 ok = 1 57 var k: i64 = 0 58 while k < pubn { if gcontains(pubout[k] as *u8, ilen[k], "/private/" as *u8) == 1 { ok = 0 } k = k + 1 } 59 rows=rows+1; pass=pass+grow(1, ok, "NON-DISCLOSURE: public listing never mentions /gallery/private (not called out)" as *u8) 60 61 // R2: public(0) and family(1) are DENIED the NSFW items 62 ok = 0; if gallow(0, pp, pl, pv, np, "/gallery/private/p1" as *u8)==AUTHZ_DENY { if gallow(1, pp, pl, pv, np, "/gallery/private/p1" as *u8)==AUTHZ_DENY { ok=1 } } 63 rows=rows+1; pass=pass+grow(2, ok, "NSFW DENIED to public + family levels (not shared by all)" as *u8) 64 65 // R3: a private (2) user CAN view the NSFW 66 ok = 0; if gallow(2, pp, pl, pv, np, "/gallery/private/p1" as *u8)==AUTHZ_ALLOW { ok=1 } 67 rows=rows+1; pass=pass+grow(3, ok, "NSFW allowed to a private-level (2) user (the gated section)" as *u8) 68 69 // R4: a private (2) listing shows ALL items (incl the NSFW section) 70 let prvout: *i64 = sys_mmap(8*8) as *i64 71 let prvn: i64 = authz_filter(2, items, ilen, nit, pp, pl, pv, np, prvout) 72 ok = 0; if prvn == 4 { ok = 1 } 73 rows=rows+1; pass=pass+grow(4, ok, "private listing shows all 4 (public + NSFW) for a private user" as *u8) 74 75 // R5: THE REST IS EXPOSED -- public(0) can view public gallery items + any non-gallery path 76 ok = 0; if gallow(0, pp, pl, pv, np, "/gallery/sunset.jpg" as *u8)==AUTHZ_ALLOW { if gallow(0, pp, pl, pv, np, "/wiki/charter" as *u8)==AUTHZ_ALLOW { ok=1 } } 77 rows=rows+1; pass=pass+grow(5, ok, "the rest is exposed: public sees public gallery items + non-gallery paths" as *u8) 78 79 // R6: family (1) listing ALSO omits the NSFW (only level 2 sees it) 80 let famout: *i64 = sys_mmap(8*8) as *i64 81 let famn: i64 = authz_filter(1, items, ilen, nit, pp, pl, pv, np, famout) 82 ok = 0; if famn == 2 { ok = 1 } 83 rows=rows+1; pass=pass+grow(6, ok, "family listing also omits NSFW (only the private level sees it)" as *u8) 84 85 gw("NX-GALLERY-NSFW-GATE rows=" as *u8); let rb: *u8=sys_mmap(8); rb[0]=(48+rows) as u8; sys_write(1,rb,1); gw(" pass=" as *u8); let pb: *u8=sys_mmap(8); pb[0]=(48+pass) as u8; sys_write(1,pb,1); gw("\n" as *u8) 86 if pass == rows { 87 let line: *u8 = "CMSGATE row=nx_gallery_nsfw gated-nsfw-section rows=7 pass=7 verdict=PASS\n" as *u8 88 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4) 89 if gf >= 0 { sys_write(gf, line, gslen(line)); sys_close(gf) } 90 gw("NX-GALLERY-NSFW-GATE GREEN 7/7 (NSFW gated to private level + never listed publicly; rest exposed)\n" as *u8) 91 sys_exit(0); return 0 92 } 93 gw("NX-GALLERY-NSFW-GATE RED\n" as *u8) 94 sys_exit(1); return 1 95}