code wiki / _hdl_build / nx_reader_sov.nx
nx_reader_sov.nx source
↩ module page · 25 lines · 1585 B
1// nx_reader_sov.nx -- shared FAIL-CLOSED sovereignty predicate for the reader last-mile.
2// reader_sovereign_ok(buf,n): 1 = clean (zero third-party loads), 0 = REFUSE. Used by BOTH nx_reader_page
3// (emit-time enforcement: refuse to write the served file if the source carries a 3rd-party load) AND
4// nx_reader_page_gate (tests the SAME predicate directly -> no subprocess needed). Prefixed helpers compose
5// without symbol clash. Pure (no syscalls). license_tier: ORIGINAL
6func rsv_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
7func rsv_find(hay: *u8, hl: i64, needle: *u8) -> i64 {
8 let nl: i64 = rsv_slen(needle); if nl == 0 { return 0-1 }
9 var i: i64 = 0
10 while i + nl <= hl { 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 }
11 return 0-1
12}
13func rsv_has(hay: *u8, hl: i64, needle: *u8) -> i64 { if rsv_find(hay, hl, needle) >= 0 { return 1 } return 0 }
14func reader_sovereign_ok(buf: *u8, n: i64) -> i64 {
15 if rsv_has(buf, n, "<script src=" as *u8) == 1 { return 0 }
16 if rsv_has(buf, n, "src=\"http" as *u8) == 1 { return 0 }
17 if rsv_has(buf, n, "href=\"http" as *u8) == 1 { return 0 }
18 if rsv_has(buf, n, "@import" as *u8) == 1 { return 0 }
19 if rsv_has(buf, n, "<iframe" as *u8) == 1 { return 0 }
20 if rsv_has(buf, n, "googleapis" as *u8) == 1 { return 0 }
21 if rsv_has(buf, n, "jsdelivr" as *u8) == 1 { return 0 }
22 if rsv_has(buf, n, "unpkg" as *u8) == 1 { return 0 }
23 if rsv_has(buf, n, "epub.js" as *u8) == 1 { return 0 }
24 return 1
25}