US07-02: Harden API Authorization and Path Boundaries (#84)
This commit was merged in pull request #84.
This commit is contained in:
30
photo_pipeline/api/routes/session.py
Normal file
30
photo_pipeline/api/routes/session.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Session bootstrap: the one endpoint reachable without a session (US07-02).
|
||||
|
||||
It sets the ``HttpOnly``/``SameSite=Strict`` session cookie and returns the CSRF
|
||||
token in the body. A foreign page can call this — it just cannot read the answer,
|
||||
because the app sends no CORS headers — and the cookie it received is never attached
|
||||
to a request that foreign page initiates.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from photo_pipeline.api.security import SESSION_COOKIE
|
||||
|
||||
router = APIRouter(tags=["session"])
|
||||
|
||||
|
||||
@router.get("/session")
|
||||
def start_session(request: Request) -> JSONResponse:
|
||||
session = request.app.state.session
|
||||
response = JSONResponse({"csrf_token": session.csrf_token})
|
||||
response.set_cookie(
|
||||
SESSION_COOKIE,
|
||||
session.id,
|
||||
httponly=True,
|
||||
samesite="strict",
|
||||
path="/",
|
||||
)
|
||||
return response
|
||||
Reference in New Issue
Block a user