Fix JS files served as JSON envelope (checkout/Stripe/auth all broken) #53
Reference in New Issue
Block a user
Delete Branch "fix/checkout-auth-reveal"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Root Cause
All compiled JS files (
/js/*.js) were being served as the raw{"el_http_response":1,...}JSON wrapper instead of actual JavaScript. Every script on the page silently failed — auth, Stripe, and the free-tier flow were completely dead.Why:
http_parse_envelope()calledjson_parse()on the full ~47KB response envelope (JS body JSON-encoded inside). The parser fails on large/complex content, sois_envelope=0and the raw JSON envelope was forwarded to the browser as the response body.Secondary:
http_detect_content_type()mis-identifies obfuscated JS asapplication/json(content starts with\n[javascript-obfuscator-cli]...— the[triggers the JSON array heuristic). WithX-Content-Type-Options: nosniff, this blocks script execution regardless.Fix
runtime/el_runtime.cReplace
json_parse-of-full-envelope with a direct field scanner:"status"— strtol scan"headers"— brace-depth scan extracts the object literal, thenjson_parseonly that small substring (headers are always simple k/v pairs < 1KB)"body"—jp_parse_string_rawdirectly on the JSON string field, no intermediate allocation, no size limitsrc/main.el/js/*route now callshttp_response(200, js_headers_json(), content)with explicitContent-Type: application/javascripthandle_requestalready passes through pre-wrapped envelopes, so security headers are includedResult
JS files served correctly. The fixes from PR #51 (free-success + Stripe auto-init) take effect automatically.
http_parse_envelope() called json_parse() on the entire response envelope (~47KB when body is obfuscated JS). The parser failed on large/complex content, so is_envelope=0 and the raw JSON was sent — browsers got {"el_http_response":1,...} instead of executable JavaScript, silently breaking all client-side code. Fix: replace json_parse-of-full-envelope with a direct field scanner: - "status" extracted via strtol - "headers" object extracted via brace-depth scan, then json_parse only that small substring (always safe — headers are simple k/v string pairs < 1KB) - "body" string extracted via jp_parse_string_raw — no intermediate allocation Also: /js/* route now returns http_response(200, js_headers_json(), content) with explicit Content-Type: application/javascript so the browser doesn't apply the json-heuristic (obfuscated JS starting with '[' was detected as JSON, which with X-Content-Type-Options: nosniff blocks script execution).