code wiki / (root) / nx_path_canonicalize.nx

nx_path_canonicalize.nx

buildroot/runtime/nx_path_canonicalize.nx

6946 B191 linesdepth 0pulls 0 transitivereach 10 importersview sourcekind librarytopic path
docsdependenciesstructsconstsfunctions

about

nx_path_canonicalize.nx -- structural CWE-22 path-traversal prevention. Named by nx_bug_tape_intelligence.sh F1 rule as rank-5 next ship- order. Closes the path-traversal class STRUCTURALLY: caller provides a base directory + a user-supplied relative path; this primitive returns either NXP_OK with the canonical path, or one of five sealed-enum rejection verdicts. No "partial" path return, no silent fixup, no late escape. The CWE-22 attack shape: user submits `../../../etc/passwd` (or URL-encoded equivalent), web framework joins it with base + opens the resulting path, leaking outside the intended directory. Substrate's structural prevention: 1. Reject ANY `..` segment outright (no "join + normalize") 2. Reject leading `/` (caller's base is the only absolute path) 3. Reject NUL bytes (truncation attacks) 4. Reject backslash on POSIX targets (no Windows-path confusion) 5. Reject empty path (no implicit index) 6. Reject paths > caller's max_len (resource bound) Sealed-enum verdict: NXP_OK validated path written to out_buf NXP_TRAVERSAL contains `..` segment or leading `/` NXP_NUL contains NUL byte NXP_BACKSLASH contains backslash (POSIX target) NXP_EMPTY zero-length input NXP_TOO_LONG exceeds max_out NXP_BAD_ARG null pointers / negative sizes Per cardinal feedback-defensive-at-boundaries-trusting-internally: canonicalize ONCE at the user-input boundary; trust the canonical path internally. Per cardinal user-owns-every-bit: caller provides base + max_len + out_buf. Substrate never reads/writes filesystem; this is a pure validator + byte-copier. nx_capability_claims: needs: [sealed_enum, byte_ops]

dependencies 0 imports · 4 importers

nx_path_canonicalize.nx nx_audit_server_routed.nx nx_nishipages_serve.nx nx_pages_static.nx nx_path_canonicalize_test.nx

imports: none

imported by: nx_audit_server_routed.nxnx_nishipages_serve.nxnx_pages_static.nxnx_path_canonicalize_test.nx

structs

none

consts

52const NXP_OK: i64 = 0
53const NXP_TRAVERSAL: i64 = 1
54const NXP_NUL: i64 = 2
55const NXP_BACKSLASH: i64 = 3
56const NXP_EMPTY: i64 = 4
57const NXP_TOO_LONG: i64 = 5
58const NXP_BAD_ARG: i64 = 6
59const NXP_VERDICT_N: i64 = 7

functions

61func nxp_verdict_is_valid(v: i64) -> i64
called by 1: main
67func nxp_verdict_name(v: i64) -> *u8
called by 1: main
88func nxp_is_dotdot_segment(src: *u8, i: i64, n: i64) -> i64
113func nx_path_canonicalize(src: *u8, src_n: i64,
163func nx_path_join(base: *u8, base_n: i64,