Skip to content

feat: honor HTTP_PROXY/HTTPS_PROXY env vars in loggedFetch#261

Closed
rafa-thayto wants to merge 2 commits intomainfrom
feat/fetch-proxy-env
Closed

feat: honor HTTP_PROXY/HTTPS_PROXY env vars in loggedFetch#261
rafa-thayto wants to merge 2 commits intomainfrom
feat/fetch-proxy-env

Conversation

@rafa-thayto
Copy link
Copy Markdown
Contributor

Summary

  • Bun's fetch() does not read HTTP_PROXY/HTTPS_PROXY env vars, so traffic inspectors (mitmproxy, Charles, Proxyman) couldn't intercept the CLI's outbound requests.
  • loggedFetch now resolves a proxy from curl-style env vars (HTTP_PROXY, HTTPS_PROXY, NO_PROXY — uppercase or lowercase) and passes it through Bun's per-request proxy option.
  • Localhost (localhost, 127.0.0.1, ::1) is always skipped so the OAuth callback listener is never routed through an external proxy.
  • With --verbose, the chosen proxy is logged alongside the request.

Test plan

  • HTTPS_PROXY=http://localhost:8080 clerk apps list --verbose shows routing via proxy http://localhost:8080 and the request appears in mitmproxy.
  • NO_PROXY=api.clerk.com HTTPS_PROXY=http://localhost:8080 clerk apps list --verbose does NOT route through the proxy.
  • OAuth flow (clerk auth login) is unaffected when HTTPS_PROXY is set — the localhost callback skips the proxy.
  • Lowercase variants (https_proxy, no_proxy) are also honored.

@rafa-thayto
Copy link
Copy Markdown
Contributor Author

!snapshot

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 22c6d6b3-93ba-48fd-a7c6-fc50fbb337d7

📥 Commits

Reviewing files that changed from the base of the PR and between 7f13c91 and 3dae5b7.

📒 Files selected for processing (2)
  • .changeset/fetch-proxy-env.md
  • packages/cli-core/src/lib/fetch.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fetch-proxy-env.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/cli-core/src/lib/fetch.ts

📝 Walkthrough

Walkthrough

Adds handling of proxy environment variables for outbound HTTP requests. The fetch wrapper resolves a per-request proxy from curl-style env vars (HTTP_PROXY/HTTPS_PROXY/NO_PROXY, case-insensitive), skips proxying localhost (to avoid the OAuth callback), passes the proxy to Bun's per-request proxy option, and logs the chosen proxy when --verbose. Implements internal helpers: resolveProxy, case-insensitive env lookup, NO_PROXY matching, and redactProxy for safe logging. No exported/public signatures were changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main feature: making loggedFetch honor HTTP_PROXY/HTTPS_PROXY environment variables.
Description check ✅ Passed The description is directly related to the changeset, providing context about the problem solved, implementation approach, and test plan for the proxy feature.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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


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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Snapshot published

npm install -g clerk@1.1.2-snapshot.f158c47
Package Version
clerk 1.1.2-snapshot.f158c47

Published from f158c47

@rafa-thayto rafa-thayto force-pushed the feat/fetch-proxy-env branch from f158c47 to 5800ec9 Compare May 6, 2026 18:45
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 6, 2026

🦋 Changeset detected

Latest commit: 3dae5b7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
clerk Patch

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli-core/src/lib/fetch.ts`:
- Around line 21-23: The verbose proxy log currently prints the full proxy URL
(via the local variable proxy) which may contain userinfo; update the logging in
the fetch flow (near resolveProxy, fetchInit and the log.debug using tag) to
redact credentials before logging by parsing the proxy string as a URL, clearing
username/password (or reconstructing protocol://host[:port]) and logging that
safe representation instead of the raw proxy; leave fetchInit unchanged and only
modify the value passed to log.debug so credentials are never emitted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aeee4b66-78a4-4f50-9e8b-a58389ef50ae

📥 Commits

Reviewing files that changed from the base of the PR and between f158c47 and 5800ec9.

📒 Files selected for processing (2)
  • .changeset/fetch-proxy-env.md
  • packages/cli-core/src/lib/fetch.ts

Comment thread packages/cli-core/src/lib/fetch.ts Outdated
Bun's fetch() does not auto-read these env vars, so tools like mitmproxy
and Charles couldn't intercept CLI traffic. Resolve a proxy per request
from curl-style env vars (uppercase or lowercase) and pass it through
Bun's `proxy` option. Always skip localhost so the OAuth callback
listener is never proxied. Log the chosen proxy under --verbose.
Proxy env vars can include inline credentials (e.g. http://user:pass@proxy:8080).
Strip userinfo before passing the URL to log.debug so credentials are never
emitted in --verbose output or captured in CI logs.
@rafa-thayto rafa-thayto force-pushed the feat/fetch-proxy-env branch from 7f13c91 to 3dae5b7 Compare May 7, 2026 12:12
@rafa-thayto rafa-thayto closed this May 7, 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.

1 participant