Skip to content

BruteForceProtection crashes with a RedisBackend (or any non-MemoryBackend) #12

Description

@magi8101

record_failure() and mark_success() in security/brute_force.py call self._backend.incr_sync(...) / .reset_sync(...), but those aren't part of the async StorageBackend Protocol (incr/get/reset) — _patch_backend() monkey-patches sync shims onto MemoryBackend only, because its ops are plain dict access under the hood. RedisBackend (or any other custom StorageBackend) never gets patched, so passing backend=RedisBackend(...) to BruteForceProtection will AttributeError the first time someone fails a login.

Found while clearing mypy errors in #11 (the missing attrs were part of the tracked debt) — documented inline there but not fixed, since the real fix is making record_failure/mark_success async and awaiting the Protocol's actual incr/reset, which is a behavior change touching the middleware's call and the existing brute-force test suite, not a type-only fix.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions