From 74b1ccec2abe437e7b10466a6d72a9c06aa6acbd Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Mon, 23 Nov 2026 20:13:29 +0100 Subject: [PATCH 1/2] Render Markdown release notes safely in the updater --- docs/deployment.md | 9 +++ pyproject.toml | 1 + .../hosting/templates/hosting/updates.html | 9 ++- src/coulobre/hosting/templatetags/__init__.py | 0 .../hosting/templatetags/release_notes.py | 29 ++++++++++ src/coulobre/hosting/test_update_views.py | 56 +++++++++++++++++++ 6 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/coulobre/hosting/templatetags/__init__.py create mode 100644 src/coulobre/hosting/templatetags/release_notes.py create mode 100644 src/coulobre/hosting/test_update_views.py diff --git a/docs/deployment.md b/docs/deployment.md index c51642e..4488a8e 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -608,6 +608,15 @@ in-place procedure for custom service unit changes and for environments missing a dependency required by the target version. From 0.11 onward, the updater checks installed dependencies before stopping panel services. +Markdown release notes require `markdown-it-py` in the panel's virtual +environment. To use the web updater for the first release with this feature, +install the dependency before starting the update. The in-place procedure +installs it with the panel package. + +```sh +sudo /opt/coulobre/bin/python -m pip install 'markdown-it-py>=4.3,<5' +``` + The panel and its workers pause during the upgrade. Refresh **Updates** after the panel returns. The latest update status names the recovery directory in `/var/lib/coulobre-update/`. The root-only directory holds the previous diff --git a/pyproject.toml b/pyproject.toml index b12797f..cda5670 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ dependencies = [ "cryptography>=50", "dnspython>=2.9.2,<3", "idna>=3.15,<4", + "markdown-it-py>=4.3,<5", "qrcode>=8.2,<9", ] diff --git a/src/coulobre/hosting/templates/hosting/updates.html b/src/coulobre/hosting/templates/hosting/updates.html index 3ad9920..0f8ebd9 100644 --- a/src/coulobre/hosting/templates/hosting/updates.html +++ b/src/coulobre/hosting/templates/hosting/updates.html @@ -1,4 +1,5 @@ {% extends "hosting/base.html" %} +{% load release_notes %} {% block title %}Updates · Coulobre Panel{% endblock %} {% block content %}
@@ -44,11 +45,13 @@

Compatible releases

{% for release in releases %} -
+
{{ release.version }}{% if release.prerelease %} · Prerelease{% endif %} - {{ release.notes|linebreaks }} + {% if release.notes %} +
{{ release.notes|release_notes_html }}
+ {% endif %} {% if may_apply and release.version in applyable_versions and update_status.state != "running" and update_status.state != "recovery_required" %} -
+ {% csrf_token %} diff --git a/src/coulobre/hosting/templatetags/__init__.py b/src/coulobre/hosting/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/coulobre/hosting/templatetags/release_notes.py b/src/coulobre/hosting/templatetags/release_notes.py new file mode 100644 index 0000000..023d1db --- /dev/null +++ b/src/coulobre/hosting/templatetags/release_notes.py @@ -0,0 +1,29 @@ +from urllib.parse import urlsplit + +from django import template +from django.utils.safestring import mark_safe +from markdown_it import MarkdownIt + +register = template.Library() + + +class ReleaseNotesMarkdown(MarkdownIt): + def validateLink(self, url): # noqa: N802 - markdown-it-py hook + try: + link = urlsplit(url) + return ( + link.scheme in {"https", "http"} + and bool(link.hostname) + and link.username is None + and link.password is None + ) + except ValueError: + return False + + +markdown = ReleaseNotesMarkdown("js-default").disable("image") + + +@register.filter +def release_notes_html(notes): + return mark_safe(markdown.render(notes)) diff --git a/src/coulobre/hosting/test_update_views.py b/src/coulobre/hosting/test_update_views.py new file mode 100644 index 0000000..ec7a0bd --- /dev/null +++ b/src/coulobre/hosting/test_update_views.py @@ -0,0 +1,56 @@ +from unittest.mock import patch + +from django.contrib.auth import get_user_model +from django.core.cache import cache +from django.test import TestCase +from django.urls import reverse + +from coulobre.release_updates import Release + + +class UpdateViewTests(TestCase): + @classmethod + def setUpTestData(cls): + cls.admin = get_user_model().objects.create_superuser("operator") + + def test_catalog_renders_markdown_and_escapes_untrusted_content(self): + checksum = "a" * 64 + notes = f"""## Changes + +- **Upgrade** from the previous release. +- Follow the [deployment guide](https://example.test/docs#upgrade). + +```text +{checksum} coulobre_panel-0.11.1rc1.tar.gz +``` + + + +[Unsafe](javascript:invalid) [Local action](/updates/) + +![Remote image](https://example.test/image.png) +""" + release = Release("0.11.1rc1", notes, True, checksum) + self.client.force_login(self.admin) + cache.clear() + self.addCleanup(cache.clear) + path = "coulobre.hosting.update_views" + with ( + patch(f"{path}.SOCKET", **{"is_socket.return_value": True}), + patch(f"{path}.inspect_linked_nodes", return_value={"nodes": []}), + patch(f"{path}.available_releases", return_value=[release]), + ): + response = self.client.get(reverse("panel:updates")) + + self.assertContains(response, "

Changes

", html=True) + self.assertContains(response, "Upgrade", html=True) + self.assertContains(response, '
')
+        self.assertContains(response, f"{checksum}  coulobre_panel-")
+        self.assertContains(
+            response, 'href="https://example.test/docs#upgrade"'
+        )
+        self.assertContains(response, "<script>")
+        self.assertNotContains(response, "