Skip to content

fix: clear inherited DNS lookup for non-localhost URLs in redirect handling - #7426

Merged
sid-bruno merged 4 commits into
usebruno:mainfrom
chirag-bruno:fix/redirect-dns-resolution-localhost
Apr 3, 2026
Merged

fix: clear inherited DNS lookup for non-localhost URLs in redirect handling#7426
sid-bruno merged 4 commits into
usebruno:mainfrom
chirag-bruno:fix/redirect-dns-resolution-localhost

Conversation

@chirag-bruno

@chirag-bruno chirag-bruno commented Mar 10, 2026

Copy link
Copy Markdown
Collaborator

Description

JIRA

When redirecting from localhost to an external domain, the custom DNS lookup function (which always resolves to 127.0.0.1 or ::1) was being inherited via config spread. This caused external domains to incorrectly resolve to localhost, resulting in ECONNREFUSED errors.

The fix adds an else clause to the request interceptor that clears any inherited lookup function for non-localhost URLs, ensuring external domains use normal DNS resolution.

Fixes #7343

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • Bug Fixes

    • Custom DNS lookup behavior now applies only to localhost variants and is cleared for external domains, preventing unintended DNS handling for non-local hosts.
  • Tests

    • Added tests validating DNS lookup injection for localhost variants, clearing when targeting external hosts, and correct behavior across localhost redirects.

@coderabbitai

coderabbitai Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

â„đïļ Recent review info
⚙ïļ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9794baf1-41d4-4200-84ad-43ea8ec8fa5d

ðŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between 3661535 and 6a32316.

📒 Files selected for processing (2)
  • packages/bruno-electron/src/ipc/network/axios-instance.js
  • packages/bruno-electron/tests/network/axios-instance.spec.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/bruno-electron/src/ipc/network/axios-instance.js
  • packages/bruno-electron/tests/network/axios-instance.spec.js

Walkthrough

Removes any preexisting config.lookup for non-localhost requests in the axios request interceptor and adds tests verifying lookup is set for localhost variants and cleared for external hosts and redirect scenarios.

Changes

Cohort / File(s) Summary
Axios interceptor change
packages/bruno-electron/src/ipc/network/axios-instance.js
Adds an else branch in the request interceptor that deletes config.lookup when the request host is not localhost, 127.0.0.1, or ::1.
Unit tests
packages/bruno-electron/tests/network/axios-instance.spec.js
Adds Jest tests covering: lookup injection for localhost, 127.0.0.1, ::1, and *.localhost; absence of lookup for external domains; clearing inherited lookup when moving to external hosts; and replacing inherited lookup on localhost redirects.

Sequence Diagram(s)

(No sequence diagram generated.)

Estimated code review effort

ðŸŽŊ 3 (Moderate) | ⏱ïļ ~20 minutes

Suggested labels

size/M

Suggested reviewers

  • helloanoop
  • bijin-bruno
  • naman-bruno

Poem

🧭 Small gatekeeper at the DNS door,
localhost honoured, outsiders no more.
Lookups tidy, redirects sing true,
network threads mend, and tests nod too. 🎉

ðŸšĨ Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠ïļ Warning Docstring coverage is 50.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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: clearing inherited DNS lookup for non-localhost URLs in redirect scenarios, which directly addresses the issue.
Linked Issues check ✅ Passed The code changes fully implement the required fix: the else clause clears inherited lookup functions for non-localhost domains, enabling normal DNS resolution for external hosts as required by issue #7343.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to the DNS lookup redirect issue. The implementation fix and corresponding test suite are directly aligned with the stated objective and do not introduce unrelated modifications.

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

âœĻ Finishing Touches
🧊 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-electron/tests/network/axios-instance.spec.js`:
- Around line 39-43: The tests currently reach into axios internals by grabbing
axiosInstance.interceptors.request.handlers[0] and calling .fulfilled, which
couples tests to implementation; instead, refactor tests for makeAxiosInstance
to exercise the public request flow by installing a stub adapter on
axiosInstance (or using axios-mock-adapter) and sending a real request through
axiosInstance(), then assert that response.config.lookup (or the mutated config)
is set as expected. Replace references to requestInterceptor usage with a
request call like axiosInstance({ url: '/', adapter: stubAdapter }) and verify
response.config.lookup, keeping the assertions behavior-driven and avoiding
direct access to interceptors.request.handlers.

â„đïļ Review info
⚙ïļ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 72315f18-8112-4429-b951-fbab5e957f2c

ðŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between f123a2b and 886ca6b.

📒 Files selected for processing (2)
  • packages/bruno-electron/src/ipc/network/axios-instance.js
  • packages/bruno-electron/tests/network/axios-instance.spec.js

Comment thread packages/bruno-electron/tests/network/axios-instance.spec.js
lohit-bruno
lohit-bruno previously approved these changes Mar 10, 2026

@sanish-bruno sanish-bruno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PR Review

Found 1 issue(s): 0 major, 0 minor, 1 nit.

Summary

  • The 2-line fix is correct and minimal — delete config.lookup in the else branch of the request interceptor properly clears the inherited DNS lookup function for non-localhost URLs during redirects.
  • The redirect flow is sound: config spread at L347 inherits lookup, then instance(requestConfig) at L439 re-enters the request interceptor where the else clause now cleans it up.
  • Tests are well-structured using a stub adapter pattern that exercises the public request flow without poking at axios internals. Good coverage of localhost variants, external domains, and the redirect inheritance scenario.
  • delete on a non-existent property is a safe no-op, so first-time non-localhost requests are unaffected.

Comment thread packages/bruno-electron/tests/network/axios-instance.spec.js
cchirag added 3 commits April 2, 2026 11:58
â€Ķndling

When redirecting from localhost to an external domain, the custom DNS
lookup function (which always resolves to 127.0.0.1 or ::1) was being
inherited via config spread. This caused external domains to incorrectly
resolve to localhost, resulting in ECONNREFUSED errors.

The fix adds an else clause to the request interceptor that clears any
inherited lookup function for non-localhost URLs, ensuring external
domains use normal DNS resolution.

Fixes usebruno#7343
Replace direct access to axios interceptor internals with a behavior-driven
approach using a stub adapter. Tests now exercise the public request flow
by making actual requests through axiosInstance() and asserting on the
config that reaches the adapter.

This decouples tests from axios implementation details and makes them
more maintainable.
â€Ķredirect

Renamed test and added an inherited lookup function to properly simulate
a redirect scenario, verifying the interceptor replaces it with a fresh one.
sid-bruno
sid-bruno previously approved these changes Apr 3, 2026
@chirag-bruno
chirag-bruno dismissed sid-bruno’s stale review April 3, 2026 08:17

The merge-base changed after approval.

@sid-bruno
sid-bruno merged commit 233013d into usebruno:main Apr 3, 2026
14 of 15 checks passed
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authentication Flow changes redirect to 127.0.0.1

5 participants