From b4e6cf3cc31f991ef1638003a067c8bcbf40dfb8 Mon Sep 17 00:00:00 2001 From: Phil Date: Sat, 31 Oct 2026 12:12:28 -0600 Subject: [PATCH] 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 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 --- CHANGELOG.md | 10 ++++++++ starpunk/__init__.py | 8 ++++-- starpunk/indieauth.py | 8 +----- starpunk/routes/indieauth.py | 8 +++--- starpunk/utils.py | 12 +++++++++ templates/base.html | 12 ++++----- templates/index.html | 4 +-- templates/note.html | 2 +- templates/tag.html | 2 +- tests/test_absolute_urls.py | 48 ++++++++++++++++++++++++++++++++++++ 10 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 tests/test_absolute_urls.py diff --git a/CHANGELOG.md b/CHANGELOG.md index edc07e3..05e8ee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.0.1] - 2026-10-31 + +### Fixed + +- Page links built from the request said `http://` behind an HTTPS reverse proxy + (RSS/OPML ``s and microformats `u-url`/`u-uid` permalinks). All absolute + URLs in templates now come from `SITE_URL` via `absolute_url_for()`. +- Container builds in Gitea Actions: build through the server's rootless BuildKit + and log in to the public registry name (the old workflow never succeeded). + ## [2.0.0] - 2026-10-31 ### Changed (breaking) diff --git a/starpunk/__init__.py b/starpunk/__init__.py index a15dbda..a240108 100644 --- a/starpunk/__init__.py +++ b/starpunk/__init__.py @@ -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) diff --git a/starpunk/indieauth.py b/starpunk/indieauth.py index 8d6d05c..b8f10b9 100644 --- a/starpunk/indieauth.py +++ b/starpunk/indieauth.py @@ -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"] diff --git a/starpunk/routes/indieauth.py b/starpunk/routes/indieauth.py index d8c12dc..efb2cc5 100644 --- a/starpunk/routes/indieauth.py +++ b/starpunk/routes/indieauth.py @@ -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"], diff --git a/starpunk/utils.py b/starpunk/utils.py index 674b874..738fb91 100644 --- a/starpunk/utils.py +++ b/starpunk/utils.py @@ -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) diff --git a/templates/base.html b/templates/base.html index c9d39f8..4ec772d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,16 +5,16 @@ {% block title %}StarPunk{% endblock %} - - + + {# Webmention endpoint (v1.6.0) #} {% if config.WEBMENTION_ENABLED %} - - - - + + + + {% endif %} {# rel-me links from discovered author profile (v1.2.0 Phase 2) #} diff --git a/templates/index.html b/templates/index.html index 9a4288e..086b742 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,7 +9,7 @@

{{ config.SITE_NAME or 'Recent Notes' }}

{# u-url for feed (self-reference) #} - + {# Feed-level author h-card with all properties #} {# Hidden because it's semantic-only markup for parsers, not visual content #} @@ -53,7 +53,7 @@