Repository navigation
docs: say BackendSession doesn't check addresses - #825
Conversation
BackendSession is a plain requests session: it connects to any address and follows redirects by default. Backends discovered in registries are checked for public addresses only when the registry is read, so requests to them go through GuardedClient with credentials.apply(headers). Say so in the plugin docs, the example and the class docstring. Closes #824 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Show the GuardedClient call for discovered backends, with the registry entry's allow_private_addresses, branch on backend.source, and say that GuardedClient ignores proxies and CA certificates of the environment (pass ca_bundle). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Reviewer's GuideAPIDocument when the public
DocumentationUpdate the backend credentials example and explain the security and configuration tradeoffs when choosing
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #825 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 76 76
Lines 10831 10831
=========================================
Hits 10831 10831
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@sourcery-ai review |
Linked issuesChecked at commit 948fe11 #824 docs: say BackendSession doesn't check addresses · 3 of 3 met
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/plugins.md" line_range="411" />
<code_context>
+ client = GuardedClient(
+ timeout=15, allow_private_addresses=entry.allow_private_addresses
+ )
+ client.get(url, auth=credentials)
+# other clients: apply them to the request's headers, which also removes an
+# `Authorization` header there for `auth: none`
</code_context>
<issue_to_address>
**Large responses fail at default cap**
When a discovered backend returns a response body larger than 16 MiB, `GuardedClient.get()` uses the 16 MiB default response limit, so `_read()` raises `ResponseTooLarge` and the caller receives no response for a larger backend payload.
Mention the default response-size limit beside this example and show how to set `max_response_size` when larger responses are expected.
</issue_to_address>
### Comment 2
<location path="foca/plugins/backends/credentials.py" line_range="566" />
<code_context>
+ configuration. It doesn't check the addresses that it connects to,
+ and follows redirects by default (except for `head()`): send requests
+ to backends discovered in registries with
+ :py:class:`foca.utils.http.GuardedClient` instead.
"""
</code_context>
<issue_to_address>
**Mention credential application**
The class docstring directs callers to GuardedClient for registry-discovered backends but omits the issue's requested guidance to pass credentials with `credentials.apply(headers)`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: docs/plugins.md:411
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/plugins.md" line_range="410-411" />
<code_context>
token_provider,
auth=outbound.auth, # None: the backend's own
)
-with BackendSession() as session:
- session.get(url, auth=credentials, allow_redirects=False, timeout=15)
-# other clients (e.g., GuardedClient): apply them to the request's headers,
-# which also removes an `Authorization` header there for `auth: none`
+if backend.source == "configured":
+ with BackendSession() as session:
+ session.get(url, auth=credentials, allow_redirects=False, timeout=15)
+else: # discovered in a registry: check the address of each connection
+ entry = backend_list.entry_for(backend) # the registry entry
+ client = GuardedClient(
+ timeout=15, allow_private_addresses=entry.allow_private_addresses
+ )
+ client.get(url, auth=credentials)
+# other clients: apply them to the request's headers, which also removes an
+# `Authorization` header there for `auth: none`
</code_context>
<issue_to_address>
**HTTP-discovered backends are rejected**
When a registry advertises a backend with an HTTP URL, `GuardedClient` is created without `allow_http=True`, so its default accepts only HTTPS and `client.get(url, auth=credentials)` raises `InvalidRequestURL` before sending when a discovered backend URL uses HTTP.
For HTTP backends that are intended to be supported, explicitly enable `allow_http` when constructing the client.
</issue_to_address>
### Comment 2
<location path="foca/plugins/backends/credentials.py" line_range="566" />
<code_context>
+ configuration. It doesn't check the addresses that it connects to,
+ and follows redirects by default (except for `head()`): send requests
+ to backends discovered in registries with
+ :py:class:`foca.utils.http.GuardedClient` instead.
"""
</code_context>
<issue_to_address>
**Document credential forwarding**
The issue asks the class docstring to repeat the guidance for discovered backends, including applying credentials. The docstring recommends GuardedClient but does not explain passing credentials with auth or applying them to headers.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: docs/plugins.md:411
Registries yield https backends only, so GuardedClient's default allow_http fits; say that it refuses responses larger than max_response_size, and that BackendSession's docstring passes the credentials as auth or applies them to the client's headers. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Summary
Found in the pre-release review of 0.23.0:
BackendSession(#796) is a plainrequests.Sessionthat connects to any address and follows redirects by default, while backends discovered in registries are checked for public addresses only when the registry is read. The docs showed it as the way to call any backend. Docs only (plus the class docstring):docs/plugins.md("Credentials of backends"): the example branches onbackend.source:BackendSessionfor configured backends,GuardedClient(withauth=credentialsand the registry entry'sallow_private_addresses) for discovered ones. A new paragraph explains why (DNS rebinding, redirects), thatallow_private_addressesturns the checks off, and thatGuardedClientignores the environment's proxies and CA certificates (passca_bundle).BackendSessiondocstring: when to use it, andGuardedClientfor discovered backends.Closes #824
A guarded mode of
BackendSessioncould follow later (separate issue, if gateways need it); see the issue.Verification
ruff check/ruff format --checkonfoca/plugins/backends/credentials.py: pass.mkdocs build --strict: pass.GuardedClientalways sends withallow_redirects=Falseand checks addresses per connection;credentials.apply(headers)andauth=credentialsboth work with it;entry_for()returns the registry entry for discovered backends.Review
adversarial-reviewer and quality-reviewer (one round; the fixes changed docs only): fixed the medium findings (missing
allow_private_addressesof the registry entry;GuardedClientignores environment proxies and CA bundles) and the low ones (explicitGuardedClientcall,head()default, docstring naming the intended use, muddled example comment).Declined review findings
None.
Open questions
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Summary by Sourcery
Document that BackendSession is intended for trusted configured backends and direct registry-discovered traffic through GuardedClient for safer request handling.
Enhancements:
Documentation: