code wiki / _hdl_build / nx_meta_refresh_gate.nx
nx_meta_refresh_gate.nx source
↩ module page · 50 lines · 3770 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_meta_refresh_gate.nx -- proves the meta-refresh / Refresh-header redirect parser (rank 9): extracts the
4// target from the real-world variants (quoted / unquoted / spaced / attribute-order / Refresh header) and
5// correctly declines relative-only, non-refresh meta, and no-refresh pages. license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_x509_trust_store.nx"
8import "nx_browser_fetch.nx"
9
10func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
11" as *u8); return ok }
12func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
13func streq(a: *u8, b: *u8) -> i64 { if gsl(a)!=gsl(b) { return 0 } var i: i64=0; while a[i]!=(0 as u8){ if (a[i]&0xff)!=(b[i]&0xff){return 0} i=i+1 } return 1 }
14func mref(html: *u8, out: *u8) -> i64 { return bf_meta_refresh(html, gsl(html), out, 4096) }
15
16func main() -> i64 {
17 gw("meta-refresh SOVEREIGN gate (rank 9: follow <meta refresh>/Refresh chains to the real content)\n" as *u8)
18 var pass: i64 = 0
19 var ttl: i64 = 0
20 let out: *u8 = sys_mmap(4096)
21
22 // M1: standard double-quoted meta refresh
23 mref("<html><head><meta http-equiv=\"refresh\" content=\"0;url=https://real.example/article\"></head></html>" as *u8, out)
24 ttl=ttl+1; pass=pass+grow("M1 quoted 0;url= -> https://real.example/article\x00" as *u8, streq(out, "https://real.example/article" as *u8))
25 // M2: spaced content + single quotes + delay
26 mref("<meta http-equiv='refresh' content='3; url=https://dest.example/page2'>" as *u8, out)
27 ttl=ttl+1; pass=pass+grow("M2 spaced '3; url=' single-quote -> dest.example/page2\x00" as *u8, streq(out, "https://dest.example/page2" as *u8))
28 // M3: unquoted url value
29 mref("<meta http-equiv=refresh content=0;url=https://noquote.example/x>" as *u8, out)
30 ttl=ttl+1; pass=pass+grow("M3 unquoted url -> noquote.example/x\x00" as *u8, streq(out, "https://noquote.example/x" as *u8))
31 // M4: uppercase / mixed case
32 mref("<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0; URL=https://caps.example/y\">" as *u8, out)
33 ttl=ttl+1; pass=pass+grow("M4 uppercase META/REFRESH/URL -> caps.example/y\x00" as *u8, streq(out, "https://caps.example/y" as *u8))
34 // M5: Refresh response HEADER form
35 mref("HTTP/1.1 200 OK\r\nRefresh: 0; url=https://hdr.example/z\r\nContent-Type: text/html\r\n\r\n<html></html>" as *u8, out)
36 ttl=ttl+1; pass=pass+grow("M5 Refresh: header -> hdr.example/z\x00" as *u8, streq(out, "https://hdr.example/z" as *u8))
37 // M6: relative url -> DECLINED (absolute http(s) only; we don't chase relative scam hops blindly)
38 let r6: i64 = mref("<meta http-equiv=\"refresh\" content=\"0;url=/local/path\">" as *u8, out)
39 ttl=ttl+1; pass=pass+grow("M6 relative /local/path -> declined (0)\x00" as *u8, (r6 == 0) as i64)
40 // M7: a page with NO meta refresh -> nothing
41 let r7: i64 = mref("<html><body><h1>content</h1><p>no redirect here</p></body></html>" as *u8, out)
42 ttl=ttl+1; pass=pass+grow("M7 no meta refresh -> nothing (0)\x00" as *u8, (r7 == 0) as i64)
43 // M8: a meta that is NOT refresh (e.g. viewport) with a url elsewhere -> not falsely followed
44 let r8: i64 = mref("<meta name=\"viewport\" content=\"width=device-width\"><a href=\"https://x/y\">link</a>" as *u8, out)
45 ttl=ttl+1; pass=pass+grow("M8 viewport meta + <a href> -> not followed (0)\x00" as *u8, (r8 == 0) as i64)
46
47 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8)
48 if pass == ttl { gw("verdict=GREEN (meta-refresh/Refresh chains resolved to absolute content targets; relative/non-refresh declined)\n" as *u8); sys_exit(0); return 0 }
49 gw("verdict=RED\n" as *u8); sys_exit(1); return 1
50}