code wiki / _hdl_build / nx_clean_serve.nx

nx_clean_serve.nx

buildroot/runtime/_hdl_build/nx_clean_serve.nx

16154 B233 linesdepth 4pulls 4 transitivereach 3 importersview sourcekind librarytopic clean
docsdependenciesstructsconstsfunctions

about

nx_clean_serve.nx -- the ETHICAL clean-serve policy engine: the win-win-win transform for the Nishi search engine's neutral, safe delivery of hostile sites. The problem with strip-and-block (ad_strip_junk) is that it nukes EVERY script -> the user is safe but the SITE earns nothing (all ads die too). The problem with letting ads through is malvertising (redirect / popunder / cryptojack / tabnab / fingerprint). The middle path is a THIRD verdict -- SANITIZE: an ad is KEPT as an inert, script-free static creative (image + a click link with rel="noopener noreferrer nofollow") so the SITE still earns the impression + click, while every attack vector (which ALL require active content -- JS, unsandboxed frames, beacons, auto-redirect) is removed. Result: USER safe (no active content survives) + gets the content native HTML5; SITE monetizes (its safe static ads render + click through); SEARCH neutral (a difficult site is served cleanly, not deranked). Composes nx_web_filter's data-driven category verdict. Pure core: the archive daemon imports it for /visit and /preserve; the gate tests it headless with an adversary corpus. Emits a machine-readable SAFETY RECEIPT. license_tier: ORIGINAL

dependencies 2 imports · 3 importers

nx_syscalls.nx nx_web_filter.nx nx_clean_serve.nx nx_clean_serve_daemon.nx nx_clean_serve_gate.nx nx_cleanview.nx

imports: nx_syscalls.nxnx_web_filter.nx

imported by: nx_clean_serve_daemon.nxnx_clean_serve_gate.nxnx_cleanview.nx

structs

none

consts

16const CS_MAGIC_4096: i64 = 4096
17const CS_MAGIC_4095: i64 = 4095
20const CS_ALLOW: i64 = 0 // content / first-party / unknown -> pass through
21const CS_BLOCK: i64 = 1 // an attack vector (tracker/miner/malware/popunder) -> remove entirely
22const CS_SANITIZE: i64 = 2 // an ad -> keep as an inert static creative (site monetizes, user stays safe)
25const CR_SCRIPTS: i64 = 0 // <script> blocks removed
26const CR_IFRAMES: i64 = 1 // active third-party frames removed
27const CR_HANDLERS: i64 = 2 // inline on*= event handlers stripped
28const CR_REDIRECTS: i64 = 3 // meta-refresh + javascript: exec/redirect vectors neutralized
29const CR_MINER: i64 = 4 // crypto-miner request URLs neutralized
30const CR_POPUP: i64 = 5 // popunder request URLs neutralized
31const CR_MAL: i64 = 6 // malware/scam request URLs neutralized
32const CR_TRACK: i64 = 7 // tracker/beacon request URLs neutralized
33const CR_ADS_KEPT: i64 = 8 // ad creatives PRESERVED as safe static (the site's monetization, intact)
34const CR_BLOCKED: i64 = 9 // total attack request URLs neutralized (sum of miner+popup+mal+track)
35const CR_N: i64 = 10
51const CS_MAX_TAG: i64 = 16384
114const CS_VERDICT_BUDGET: i64 = 400

functions

38func cs_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 2: g_hasmain
39func cs_put(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off]=s[i];off=off+1;i=i+1} return off }
40func cs_putn(dst: *u8, off: i64, v: i64) -> i64 { var m: i64=v; if m==0 { dst[off]=48 as u8; return off+1 } let t: *u8=sys_mmap(24); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var j: i64=0; while j<k { dst[off]=t[k-1-j]; off=off+1; j=j+1 } return off }
called by 2: cs_receipt_jsonmain calls 1: sys_mmap
41func cs_lc(c: i64) -> i64 { if c>=65 { if c<=90 { return c+32 } } return c }
called by 1: cs_ci_at
42func cs_ci_at(src: *u8, slen: i64, pos: i64, lit: *u8, litlen: i64) -> i64 { if pos+litlen>slen { return 0 } var i: i64=0; while i<litlen { if cs_lc(src[pos+i]&0xff)!=cs_lc(lit[i]&0xff) { return 0 } i=i+1 } return 1 }
43func cs_skip_block(src: *u8, slen: i64, from: i64, close: *u8, closelen: i64) -> i64
called by 1: cs_clean_into calls 1: cs_ci_at
53func cs_tag_end(src: *u8, slen: i64, from: i64) -> i64
called by 1: cs_clean_into
66func cs_within(src: *u8, from: i64, to: i64, lit: *u8, litlen: i64) -> i64
called by 1: cs_clean_into calls 1: cs_ci_at
72func cs_a_delim(c: i64) -> i64 { if c==32 {return 1} if c==9 {return 1} if c==10 {return 1} if c==13 {return 1} if c==62 {return 1} return 0 }
called by 1: cs_clean_into
74func cs_url_delim(c: i64) -> i64 { if c==34{return 1} if c==39{return 1} if c==32{return 1} if c==60{return 1} if c==62{return 1} if c==41{return 1} if c==125{return 1} if c==93{return 1} if c==92{return 1} if c==10{return 1} if c==9{return 1} if c==13{return 1} return 0 }
76func cs_tag_attr(src: *u8, from: i64, to: i64, name: *u8, namelen: i64, out: *u8, cap: i64) -> i64
called by 1: cs_clean_into calls 1: cs_ci_at
100func cs_rc_new() -> *i64 { let rc: *i64 = sys_mmap(8*CR_N) as *i64; var z: i64=0; while z<CR_N { rc[z]=0; z=z+1 } return rc }
103func cs_verdict(t: *i64, url: *u8, ul: i64, out_cat: *i64) -> i64
116func cs_scan_urls(src: *u8, slen: i64, t: *i64, rc: *i64) -> i64
151func cs_clean_into(out: *u8, off: i64, cap: i64, src: *u8, slen: i64, t: *i64, rc: *i64) -> i64
211func cs_clean_page(src: *u8, slen: i64, t: *i64, out: *u8, cap: i64, rc: *i64) -> i64
219func cs_receipt_json(rc: *i64, out: *u8, cap: i64) -> i64