Skip to content

RQ-2425: verify upstream TLS by default (+ live toggle, clear cert errors)#108

Merged
dinex-dev merged 4 commits into
masterfrom
fix/RQ-2425-tls-verify-by-default
Jun 22, 2026
Merged

RQ-2425: verify upstream TLS by default (+ live toggle, clear cert errors)#108
dinex-dev merged 4 commits into
masterfrom
fix/RQ-2425-tls-verify-by-default

Conversation

@dinex-dev

@dinex-dev dinex-dev commented Jun 22, 2026

Copy link
Copy Markdown
Member

Security fix for RQ-2425 (Critical). Part of a 3-repo change (proxy + desktop-app + interceptor web app) — should merge together.

What

  • Replace the hardcoded rejectUnauthorized = false with !proxyConfig.allowInsecureCertsverify upstream TLS by default.
  • Add setAllowInsecureCerts() live setter on RQProxy/ProxyMiddlewareManager so the desktop toggle applies to the running proxy without a restart.
  • On upstream cert rejection, serve a clear SSL error page (CERT_HAS_EXPIREDERR_CERT_DATE_INVALID, self-signed→ERR_CERT_AUTHORITY_INVALID, …) instead of a misleading ERR_NAME_NOT_RESOLVED; fix the DNS-unreachable check to use a clean hostname.

Verified

End-to-end through the running proxy: bad-cert hosts (expired/self-signed) fail with default-on verification (502) and load when the toggle is on; valid certs unaffected; toggle flips live with no restart.

⚠️ Draft — pending review. Pairs with the desktop-app + interceptor PRs.

Summary by CodeRabbit

  • New Features

    • Added runtime control to disable upstream SSL/TLS certificate verification for compatibility with self-signed or internal certificates.
    • Introduced dedicated error pages for certificate validation failures with diagnostic tokens.
  • Bug Fixes

    • Improved error handling to properly distinguish between certificate failures and unreachable-address errors.

dinex-dev and others added 3 commits June 18, 2026 11:43
The proxy hardcoded `rejectUnauthorized = false` on every outbound request,
silently accepting any (expired/self-signed/wrong-host/attacker) certificate
from origin servers — letting a network attacker MITM all proxied HTTPS traffic
with no signal to the user.

Verify upstream certificates by default and only skip when the user explicitly
opts in via the new `ProxyConfig.allowInsecureCerts` flag (for self-signed /
internal upstreams). Defaults to secure (verify) when unset.

Follow-up (desktop app): expose this as a user setting / per-host cert exception.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add setAllowInsecureCerts() on RQProxy + ProxyMiddlewareManager. Because the
per-request handler reads proxyConfig.allowInsecureCerts, mutating it via this
setter applies the new TLS-verification policy on the next request — no proxy
restart and no app restart. Lets the desktop toggle take effect immediately.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
When "Allow insecure SSL in proxy interceptor" is OFF (default) and an origin
presents an untrusted/expired/self-signed cert, the proxy used to serve an
ERR_NAME_NOT_RESOLVED page — misleading, since the host resolves fine.

- Detect TLS cert verification errors (isCertificateError) and serve a dedicated
  page that names the cause (e.g. CERT_HAS_EXPIRED -> ERR_CERT_DATE_INVALID) and
  tells the user they can enable the insecure-SSL toggle if they trust the host.
- Fix the DNS-unreachable check to use a clean hostname (headers.host minus port)
  instead of the full request URL, so dns.lookup() no longer reports every
  upstream error as ENOTFOUND.
- Rebuild dist.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@dinex-dev, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 29 minutes and 3 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1eeea7b2-9039-4db2-a773-2f674697bd64

📥 Commits

Reviewing files that changed from the base of the PR and between 3283add and 51d3229.

