Skip to content

Add a dependency that requires a session with a user #114

Description

@allen0099

Problem

Under FastAPICacheXSessionMiddleware, any visitor who reaches an endpoint that writes to request.session (a cart, a CSRF value) gets an anonymous session with user=None. get_session, RequiredSession and UserSessionDep only check that a session exists, so an app using them as an authentication guard admits anonymous visitors. UserSessionDep's name suggests otherwise.

Proposal

  • Add require_user_session (and an annotated alias) that raises 401 when session.user is None.
  • Document the difference in SESSION.md.
  • Making UserSessionDep enforce a user is breaking and tracked for 0.4.0.

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

    enhancementNew feature or requestsessionSession management subsystem

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions