fix: Build absolute URLs from SITE_URL, not the request (v2.0.1)

Behind Caddy the app is reached over plain HTTP, so url_for(_external=True)
produced http:// links on the https site: the RSS/OPML <link>s and the
microformats u-url/u-uid permalinks that IndieWeb parsers treat as
canonical. Templates now use absolute_url_for(), shared with the
IndieAuth metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-10-31 12:12:28 -06:00
1 parent 2d0568d9c2
commit b4e6cf3cc3
10 files changed
+91 -23

No files matched your search

+6 -2
View File
@@ -191,6 +191,10 @@ def create_app(config=None):
register_routes(app)
# Template context processor - Inject author profile (v1.2.0 Phase 2)
from starpunk.utils import absolute_url_for
app.jinja_env.globals["absolute_url_for"] = absolute_url_for
@app.context_processor
def inject_author():
"""
@@ -436,5 +440,5 @@ def create_app(config=None):
# Package version (Semantic Versioning 2.0.0)
# See docs/standards/versioning-strategy.md for details
__version__ = "2.0.0"
__version_info__ = (2, 0, 0)
__version__ = "2.0.1"
__version_info__ = (2, 0, 1)
+1 -7
View File
@@ -22,6 +22,7 @@ from bs4 import BeautifulSoup
from flask import current_app
from starpunk.database import get_db
from starpunk.utils import absolute_url_for
CODE_LIFETIME_MINUTES = 10
SUPPORTED_SCOPES = ["create", "update", "delete", "media", "profile"]
@@ -55,13 +56,6 @@ def issuer() -> str:
return current_app.config["SITE_URL"].rstrip("/") + "/"
def site_url_for(endpoint: str) -> str:
"""Absolute URL built from SITE_URL (request host/scheme is unreliable behind a proxy)"""
from flask import url_for
return current_app.config["SITE_URL"].rstrip("/") + url_for(endpoint)
def admin_me() -> str:
"""The single identity StarPunk issues tokens for"""
return current_app.config["ADMIN_ME"]
+4 -4
View File
@@ -34,11 +34,11 @@ from starpunk.indieauth import (
issuer,
redeem_authorization_code,
revoke_access_token,
site_url_for,
validate_authorization_request,
verify_access_token,
)
from starpunk.micropub import extract_bearer_token
from starpunk.utils import absolute_url_for
bp = Blueprint("indieauth", __name__)
@@ -89,9 +89,9 @@ def metadata():
return _json(
{
"issuer": issuer(),
"authorization_endpoint": site_url_for("indieauth.authorize"),
"token_endpoint": site_url_for("indieauth.token"),
"revocation_endpoint": site_url_for("indieauth.revoke"),
"authorization_endpoint": absolute_url_for("indieauth.authorize"),
"token_endpoint": absolute_url_for("indieauth.token"),
"revocation_endpoint": absolute_url_for("indieauth.revoke"),
"revocation_endpoint_auth_methods_supported": ["none"],
"scopes_supported": SUPPORTED_SCOPES,
"response_types_supported": ["code"],
+12
View File
@@ -681,3 +681,15 @@ def parse_iso8601(date_string: str) -> datetime:
# Parse using fromisoformat
return datetime.fromisoformat(date_string)
def absolute_url_for(endpoint: str, **values) -> str:
"""
Absolute URL for an endpoint, built from SITE_URL
Use instead of url_for(..., _external=True): behind a reverse proxy the
request arrives over plain HTTP, so _external URLs would say http://.
"""
from flask import current_app, url_for
return current_app.config["SITE_URL"].rstrip("/") + url_for(endpoint, **values)