Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR introduces a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
localhost was not loading before the recent fix on dev because the env vars weren't pulled correctly. The recent fix is not enough because we have no guarantee that process will exist in the sdk environment. So we solve it without env vars. We explicitly check for localhost (simulating dev env), and allow the sdk to configure the feature. It is a default parameter so shouldn't be a breaking change.
b873f17 to
fb0ca7d
Compare
Greptile SummaryReplaced environment variable checks (
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as Client App
participant Interface as StackClientInterface
participant Security as shouldAllowInsecureRequest()
participant OAuth as OAuth Library
Client->>Interface: Initialize with dangerouslyAllowInsecureHttp option
Note over Client,Interface: Option defaults to false for security
Interface->>Interface: Build tokenEndpoint URL
Note over Interface: tokenEndpoint = getApiUrl() + '/auth/oauth/token'
Interface->>Security: shouldAllowInsecureRequest(tokenEndpoint, option)
alt tokenEndpoint matches localhost pattern
Security->>Security: Check regex: /^http:\/\/(localhost|127\.0\.0\.1)(:|\/|$)/
Security-->>Interface: return true (localhost always allowed)
else non-localhost HTTP with flag enabled
Security->>Security: Check dangerouslyAllowInsecureHttp === true
Security->>Security: Check endpoint.startsWith('http://')
Security-->>Interface: return true (explicitly opted in)
else non-localhost HTTP without flag
Security-->>Interface: return false (blocked for security)
else HTTPS endpoint
Security-->>Interface: return false (no flag needed for HTTPS)
end
alt allowInsecure === true
Interface->>OAuth: Call with {[allowInsecureRequests]: true}
else allowInsecure === false
Interface->>OAuth: Call without insecure flag
end
OAuth-->>Interface: Response
Interface-->>Client: Complete request
|
There was a problem hiding this comment.
Pull request overview
This PR fixes the localhost loading issue in non-Next.js environments by removing the dependency on process.env.NODE_ENV checks for HTTP security validation. Instead, it introduces a configurable dangerouslyAllowInsecureHttp option and implements localhost detection as a heuristic for development environments.
Changes:
- Added
dangerouslyAllowInsecureHttpconfiguration option to SDK with appropriate warnings - Replaced
process.env.NODE_ENVchecks with a dedicatedshouldAllowInsecureRequest()utility function - Implemented localhost detection using regex to automatically allow HTTP for local development
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/template/src/lib/stack-app/apps/interfaces/client-app.ts | Added dangerouslyAllowInsecureHttp option to the SDK configuration interface |
| packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts | Passed the new option through to the StackClientInterface with a default value of false |
| packages/stack-shared/src/utils/http-security.tsx | Created new utility function to determine if insecure HTTP requests should be allowed based on localhost detection and configuration |
| packages/stack-shared/src/utils/http-security.test.ts | Added comprehensive test coverage for the new security utility function |
| packages/stack-shared/src/interface/client-interface.ts | Replaced process.env checks with the new shouldAllowInsecureRequest() function in OAuth token endpoints |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
N2D4
left a comment
There was a problem hiding this comment.
this is quite overengineered. there is nothing dangerous about allowing insecure HTTP connections here as the tokenEndpoint is under our own control
| /** | ||
| * Allows HTTP (non-HTTPS) requests to non-localhost servers. | ||
| * WARNING: Only use this for testing environments. Never enable in production. | ||
| * @default false | ||
| */ | ||
| dangerouslyAllowInsecureHttp?: boolean, |
There was a problem hiding this comment.
it's not that dangerous. it would still require us to have an HTTP base url... which we'd never do in production
keep in mind, tokenEndpoint is controlled by us, not an attacker
| /** | |
| * Allows HTTP (non-HTTPS) requests to non-localhost servers. | |
| * WARNING: Only use this for testing environments. Never enable in production. | |
| * @default false | |
| */ | |
| dangerouslyAllowInsecureHttp?: boolean, |
Summary of Changes
The recent push to main fixed the issue with localhost not loading, but only for next.js environments. We don't have a guarantee that the sdk will be loaded in an environment with access to
process. So, we move away from using environment variables to check for test/dev environments. We allow it to be configured via the sdk and also check for localhost explicitly (sort of a heuristic for development env).Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.