Resolve Open Proxy, XSS Vectors, and Implement API Rate Limiting in onchainsummer.xyz - #437
Open
Sahveli01 wants to merge 2 commits into
Open
Resolve Open Proxy, XSS Vectors, and Implement API Rate Limiting in onchainsummer.xyz#437Sahveli01 wants to merge 2 commits into
onchainsummer.xyz#437Sahveli01 wants to merge 2 commits into
Conversation
…`onchainsummer.xyz` ### Description This pull request addresses findings F-05, F-06, and F-11 from the workspace security audit targeting the `onchainsummer.xyz` reservoir API proxy. The route previously functioned as an open proxy exposing the deployment's API keys when unconfigured, allowed XSS payloads through improper content-type handling, and suffered from missing rate limits. These vectors have been comprehensively closed. ### Key Changes & Remediations #### 1. Open Proxy & Origin Validation (F-05) (`src/app/api/reservoir/[...slug]/route.ts`) * **Strict Origin Matching:** Removed the flawed Regex host parser that could be easily bypassed by domain manipulations. The logic now strictly extracts and matches origins using the WHATWG `URL` parser. * **Fail-Closed Configuration:** If `ALLOWED_API_DOMAINS` is not defined, the proxy now gracefully defaults to same-origin behavior instead of failing open to the entire internet. #### 2. XSS & Binary Corruption Mitigation (F-06) (`src/app/api/reservoir/[...slug]/route.ts`) * **Strict MIME Handling:** The proxy previously served all `image/*` upstream responses with a `text/html` header, effectively turning any upstream binary payload into a stored XSS vector on the local origin. It now correctly passes through upstream MIME types strictly checked against a safe `PASSTHROUGH_MEDIA_TYPES` allowlist while enforcing the `nosniff` header. * **Binary Integrity:** Switched `response.text()` resolution to `response.arrayBuffer()` to ensure binary image bodies are no longer corrupted by UTF-8 string conversions during transit. * **Error Masking:** Suppressed verbatim upstream error messages. Instead of returning raw upstream exception strings to the client, the proxy now securely logs details server-side and responds with a generic `502 Bad Gateway` to prevent intelligence leakage. #### 3. API Rate Limiting (F-11) (`src/utils/apiRateLimit.ts`) * **Abuse Protection:** Introduced an in-memory sliding-window rate limiter for the proxy bridge, capping requests to 120 per minute per client key. * **Memory Exhaustion Safeguard:** Capped the underlying tracking `Map` to 5,000 clients, safely deferring key pruning logic into an independent step that adheres strictly to ES5 non-mutative Map iteration constraints.
Collaborator
🟡 Heimdall Review Status
|
This update fixes multiple defects in the proxy API endpoint, including origin checks, content type handling, and error responses. It improves security by ensuring only allowed origins can access the proxy and correctly processes binary responses.
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.
Description
This pull request addresses findings F-05, F-06, and F-11 from the workspace security audit targeting the
onchainsummer.xyzreservoir API proxy. The route previously functioned as an open proxy exposing the deployment's API keys when unconfigured, allowed XSS payloads through improper content-type handling, and suffered from missing rate limits. These vectors have been comprehensively closed.Key Changes & Remediations
1. Open Proxy & Origin Validation (F-05) (
src/app/api/reservoir/[...slug]/route.ts)URLparser.ALLOWED_API_DOMAINSis not defined, the proxy now gracefully defaults to same-origin behavior instead of failing open to the entire internet.2. XSS & Binary Corruption Mitigation (F-06) (
src/app/api/reservoir/[...slug]/route.ts)image/*upstream responses with atext/htmlheader, effectively turning any upstream binary payload into a stored XSS vector on the local origin. It now correctly passes through upstream MIME types strictly checked against a safePASSTHROUGH_MEDIA_TYPESallowlist while enforcing thenosniffheader.response.text()resolution toresponse.arrayBuffer()to ensure binary image bodies are no longer corrupted by UTF-8 string conversions during transit.502 Bad Gatewayto prevent intelligence leakage.3. API Rate Limiting (F-11) (
src/utils/apiRateLimit.ts)Mapto 5,000 clients, safely deferring key pruning logic into an independent step that adheres strictly to ES5 non-mutative Map iteration constraints.