fix: crash and RFC compliance edge cases - #121
Merged
Merged
Conversation
Add an edge-case suite covering malformed percent-encoding, directories without index.html, if-modified-since handling, proxy upstream failure mid-response, and CORS preflight on the proxy path. Tests asserting the desired behavior fail until the corresponding source fixes land. Extend makeRequest to accept a custom HTTP method. 🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
decodeURIComponent throws URIError on sequences like /%zz, which escaped the request handler and killed the server. Catch the error and reject the request. 🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
A trailing-slash request to a directory without index.html rewrote the target inside a try/catch and then stat'ed and read it outside, crashing the server with an uncaught ENOENT. Validate the rewritten target before serving. 🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
RFC 9110 requires honoring If-Modified-Since on its own; the previous condition only returned 304 when if-none-match was also present. Skip unparseable dates instead of comparing them. 🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
The proxy piped the upstream response without an error handler, so an upstream that broke mid-body left the client hanging on an open connection forever. Destroy the client socket when the upstream response errors. 🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
OPTIONS requests were forwarded to the upstream; answer them directly with 204 so preflights succeed even when the upstream rejects or cannot handle them. Also fix the edge-case test harness: resolve the request path from an env var (argv is unreliable under node --eval), import the module with a cwd-relative path, run the child with --use-system-ca, and accept the 403 that malformed percent-encoding now returns. 🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes all ten crash, hang, RFC-compliance, proxy, and response-quality bugs found in the review. Each fix is a separate commit; the edge-case test suite lands first.
/%zzthrewURIError; now rejected safely. (904a911)index.htmlcrashed the server: now serves 404. (f6209f7)If-Modified-Sincealone never produced 304: now honored per RFC 9110. (f407c96)9db8e12)98305ef)b3f8b15)1f0ab67)28183b9)X-Forwarded-Forwas overwritten: client address is appended. (330e42d)e998c05)Verification
pnpm lintpasses.node server.jsprocess occupying port 8080.🤖 Generated with OpenCode (Smart-router)