Skip to content

fix: bound redirect bodies, tell sent from unsent #640

Closed

Description

@uniqueg

Problem

Two gaps of foca.utils.http.GuardedClient, which gateways rely on to bound responses and to decide whether a request can be retried on another backend:

  1. Redirect bodies ignore the size limit. With allow_redirects=False, requests.Session.send() still prepares the next request (for Response.next) and reads the whole body of the redirect, without limit, before GuardedClient sees the response. Only the deadline ends the read. An invalid Location header raises an error at that point, too. Response hooks of authentication handlers (e.g., HTTPDigestAuth) read bodies without limit in the same way.
  2. Sent and not-sent errors are ambiguous. RequestNotSent and RequestMaybeSent are told apart by the kind of error, but the same errors occur before and after sending. A TLS error while waiting for or reading a response is reported as RequestNotSent, so a gateway may submit the request a second time. A connection lost during the TLS handshake is reported as RequestMaybeSent, so a request that can safely be retried is not.

Proposal

  • Don't let requests handle redirects, so that their bodies go through the size limit and they are returned like other responses.
  • Refuse authentication handlers with response hooks.
  • Note when the first byte of a request goes out, and decide RequestNotSent or RequestMaybeSent by that alone. Each reason code then means one or the other.

Acceptance criteria

  • A redirect with an endless body gives ResponseTooLarge, not a timeout; a redirect to an invalid URL is returned.
  • Tests for TLS errors and lost connections before and after sending.
  • docs/utilities.md and the migration guide updated.

Activity

  1. added this to the v0.20.0 milestone on Nov 3, 2026
  2. added
    priority: medium
    status: in progress
    type: bug
    type: security
    workload: hours
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumstatus: in progresstype: bugtype: securityworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions