Repository navigation
fix(runtimeConfig): filter localhost URLs from external service config #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,12 +25,26 @@ declare global { | |||||
| // Dynamic lookup on purpose: `process.env[name]` is never inlined at build time. | ||||||
| const readEnv = (name: string): string | undefined => process.env[name] || undefined | ||||||
|
|
||||||
| // Localhost URLs in env files are format-valid placeholders (e.g. .env.test). | ||||||
| // Treat them as unset so consumers don't attempt real network calls to them. | ||||||
| const readExternalUrl = (name: string): string | undefined => { | ||||||
| const value = readEnv(name) | ||||||
| if (!value) return undefined | ||||||
| try { | ||||||
| const { hostname } = new URL(value) | ||||||
| if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1') return undefined | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: The WHATWG
Suggested change
Reply with |
||||||
| } catch { | ||||||
| return undefined | ||||||
| } | ||||||
| return value | ||||||
| } | ||||||
|
|
||||||
| export const readRuntimeConfigFromEnv = (): RuntimeConfig => ({ | ||||||
| serverUrl: readEnv('SERVER_URL'), | ||||||
| statusPageUrl: readEnv('STATUS_PAGE_URL'), | ||||||
| umamiUrl: readEnv('NEXT_PUBLIC_UMAMI_URL'), | ||||||
| statusPageUrl: readExternalUrl('STATUS_PAGE_URL'), | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: This does not silence the ServiceStatus heartbeat fetch described in the PR The PR says this stops Reply with |
||||||
| umamiUrl: readExternalUrl('NEXT_PUBLIC_UMAMI_URL'), | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CRITICAL:
Reply with |
||||||
| umamiSiteId: readEnv('NEXT_PUBLIC_UMAMI_SITE_ID'), | ||||||
| iconifyApi: readEnv('NEXT_PUBLIC_ICONIFY_API'), | ||||||
| iconifyApi: readExternalUrl('NEXT_PUBLIC_ICONIFY_API'), | ||||||
| sentryDsn: readEnv('SENTRY_DSN'), | ||||||
| sentryEnvironment: readEnv('SENTRY_ENVIRONMENT'), | ||||||
| }) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SUGGESTION: No regression test for the new localhost filtering
src/lib/runtimeConfig/index.test.tsalready coversreadRuntimeConfigFromEnvmapping, but nothing asserts the behavior this PR adds: alocalhost/127.0.0.1URL mapping toundefinedwhile a real URL passes through. A case such asvi.stubEnv('NEXT_PUBLIC_UMAMI_URL', 'http://localhost:3002')withexpect(readRuntimeConfigFromEnv().umamiUrl).toBeUndefined()would lock the filter in and matches the repo's regression-test convention for bug fixes.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.