Skip to content

Add type hints and docstrings to utils/security_middleware.py #1023

@marketcalls

Description

@marketcalls

Description

The `utils/security_middleware.py` module implements critical security functionality (IP banning, WSGI middleware) but lacks type hints and docstrings, making it harder for new contributors to understand.

Affected File

  • `utils/security_middleware.py`

What to Do

  1. Add type hints to `SecurityMiddleware.init` and `call`
  2. Add type hints to `check_ip_ban` decorator
  3. Add class-level and function-level docstrings

```python
from typing import Any, Callable

class SecurityMiddleware:
"""WSGI middleware that checks if the client IP is banned before processing requests."""

def __init__(self, app: Any) -> None:
    \"\"\"Initialize middleware with the WSGI application.\"\"\"
    self.app = app

def __call__(self, environ: dict[str, Any], start_response: Callable) -> Any:
    \"\"\"Check IP ban status and either block or forward the request.\"\"\"
    ...

def check_ip_ban(f: Callable[..., Any]) -> Callable[..., Any]:
"""Decorator that returns 403 if the client IP is banned."""
...
```

Acceptance Criteria

  • All public methods have type hints
  • All classes and functions have docstrings
  • Type hints are accurate (verify parameter/return types)

Skills You'll Learn

  • Python type hints for WSGI apps
  • Writing effective docstrings
  • Understanding middleware patterns

Metadata

Metadata

Assignees

No one assigned

    Labels

    FOSSHack 2026FOSSHack 2026 HackathonbackendFlask backend issuesdocumentationImprovements or additions to documentationgood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions