code wiki / _hdl_build / nx_clean_serve.nx

nx_clean_serve.nx

buildroot/runtime/_hdl_build/nx_clean_serve.nx

25843 B356 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
18const CS_SKIP_LINE_CAP: i64 = 256 // one row of the media skip table (a substring), NUL-terminated
19const CS_DECL_SEP_MAX: i64 = 24 // bytes of separator tolerated between a declaration key and its quoted value (` content=`, `: `)
20const CS_TOKEN_MIN: i64 = 5 // a page id token shorter than this is too common to identify a stream (a bare numeric year, a two-letter slug)
21const CS_LISTING_MIN: i64 = 6 // this many distinct stream literals with none carrying the page token = a listing grid, not a player
24const CS_ALLOW: i64 = 0 // content / first-party / unknown -> pass through
25const CS_BLOCK: i64 = 1 // an attack vector (tracker/miner/malware/popunder) -> remove entirely
26const CS_SANITIZE: i64 = 2 // an ad -> keep as an inert static creative (site monetizes, user stays safe)
29const CR_SCRIPTS: i64 = 0 // <script> blocks removed
30const CR_IFRAMES: i64 = 1 // active third-party frames removed
31const CR_HANDLERS: i64 = 2 // inline on*= event handlers stripped
32const CR_REDIRECTS: i64 = 3 // meta-refresh + javascript: exec/redirect vectors neutralized
33const CR_MINER: i64 = 4 // crypto-miner request URLs neutralized
34const CR_POPUP: i64 = 5 // popunder request URLs neutralized
35const CR_MAL: i64 = 6 // malware/scam request URLs neutralized
36const CR_TRACK: i64 = 7 // tracker/beacon request URLs neutralized
37const CR_ADS_KEPT: i64 = 8 // ad creatives PRESERVED as safe static (the site's monetization, intact)
38const CR_BLOCKED: i64 = 9 // total attack request URLs neutralized (sum of miner+popup+mal+track)
39const CR_ADVIDEO: i64 = 10 // autoplaying ad VIDEO elements removed (a 728x90 banner clip is a creative, not the content)
40const CR_N: i64 = 11
56const CS_MAX_TAG: i64 = 16384
119const CS_VERDICT_BUDGET: i64 = 400

functions

43func cs_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
44func 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 }
45func 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 1: cs_receipt_json calls 1: sys_mmap
46func cs_lc(c: i64) -> i64 { if c>=65 { if c<=90 { return c+32 } } return c }
called by 1: cs_ci_at
47func 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 }
48func 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
58func cs_tag_end(src: *u8, slen: i64, from: i64) -> i64
called by 1: cs_clean_into
71func cs_within(src: *u8, from: i64, to: i64, lit: *u8, litlen: i64) -> i64
called by 1: cs_clean_into calls 1: cs_ci_at
77func 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
79func 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 }
81func 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
105func 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 }
108func cs_verdict(t: *i64, url: *u8, ul: i64, out_cat: *i64) -> i64
121func cs_scan_urls(src: *u8, slen: i64, t: *i64, rc: *i64) -> i64
156func cs_clean_into(out: *u8, off: i64, cap: i64, src: *u8, slen: i64, t: *i64, rc: *i64) -> i64
223func cs_clean_page(src: *u8, slen: i64, t: *i64, out: *u8, cap: i64, rc: *i64) -> i64
239func cs_entity_body_off(buf: *u8, n: i64) -> i64
247func cs_has_ci(hay: *u8, hl: i64, needle: *u8) -> i64 { let nl: i64 = cs_slen(needle); if nl==0 { return 0 } if nl>hl { return 0 } var i: i64=0; let last: i64=hl-nl; while i<=last { if cs_ci_at(hay, hl, i, needle, nl)==1 { return 1 } i=i+1 } return 0 }
249func cs_media_ext(url: *u8, ul: i64) -> i64 { if cs_has_ci(url, ul, ".m3u8" as *u8)==1 { return 1 } if cs_has_ci(url, ul, ".mp4" as *u8)==1 { return 1 } if cs_has_ci(url, ul, ".webm" as *u8)==1 { return 1 } return 0 }
255func cs_media_skip(url: *u8, ul: i64, table: *u8) -> i64
288func cs_quoted_after(html: *u8, hn: i64, key: *u8, out: *u8, cap: i64) -> i64
312func cs_find_declared(html: *u8, hn: i64, out: *u8, cap: i64) -> i64
325func cs_page_token(url: *u8, ul: i64, out: *u8, cap: i64) -> i64
341func cs_receipt_json(rc: *i64, out: *u8, cap: i64) -> i64