code wiki / (root) / nx_api_edge.nx

nx_api_edge.nx

buildroot/runtime/nx_api_edge.nx

16999 B299 linesdepth 9pulls 33 transitivereach 4 importersview sourcekind tooltopic api
docsdependenciesstructsconstsfunctions

about

nx_api_edge.nx -- the REAL s-class hardening edge for the live agent-facing API (nx_tools_api on :18096, public as <domain>/api/tools + /mcp). WIRES the API-hardening capabilities that existed only as unwired island primitives + a hardcoded-secret DRAFT gateway (nx_api_gateway) into ONE real HTTP middleware that wraps ta_handle. NON-BREAKING by construction: it does NOT touch the cap-token execution auth (capt_verify still guards tools/call) nor block the open read-only catalog -- it ADDS, per request: * CORS deny-by-default (OPTIONS preflight -> 204; Access-Control-* only for allowlisted origins) * security headers on every response (X-Content-Type-Options, X-Frame-Options, Referrer-Policy, HSTS) * a REAL token-bucket rate limit (monotonic-clock refill; 429 problem+json over budget) = DoS guard * RFC 9457 application/problem+json for edge errors (429, 413) This is the composition the apistack gates proved in isolation, now on the LIVE request path. license_tier: ORIGINAL genealogy_id: international-research-sources/ietf/rfc_6454_cors + rfc_9457_problem

dependencies 2 imports · 2 importers

nx_syscalls.nx nx_tools_api.nx nx_api_edge.nx nx_mcp_edge_boundary_gate.nx nx_tools_api_serve.nx

imports: nx_syscalls.nxnx_tools_api.nx

imported by: nx_mcp_edge_boundary_gate.nxnx_tools_api_serve.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main edge_w sys_write ta_slen sys_mmap nxa_die sys_write ↻ sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ edge_row edge_w ↻ nx_api_edge_handle edge_problem_too_large sys_mmap ↻ ta_cat ta_catn sys_mmap ↻ ta_reqline ta_streq_n edge_find_header edge_header_lower edge_origin_allowed edge_find_header ↻ ta_streq_n ↻ ta_cat ↻ ta_catn ↻ edge_cpy ta_cat ↻ edge_cpy ↻ edge_tb_allow

structs

none

consts

14const EDGE_MAGIC_1000000000: i64 = 1000000000
15const EDGE_MAGIC_1000000: i64 = 1000000
17const EDGE_RESP_CAP: i64 = 1048576
26const EDGE_REQ_MAX: i64 = EDGE_RESP_CAP
30const TB_CAP_MILLI: i64 = 300000 // 300 tokens * 1000
31const TB_RATE_PER_S: i64 = 30 // sustained refill tokens/second

functions

35func edge_now_ns() -> i64
called by 1: edge_tb_allow calls 1: sys_mmap
42func edge_tb_allow() -> i64
called by 1: nx_api_edge_handle calls 1: edge_now_ns
56func edge_cpy(dst: *u8, doff: i64, src: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { dst[doff + i] = src[i]; i = i + 1 } return doff + n }
62func edge_header_lower(c: i64) -> i64
called by 1: edge_find_header
66func edge_find_header(req: *u8, req_n: i64, name: *u8, name_len: i64, vo: *i64) -> i64
99func edge_origin_allowed(req: *u8, req_n: i64, vo: *i64) -> i64
110func edge_sec_headers(out: *u8, o: i64) -> i64
119func edge_inject(resp: *u8, resp_len: i64, out: *u8, req: *u8, req_n: i64) -> i64
139func edge_problem(out: *u8, status_line: *u8, ptype: *u8, title: *u8, status: i64, detail: *u8) -> i64
156func edge_problem_too_large(out: *u8, declared: i64, limit: i64) -> i64
164func edge_problem_short_body(out: *u8, got: i64, need: i64) -> i64
173func nx_api_edge_handle(req: *u8, req_n: i64, out: *u8) -> i64
238func edge_w(s: *u8) -> i64 { sys_write(1, s, ta_slen(s)); return 0 }
239func edge_row(name: *u8, ok: i64) -> i64 { if ok == 1 { edge_w(" PASS " as *u8) } else { edge_w(" FAIL " as *u8) } edge_w(name); edge_w("\n" as *u8); return ok }
241func edge_has(hay: *u8, hn: i64, needle: *u8) -> i64
254func main() -> i64