Skip to content

docs: say BackendSession doesn't check addresses - #825

Merged
uniqueg merged 4 commits into
devfrom
docs/backend-session-addresses
Nov 25, 2026
Merged

uniqueg merged 4 commits into
devfrom
docs/backend-session-addresses

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Found in the pre-release review of 0.23.0: BackendSession (#796) is a plain requests.Session that 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 on backend.source: BackendSession for configured backends, GuardedClient (with auth=credentials and the registry entry's allow_private_addresses) for discovered ones. A new paragraph explains why (DNS rebinding, redirects), that allow_private_addresses turns the checks off, and that GuardedClient ignores the environment's proxies and CA certificates (pass ca_bundle).
  • BackendSession docstring: when to use it, and GuardedClient for discovered backends.

Closes #824

A guarded mode of BackendSession could follow later (separate issue, if gateways need it); see the issue.

Verification

  • ruff check / ruff format --check on foca/plugins/backends/credentials.py: pass.
  • mkdocs build --strict: pass.
  • Each claim checked against the code by the reviewers: GuardedClient always sends with allow_redirects=False and checks addresses per connection; credentials.apply(headers) and auth=credentials both 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_addresses of the registry entry; GuardedClient ignores environment proxies and CA bundles) and the low ones (explicit GuardedClient call, 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:

  • Clarify when to use BackendSession versus GuardedClient, including the security implications of address checks, redirects, and environment networking settings.

Documentation:

  • Document secure request handling for registry-discovered backends, including private-address policy, credentials, certificate authorities, proxies, and response-size limits.

uniqueg and others added 2 commits November 24, 2026 00:44
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
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Document when the public BackendSession should be used and direct callers of registry-discovered backends to GuardedClient.

  • foca/plugins/backends/credentials.py L561-568

Documentation

Update the backend credentials example and explain the security and configuration tradeoffs when choosing BackendSession or GuardedClient.

  • docs/plugins.md L392, L403-413, L450-470

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (382098f) to head (948fe11).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #825   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           76        76           
  Lines        10831     10831           
=========================================
  Hits         10831     10831           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 24, 2026 00:28
@uniqueg

uniqueg commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 948fe11

#824 docs: say BackendSession doesn't check addresses · 3 of 3 met

# Requirement Status Notes
1 Say that BackendSession is for the identity provider and configured backends, and doesn't check addresses or follow redirects safely by default. ✅ Met The plugin docs and class docstring state its intended use, lack of address checks, and redirect behavior.
2 Direct requests to registry-discovered backends through GuardedClient, using credentials.apply(headers). ✅ Met The example and explanatory paragraph use GuardedClient for discovered backends and document credentials via auth or applying them to headers.
3 Include the same usage guidance in the BackendSession class docstring. ✅ Met The docstring names the intended use and directs registry-discovered backend requests to GuardedClient, with either auth or Credentials.apply().

@sourcery-ai sourcery-ai 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.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread docs/plugins.md Resolved
Comment thread foca/plugins/backends/credentials.py Resolved

@sourcery-ai sourcery-ai 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.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread docs/plugins.md Resolved
Comment thread foca/plugins/backends/credentials.py Resolved
uniqueg and others added 2 commits November 25, 2026 14:48
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

@sourcery-ai sourcery-ai 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.

Sourcery assessment

Approved.

@uniqueg
uniqueg merged commit 4baaf89 into dev Nov 25, 2026
58 checks passed
@uniqueg
uniqueg deleted the docs/backend-session-addresses branch November 25, 2026 16: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.

docs: say BackendSession doesn't check addresses

1 participant