⛔ Files ignored due to path filters (4)
  • dist/components/proxy-middleware/helpers/handleUnreachableAddress.js is excluded by !**/dist/**
  • dist/components/proxy-middleware/index.js is excluded by !**/dist/**
  • dist/rq-proxy.d.ts is excluded by !**/dist/**
  • dist/rq-proxy.js is excluded by !**/dist/**
📒 Files selected for processing (3)
  • src/components/proxy-middleware/helpers/handleUnreachableAddress.js
  • src/components/proxy-middleware/index.js
  • src/rq-proxy.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/RQ-2425-tls-verify-by-default

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@requestly/requestly-proxy@108

commit: 51d3229

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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 `@src/components/proxy-middleware/helpers/handleUnreachableAddress.js`:
- Line 122: The variables host and code are being directly embedded into HTML
markup without escaping, which creates a reflected XSS vulnerability where
malicious input could execute in the error page. In the template string around
line 122, use an HTML escaping function or utility to sanitize both the host and
code variables before inserting them into the HTML content. This ensures any
special HTML characters in these request-derived values are properly encoded as
HTML entities, preventing script or markup injection attacks.

In `@src/components/proxy-middleware/index.js`:
- Line 214: The hostname extraction on line 214 uses a naive split(":")[0]
approach that fails to properly parse IPv6 addresses, causing them to be
misparsed and potentially misclassified as DNS errors. Replace this splitting
logic with a robust host parsing method that correctly handles both IPv4
addresses with optional ports (e.g., "example.com:3000") and IPv6 addresses in
bracket notation (e.g., "[::1]:3000"). Consider using Node's URL class or a
dedicated host-parsing library to extract the hostname from the
ctx.clientToProxyRequest?.headers?.host value.

In `@src/rq-proxy.ts`:
- Around line 74-77: The setAllowInsecureCerts method in the RQProxy class does
not persist the toggle value if proxyMiddlewareManager is not yet initialized,
causing early toggles to be lost. Add a property to the RQProxy class to store
the insecure certs boolean value. Update the setAllowInsecureCerts method to
store the value on the RQProxy instance in addition to calling the middleware
manager's method. Then, when proxyMiddlewareManager is created during
initialization, replay the stored toggle value by calling its
setAllowInsecureCerts method with the persisted value to ensure the setting is
applied regardless of timing.
🪄 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: 465a8e9c-5b04-4335-ac8c-15342a27821b

📥 Commits

Reviewing files that changed from the base of the PR and between cec7e29 and 3283add.

⛔ Files ignored due to path filters (7)
  • dist/components/proxy-middleware/helpers/handleUnreachableAddress.d.ts is excluded by !**/dist/**
  • dist/components/proxy-middleware/helpers/handleUnreachableAddress.js is excluded by !**/dist/**
  • dist/components/proxy-middleware/index.d.ts is excluded by !**/dist/**
  • dist/components/proxy-middleware/index.js is excluded by !**/dist/**
  • dist/rq-proxy.d.ts is excluded by !**/dist/**
  • dist/rq-proxy.js is excluded by !**/dist/**
  • dist/types/index.d.ts is excluded by !**/dist/**
📒 Files selected for processing (4)
  • src/components/proxy-middleware/helpers/handleUnreachableAddress.js
  • src/components/proxy-middleware/index.js
  • src/rq-proxy.ts
  • src/types/index.ts

Comment thread src/components/proxy-middleware/helpers/handleUnreachableAddress.js Outdated
Comment thread src/components/proxy-middleware/index.js Outdated
Comment thread src/rq-proxy.ts
- handleUnreachableAddress.js: HTML-escape host/code before embedding into the
  cert-error and unreachable error pages (prevents reflected markup/script
  injection via a crafted request URL/host header).
- index.js: parse the upstream hostname via URL() (strip IPv6 brackets/port)
  instead of split(":")[0], so IPv6 hosts aren't misclassified as
  ERR_NAME_NOT_RESOLVED.
- rq-proxy.ts: remember allowInsecureCerts on RQProxy and replay it once the
  middleware manager is created, so a toggle set before init isn't lost.

Rebuilt dist. Verified: malicious host is escaped in the error page; IPv6
host parsing (host:port, [::1]:443, [2001:db8::1]) resolves correctly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dinex-dev dinex-dev marked this pull request as ready for review June 22, 2026 05:51
Comment thread src/components/proxy-middleware/helpers/handleUnreachableAddress.js
@dinex-dev dinex-dev merged commit 5d3cdb0 into master Jun 22, 2026
8 checks passed
@dinex-dev dinex-dev deleted the fix/RQ-2425-tls-verify-by-default branch June 22, 2026 13:24
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.

2 participants