Add server-side proxy for Scalar API client to bypass CORS#4050
Conversation
🦋 Changeset detectedLatest commit: 4f8503f The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
There was a problem hiding this comment.
Pull request overview
This PR adds a server-side proxy for the Scalar API client to bypass CORS restrictions when testing API endpoints. The proxy is opt-in via the x-enable-proxy extension in OpenAPI specs and includes SSRF protection measures.
Changes:
- Added
x-enable-proxycustom extension to OpenAPI spec-level properties with type validation - Implemented proxy route handler at
/~scalar/proxywith SSRF protection (private IP blocking, DNS resolution checks, redirect validation) - Integrated proxy URL configuration into Scalar API button component based on
x-enable-proxyflag
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/openapi-parser/src/types.ts | Added x-enable-proxy boolean property to OpenAPICustomSpecProperties interface |
| packages/react-openapi/src/resolveOpenAPIOperation.ts | Extracted x-enable-proxy from schema with boolean type validation |
| packages/react-openapi/src/resolveOpenAPIOperation.test.ts | Added comprehensive test coverage for x-enable-proxy extraction logic |
| packages/react-openapi/src/ScalarApiButton.tsx | Added withProxy prop and configured Scalar's proxyUrl when enabled |
| packages/react-openapi/src/OpenAPICodeSample.tsx | Passed x-enable-proxy value to ScalarApiButton component |
| packages/gitbook/src/routes/openapi-proxy.ts | Implemented proxy handler with SSRF protection, header forwarding, and redirect validation |
| packages/gitbook/src/routes/openapi-proxy.test.ts | Added extensive test coverage for proxy functionality and security checks |
| packages/gitbook/src/app/~scalar/proxy/route.ts | Created Next.js route handlers for all HTTP methods |
| .changeset/bright-streets-hammer.md | Added changeset documenting the new feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
953142a to
0d4440e
Compare
Route API requests from Scalar's "Try It" button through a server-side proxy at /~scalar/proxy, avoiding browser CORS restrictions. - Add x-enable-proxy spec-level extension to opt-in per OpenAPI spec - Extract and pass x-enable-proxy through the OpenAPI data pipeline - Configure Scalar's proxyUrl when x-enable-proxy is true - Implement proxy route handler with SSRF protection (private IP blocking, DNS resolution checks, redirect validation) - Strip upstream CORS headers and apply permissive ones - Handle X-Scalar-Cookie and X-Scalar-User-Agent forwarding
00ea1e3 to
4f8503f
Compare
Route API requests from Scalar's "Try It" button through a server-side proxy at
/~scalar/proxy, avoiding browser CORS restrictions.x-enable-proxyspec-level extension to opt-in per OpenAPI specx-enable-proxythrough the OpenAPI data pipelinex-enable-proxyis trueX-Scalar-CookieandX-Scalar-User-AgentforwardingMainly inspired by: https://github.com/scalar/scalar/tree/main/projects/proxy-scalar-com