code wiki / _hdl_build / nx_meet_intake_process_gate.nx

nx_meet_intake_process_gate.nx source

↩ module page · 66 lines · 5003 B

1// nx_meet_intake_process_gate.nx -- liar-kill gate for P2 (submission processing). Proves: the processor SCREENS 2// (clean apply -> SCREENED; AI-slop / ghost / honeypot-bot -> FLAGGED, composing R6+R7), and SANITIZES untrusted 3// values so a CRLF header-injection attempt ("Eve\r\nBcc: evil") collapses to inert text in BOTH the application 4// record AND the confirmation email -- no injected record line, no injected mail header. expect_exit: 0 5import "nx_syscalls.nx" 6import "nx_meet_lib.nx" 7import "nx_meet_curate.nx" 8import "nx_meet_intake_process.nx" 9 10func mfind(hay: *u8, n: i64, needle: *u8) -> i64 { 11 let nl: i64 = mlen(needle); if nl == 0 { return 0 - 1 } 12 var i: i64 = 0 13 while i + nl <= n { var k: i64=0; var hit: i64=1; while k<nl { if hay[i+k]!=needle[k]{hit=0;k=nl}else{k=k+1} } if hit==1 {return i} i=i+1 } 14 return 0 - 1 15} 16 17func main() -> i64 { 18 mputs("=== nx_meet_intake_process_gate: screen (R6+R7) + injection-safe record/confirm ===\n" as *u8) 19 20 let mt: *u8 = sys_mmap(8); mt[0] = 0 as u8 // empty honeypot (real empty buffer; "" literal is unsafe for mlen) 21 let cleanres: *u8 = "Built payment service handling 12000 req/s at Acme; cut latency 38 percent. jane@example.com github.com/jane" as *u8 22 let slopres: *u8 = "As an AI language model, results-driven professional with synergy, a proven track record, detail-oriented go-getter." as *u8 23 let ghost: *u8 = "Be your own boss, unlimited earning! Competitive salary, fast-paced environment, always hiring rockstars." as *u8 24 25 // an untrusted name + email carrying a CRLF header-injection payload (built with real control bytes) 26 let injname: *u8 = sys_mmap(64) 27 var p: i64 = mcat(injname, 0, "Eve" as *u8); injname[p] = 13 as u8; injname[p+1] = 10 as u8; p = p + 2; p = mcat(injname, p, "Bcc: evil@x.com" as *u8) 28 let injmail: *u8 = sys_mmap(64) 29 var q: i64 = mcat(injmail, 0, "eve@x.com" as *u8); injmail[q] = 13 as u8; injmail[q+1] = 10 as u8; q = q + 2; q = mcat(injmail, q, "Bcc: evil" as *u8) 30 31 // build a sanitized application record for the injection submission (status from the screen verdict) 32 let rec: *u8 = sys_mmap(4096) 33 var ro: i64 = rec_field(rec, 0, "kind" as *u8, "apply" as *u8) 34 ro = rec_field(rec, ro, "name" as *u8, injname) 35 ro = rec_field(rec, ro, "email" as *u8, injmail) 36 ro = rec_field(rec, ro, "status" as *u8, curate_state_name(curate_screen_resume(cleanres, mt))) 37 38 // build confirmations: one for the injection submission, one clean 39 let conf: *u8 = sys_mmap(4096); intake_confirm(conf, injname, injmail, "application" as *u8) 40 let cn: i64 = mlen(conf) 41 let conf2: *u8 = sys_mmap(4096); intake_confirm(conf2, "Jane Doe" as *u8, "jane@example.com" as *u8, "application" as *u8) 42 let c2n: i64 = mlen(conf2) 43 let rn: i64 = mlen(rec) 44 45 var pass: i64 = 0; var fail: i64 = 0 46 // screening (composes R6 + R7) 47 if curate_screen_resume(cleanres, mt) == ST_SCREENED { pass=pass+1 } else { fail=fail+1; mputs(" FAIL clean-not-screened\n" as *u8) } 48 if curate_screen_resume(cleanres, "bot-filled" as *u8) == ST_FLAGGED { pass=pass+1 } else { fail=fail+1; mputs(" FAIL honeypot-not-flagged\n" as *u8) } 49 if curate_screen_resume(slopres, mt) == ST_FLAGGED { pass=pass+1 } else { fail=fail+1; mputs(" FAIL slop-not-flagged\n" as *u8) } 50 if curate_screen_posting(ghost, mt) == ST_FLAGGED { pass=pass+1 } else { fail=fail+1; mputs(" FAIL ghost-not-flagged\n" as *u8) } 51 // record built + status from verdict 52 if mfind(rec, rn, "status: SCREENED" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; mputs(" FAIL record-status-missing\n" as *u8) } 53 // INJECTION TEETH: the CRLF was stripped, collapsing "Eve\r\nBcc:" -> "EveBcc:" (one inert line, no new header) 54 if mfind(rec, rn, "name: EveBcc: evil@x.com" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; mputs(" FAIL record-not-sanitized\n" as *u8) } 55 if mfind(rec, rn, "email: eve@x.comBcc: evil" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; mputs(" FAIL record-email-not-sanitized\n" as *u8) } 56 // confirmation: injection neutralized in headers 57 if mfind(conf, cn, "To: eve@x.comBcc: evil" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; mputs(" FAIL confirm-header-injection\n" as *u8) } 58 if mfind(conf, cn, "From: intake@" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; mputs(" FAIL confirm-no-from\n" as *u8) } 59 // clean confirmation well-formed 60 if mfind(conf2, c2n, "To: jane@example.com" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; mputs(" FAIL clean-confirm-to\n" as *u8) } 61 if mfind(conf2, c2n, "Hi Jane Doe" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; mputs(" FAIL clean-confirm-body\n" as *u8) } 62 63 mputs("MEET-INTAKE-PROCESS-GATE pass=" as *u8); mnum(pass); mputs(" fail=" as *u8); mnum(fail) 64 if fail == 0 { mputs(" verdict=GREEN (screen R6+R7 + CRLF/header-injection-safe record + confirmation)\n" as *u8); sys_exit(0); return 0 } 65 mputs(" verdict=RED\n" as *u8); sys_exit(1); return 1 66}