Conversation
Every request carries the key in an Authorization header, and nothing checked where that header was going. `base_url` was concatenated with `endpoint_path` and handed to Net::HTTP, which turns TLS on only when the scheme happens to be https. So `base_url: "http://api.typesafe.ai"` — a typo, a copied snippet, a value read from config — sent `Bearer <key>` in cleartext, silently. A URL carrying userinfo or a fragment was worse than silent: `https://trusted.example@evil.example/p#x` reads as trusted.example, resolves to evil.example, and the appended endpoint path lands inside the fragment instead of the request path. Validate the base URL once, when the client is built, before any key goes out: it has to be an absolute http(s) URL with a host, no userinfo, and no query or fragment, and it has to be https unless the host is loopback, where nothing leaves the machine. Anything else raises ConfigurationError. The error message rewrites userinfo to "..." so a password pasted into a base URL does not end up in a backtrace. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every request carries the key in an
Authorizationheader, and nothing checked where that header was going.base_urlis concatenated withendpoint_pathand handed toNet::HTTP, which turns TLS on only when the scheme happens to behttps:So
base_url: "http://api.typesafe.ai"— a typo, a copied snippet, a value read from config — sendsBearer <key>in cleartext. Silently. Verified:A URL carrying userinfo or a fragment is worse than silent.
https://trusted.example@evil.example/p#xreads astrusted.example, resolves toevil.example, and the appended endpoint path lands inside the fragment instead of the request path.To be clear about what is not wrong: certificate verification is genuinely on for the default transport (
Net::HTTP#connectcallsSSLContext#set_params, whoseDEFAULT_PARAMSareverify_mode: VERIFY_PEER), and redirects are not followed, soAuthorizationis never forwarded to another host. This is only about the URL the client is pointed at.The fix
Validate the base URL once, when the client is built, before any key goes out. It has to be an absolute http(s) URL with a host, no userinfo, no query and no fragment, and it has to be
httpsunless the host is loopback (localhost,127.0.0.1,[::1]), where nothing leaves the machine and local mock servers keep working. Anything else raisesConfigurationError.The error message rewrites userinfo to
...so a password pasted into a base URL doesn't end up in a backtrace.Tests
test/base_url_test.rb, 12 cases, including the loopback allowances and the host-confusion URL. Suite green on 3.2.11 / 3.3.8 / 3.4.8.One of a series from a security and API-coverage audit. Branches are independent, each off
main.🤖 Generated with Claude Code