maint: Dependency upgrades and High backlog items (v2.11.0)

- All dependencies to current releases (97 known vulnerabilities -> 0),
  Python 3.14, uv pinned, requirements-test.txt, lxml/dateutil pinned
- CSRF tokens on admin forms, logout and IndieAuth consent
- IndieAuth client and crosspost link-card fetches via safe_get
- FLASK_DEBUG/FLASK_ENV default off/production; image sets them
- Foreign keys enforced on pooled connections; migration 018 removes orphans
- Rate limits shared across processes (rate_limits, migration 019)
- datetime.utcnow() and sqlite3 default adapters replaced
- compose.yaml fixed; duplicate dev_auth.py and test.ini removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-03 13:09:52 -07:00
1 parent 9f17e145ff
commit 75946be7b2
67 files changed
+885 -498

No files matched your search

+18 -17
View File
@@ -13,7 +13,7 @@ current IndieAuth spec: https://indieauth.spec.indieweb.org/
import base64
import hashlib
import secrets
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Optional
from urllib.parse import urljoin, urlparse
@@ -83,41 +83,42 @@ def fetch_client_redirect_uris(client_id: str) -> List[str]:
Supports a JSON client metadata document ("redirect_uris") and the older
HTML/Link header form (rel="redirect_uri"). Returns [] on any failure.
"""
from starpunk.webmention_ssrf import SSRFBlockedError, validate_url_for_fetch
import json
from starpunk.webmention_ssrf import FetchTooLargeError, SSRFBlockedError, safe_get, user_agent
# Every redirect hop is checked and the connection pinned to the checked
# address, with a hard time limit (v2.11.0; DEV_MODE allows localhost)
try:
if not current_app.config.get("DEV_MODE"):
validate_url_for_fetch(client_id)
response = httpx.get(
result = safe_get(
client_id,
timeout=5.0,
follow_redirects=True,
headers={"Accept": "application/json, text/html;q=0.9"},
headers={"Accept": "application/json, text/html;q=0.9",
"User-Agent": user_agent(current_app.config.get("SITE_URL", ""))},
max_bytes=500_000, timeout=5.0, truncate=True,
)
except (httpx.HTTPError, SSRFBlockedError, ValueError) as e:
except (httpx.HTTPError, SSRFBlockedError, ValueError, FetchTooLargeError) as e:
current_app.logger.info(f"IndieAuth: could not fetch client {client_id}: {e}")
return []
if response.status_code != 200:
if result.status_code != 200:
return []
base = str(response.url)
base = result.url
uris: List[str] = []
if "json" in response.headers.get("Content-Type", ""):
if "json" in result.headers.get("Content-Type", ""):
try:
data = response.json()
data = json.loads(result.text)
except ValueError:
return []
if isinstance(data, dict) and isinstance(data.get("redirect_uris"), list):
uris.extend(u for u in data["redirect_uris"] if isinstance(u, str))
return uris
link = response.links.get("redirect_uri")
link = httpx.Response(200, headers=result.headers).links.get("redirect_uri")
if link and link.get("url"):
uris.append(urljoin(base, link["url"]))
soup = BeautifulSoup(response.text[:500_000], "html.parser")
soup = BeautifulSoup(result.text, "html.parser")
for tag in soup.find_all(["link", "a"], href=True):
if "redirect_uri" in (tag.get("rel") or []):
uris.append(urljoin(base, tag["href"]))
@@ -203,7 +204,7 @@ def create_authorization_code(
redirect_uri,
scope,
code_challenge,
datetime.utcnow() + timedelta(minutes=CODE_LIFETIME_MINUTES),
datetime.now(timezone.utc).replace(tzinfo=None) + timedelta(minutes=CODE_LIFETIME_MINUTES),
),
)
db.commit()
@@ -258,7 +259,7 @@ def create_access_token(client_id: str, scope: str) -> Dict[str, Any]:
"""Issue an access token (stored hashed); returns the token response"""
token = secrets.token_urlsafe(32)
lifetime_days = current_app.config.get("INDIEAUTH_TOKEN_LIFETIME_DAYS", 90)
expires_at = datetime.utcnow() + timedelta(days=lifetime_days)
expires_at = datetime.now(timezone.utc).replace(tzinfo=None) + timedelta(days=lifetime_days)
db = get_db(current_app)
db.execute(