diff --git a/.gitignore b/.gitignore index 2d6a363..6ded754 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ __pycache__/ *.tar.gz server/data/ server.log +pi-session-*.html +.pytest_cache/ diff --git a/ani-web.service b/ani-web.service new file mode 100644 index 0000000..071c4ff --- /dev/null +++ b/ani-web.service @@ -0,0 +1,17 @@ +# Supervised replacement for run.sh's nohup (crash -> auto-restart). +# Install (then stop the run.sh instance: pkill -f 'uvicorn .*app:app'): +# sudo ln -s /home/jozamudi/code/ani-cli-front-end/ani-web.service /etc/systemd/system/ +# sudo systemctl daemon-reload && sudo systemctl enable --now ani-web +[Unit] +Description=ani-web (FastAPI anime front-end) +After=network-online.target + +[Service] +WorkingDirectory=/home/jozamudi/code/ani-cli-front-end +Environment=ANIWEB_SECURE=1 +ExecStart=/home/jozamudi/code/ani-cli-front-end/.venv/bin/python -m uvicorn server.app:app --host 0.0.0.0 --port 8321 +Restart=always +RestartSec=2 + +[Install] +WantedBy=multi-user.target diff --git a/server/app.py b/server/app.py index 05af4fe..5745ada 100644 --- a/server/app.py +++ b/server/app.py @@ -11,7 +11,7 @@ import time from pathlib import Path from base64 import urlsafe_b64encode, urlsafe_b64decode from collections import OrderedDict -from urllib.parse import quote, urljoin +from urllib.parse import quote, urljoin, urlparse from fastapi import Body, FastAPI, HTTPException, Query, Request from fastapi.responses import FileResponse, JSONResponse, RedirectResponse, Response @@ -57,6 +57,19 @@ def _lock(user: str, pw: str) -> str: return "bad" +@app.middleware("http") +async def csrf_header(request, call_next): + # ponytail: a cross-site form POST (top-level navigation) does carry the + # SameSite=Lax cookie, so