Skip to main content
← All guides

Fix Rails “Blocked hosts” through a tunnel

Why qURL here

Keep the app private on your machine and invite the people you choose by email: each verifies their address and saves a passkey, with no account needed, and comes back until you revoke them. Your Rails app answers them once .qurl.site is in config.hosts. For a quick look, send a one-time qURL™ link instead.

See how LayerV compares to ngrok →

Steps

Rails rejects unknown hosts with “Blocked hosts”. Add .qurl.site or your tunnel hostname to config.hosts. For qURL form posts, allow the exact browser origin in development while retaining origin and authenticity-token checks. With qURL, the app stays on your machine with no public URL, and qurl stop ends access whenever you want.

  1. Read the host from the error

    Rails answers 403 with a page that says “Blocked hosts: c-k3j2ab.qurl.site” and suggests the line to add, config.hosts << "c-k3j2ab.qurl.site". Through qURL the host can appear twice, because Rails checks X-Forwarded-Host as well as Host. The log shows the same list from ActionDispatch::HostAuthorization.

  2. Add the tool’s domain to config.hosts

    Add the domain, not the one hostname the error names, so the next link works too. In Rails a leading dot allows the domain and one more label in front of it: .qurl.site covers c-….qurl.site, but .ts.net does not cover machine.tailnet.ts.net, so use .tailnet.ts.net or a regular expression there. Your entries add to the development defaults, so localhost keeps working. Restart the server.

    # config/environments/development.rb
    Rails.application.configure do
      config.hosts << ".qurl.site"
      # ngrok: "your-domain.ngrok-free.app"   Cloudflare Quick Tunnel: ".trycloudflare.com"
    end
  3. Or allow it for one run without editing a file

    The development default reads RAILS_DEVELOPMENT_HOSTS, a comma-separated list, when the server starts.

    RAILS_DEVELOPMENT_HOSTS=.qurl.site bin/rails server
  4. Share it through qURL

    Publish the running dev server, make a link, and send it to the recipient. They open it and keep that page open while you configure their exact browser origin in the next step. The first publish creates this device’s identity and needs no account. Each link opens once and expires within 24 hours.

    qurl publish http://127.0.0.1:3000
    qurl share <CRID>
  5. qURL: trust the exact browser origin in development

    Rails compares the browser’s Origin with the URL it believes it is serving. Through qURL the browser uses https://r_….qurl.site while Rails sees http://c-….qurl.site. Keep forgery_protection_origin_check enabled and add the development-only exception below at the end of ApplicationController. Ask the recipient to send you the https origin from the address bar of the page they just opened. They must keep that page open; do not open their single-use link yourself. Set QURL_DEV_ORIGIN to that exact origin, restart Rails, and ask them to reload the same page. This configuration trusts one recipient origin at a time; update it for each new browser session. Trust only that exact address, never a whole-domain match, which would also trust other publishers’ links. Keep cookie domains host-only.

    # app/controllers/application_controller.rb (inside ApplicationController)
    private def valid_request_origin?
      trusted_origin = ENV.fetch("QURL_DEV_ORIGIN", "")
      if Rails.env.development? &&
          request.host.end_with?(".qurl.site") &&
          trusted_origin.start_with?("https://") &&
          request.origin == trusted_origin
        true
      else
        super
      end
    end
    # Restart with the exact browser origin (replace this example):
    # QURL_DEV_ORIGIN=https://r_your-link.qurl.site bin/rails server

What the recipient sees

With the host allowed and the exact browser origin trusted in development, pages load through the link and forms post normally.

Troubleshooting

Troubleshooting
If you seeDo this
ActionController::InvalidAuthenticityToken: “HTTP Origin header (https://r_….qurl.site) didn’t match request.base_url (http://c-….qurl.site)”The origin check failed, not the token. Keep forgery_protection_origin_check enabled, add the exact-origin override above, set QURL_DEV_ORIGIN to the browser’s https origin, and restart Rails. If the origin changes, update that value.
A .ts.net or other leading-dot entry still shows “Blocked hosts”In Rails a leading dot matches at most one label in front of the domain. Add the longer domain, such as .tailnet.ts.net, or a regular expression such as /.*\.ts\.net/.
Show 6 more fixes
More troubleshooting
If you seeDo this
qurl publish says the local app is not accepting TCP connectionsStart the app first and check that curl works on the same address. qurl publish connects to localhost as 127.0.0.1, so if your app listens only on IPv6 (on macOS or Linux, lsof -iTCP -sTCP:LISTEN -nP shows [::1]), publish 'http://[::1]:PORT' instead, or start the dev server with --host 127.0.0.1 and publish that address. Neither requires listening on your LAN. Keep the quotes: zsh treats the brackets as a pattern.
The recipient sees “Access link invalid”The link was already used or has expired. Run qurl share again and send the new link.
The recipient sees “Resource not found”The resource was deleted after the link was made. Publish the app again, then run qurl share and send the new link.
publish rejects http://127.0.0.1 with “only HTTPS URLs are allowed”, asks you to log in, or prints no Access: lineYour qURL CLI is out of date. On macOS run brew update, then brew upgrade qurl; elsewhere install the latest release. After updating, qurl --version prints 3.4.1 or later, and every publish is private by default.
publish says this Linux session “can’t reach a systemd user manager”You are in a container or sandbox without a user service manager. Run qurl publish with --foreground; sharing lasts as long as that process runs. Container and CI setup →
publish says “Quota Exceeded” with “protected resource limit reached”, or “Your qURL account has reached a plan limit”You can see this without an account: a device with no account can keep up to 3 active resources, with links that last up to 24 hours. Run qurl list --status active, then qurl delete <CRID> for any you no longer need (it asks you to confirm; --yes skips that). qurl stop keeps the resource, so it does not free a slot.

Frequently Asked Questions

Why use an exact origin instead of a qurl.site suffix check?

A suffix check would also trust pages run by other qURL publishers. The override above accepts only the exact QURL_DEV_ORIGIN in development and otherwise calls super. It rejects another qURL origin, an unrelated site, a lookalike suffix and null; the CSRF token is still required. Do not disable forgery_protection_origin_check or use this development exception in production.

Why does the qURL host appear twice in the error?

Rails checks both the Host header and X-Forwarded-Host, and a qURL link sets both to c-….qurl.site. Both must be allowed; one .qurl.site entry covers both.

Can I turn host authorization off?

Rails lets you clear config.hosts, but the check exists because of DNS rebinding attacks, which Rails 6.0 added it to guard against. Add the domains you need instead.

Who else can reach my app while the link is open?

Opening the link starts a session for that browser, which lasts 1 hour by default. After a browser opens it, another browser on the same public IP cannot use its access. A script or agent that opens the link without a browser is admitted by its network address instead, which other devices on that public IP share until the session ends. A link admits whoever opens it: the API’s IP and country rules do not apply to the signed links qurl share issues. Keep your app’s own sign-in for anything sensitive.

Publish your app now

Install the CLI, then run one command. No sign-up, no API key.

Install the CLI →

Book a pilot

Tell us what to hide. We’ll scope a pilot.

Enterprise starts with a paid pilot on one application, typically 60 to 90 days, credited in full toward year one if you convert within 60 days. After that, an annual package sized to what you protect, not per seat.