Skip to content

fix: localhost not loading#1122

Closed
nams1570 wants to merge 3 commits intodevfrom
fix-oauth-env-pull
Closed

fix: localhost not loading#1122
nams1570 wants to merge 3 commits intodevfrom
fix-oauth-env-pull

Conversation

@nams1570
Copy link
Collaborator

@nams1570 nams1570 commented Jan 19, 2026

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

    • Added optional configuration option to enable insecure HTTP requests for testing and development purposes (defaults to disabled for production safety).
  • Tests

    • Added comprehensive test coverage for HTTP request security validation across localhost and non-localhost scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Jan 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
stack-backend Error Error Jan 20, 2026 0:14am
stack-dashboard Ready Ready Preview, Comment Jan 20, 2026 0:14am
stack-demo Ready Ready Preview, Comment Jan 20, 2026 0:14am
stack-docs Error Error Jan 20, 2026 0:14am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new dangerouslyAllowInsecureHttp configuration option to control insecure HTTP request handling. It centralizes localhost detection and HTTP allowance logic into a reusable shouldAllowInsecureRequest utility that always permits localhost HTTP but requires explicit opt-in for non-localhost HTTP. The option is threaded through client initialization layers.

Changes

Cohort / File(s) Summary
HTTP Security Utility
packages/stack-shared/src/utils/http-security.tsx
New utility function shouldAllowInsecureRequest that determines if HTTP requests should be allowed based on endpoint and opt-in flag; always allows localhost HTTP, conditionally allows non-localhost HTTP.
HTTP Security Tests
packages/stack-shared/src/utils/http-security.test.ts
Comprehensive test suite covering localhost detection, HTTPS handling, opt-in flag behavior, and edge cases for the new utility.
Client Interface
packages/stack-shared/src/interface/client-interface.ts
Replaces ad-hoc environment-based insecure HTTP logic with calls to shouldAllowInsecureRequest; adds dangerouslyAllowInsecureHttp option to ClientInterfaceOptions.
Client App Interface & Implementation
packages/template/src/lib/stack-app/apps/interfaces/client-app.ts, packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts
Introduces dangerouslyAllowInsecureHttp option to public constructor options and threads it through to client initialization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

  • fix sign in bug on dev #1119 — Both PRs modify insecure HTTP allowance logic in client-interface.ts, centralizing how allowInsecure is computed for token exchange and OAuth callbacks.

Suggested reviewers

  • N2D4

Poem

🐰 A flag to test with HTTP's might,
Localhost flows without a fight,
But venture forth to distant lands?
Only when danger's in your hands!
Centralized logic, clean and tight. 🔐

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: localhost not loading' is vague and doesn't clearly convey the main change. The PR actually introduces a new configuration option for handling insecure HTTP requests and centralizes HTTP security logic, rather than simply 'fixing' localhost loading. Consider a more specific title like 'feat: add dangerouslyAllowInsecureHttp option for HTTP security configuration' or 'refactor: centralize HTTP security checks and improve localhost handling' that better captures the substantive changes being made.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
@nams1570 nams1570 marked this pull request as ready for review January 19, 2026 23:21
Copilot AI review requested due to automatic review settings January 19, 2026 23:21
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 19, 2026

Greptile Summary

Replaced environment variable checks (process.env.NODE_ENV) with explicit configuration option and localhost detection to fix SDK loading issues in non-Node.js environments.

  • Introduced shouldAllowInsecureRequest() utility that detects localhost URLs via regex and accepts an explicit opt-in flag
  • Added dangerouslyAllowInsecureHttp option to client interface for test environments
  • Removed dependency on process.env which was unavailable in browser environments
  • Comprehensive test coverage for localhost detection and edge cases

Confidence Score: 4/5

  • This PR is safe to merge with low risk - it fixes a real issue and maintains security defaults
  • The changes properly address the environment variable issue and maintain security by defaulting to secure behavior. The one minor improvement suggested (IPv6 localhost support) is not critical for the current use case since tokenEndpoint is always constructed with a path.
  • No files require special attention - all changes are well-tested and straightforward

Important Files Changed

Filename Overview
packages/stack-shared/src/utils/http-security.tsx Added utility function to determine if insecure HTTP requests should be allowed, with localhost detection logic and opt-in flag support
packages/stack-shared/src/interface/client-interface.ts Replaced process.env checks with the new shouldAllowInsecureRequest utility function and added dangerouslyAllowInsecureHttp option

Sequence Diagram

sequenceDiagram
    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
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@nams1570 nams1570 requested a review from BilalG1 January 19, 2026 23:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 dangerouslyAllowInsecureHttp configuration option to SDK with appropriate warnings
  • Replaced process.env.NODE_ENV checks with a dedicated shouldAllowInsecureRequest() 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.

Copy link
Contributor

@N2D4 N2D4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is quite overengineered. there is nothing dangerous about allowing insecure HTTP connections here as the tokenEndpoint is under our own control

Comment on lines +42 to +47
/**
* Allows HTTP (non-HTTPS) requests to non-localhost servers.
* WARNING: Only use this for testing environments. Never enable in production.
* @default false
*/
dangerouslyAllowInsecureHttp?: boolean,
Copy link
Contributor

@N2D4 N2D4 Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
/**
* Allows HTTP (non-HTTPS) requests to non-localhost servers.
* WARNING: Only use this for testing environments. Never enable in production.
* @default false
*/
dangerouslyAllowInsecureHttp?: boolean,

@N2D4 N2D4 closed this in 52668d7 Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants