Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Dependency audit in CI; flask 3.1.3, werkzeug 3.1.9, bleach 6.4.0, python-dotenv 1.2.2 (#434)

Murtaza Nasirad5982209b57
diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml
index 3e5c102a..3bf30516 100644
--- a/.forgejo/workflows/test.yml
+++ b/.forgejo/workflows/test.yml
@@ -99,6 +99,21 @@ jobs:
PYTEST_DATABASE_URI: postgresql://speakr:speakr@postgres:5432/speakr_suite
run: pytest tests/ -q -p no:cacheprovider --timeout=120
+ dependency-audit:
+ # The locked packages against the published advisories (pip-audit);
+ # accepted advisories are in scripts/audit-exceptions.txt
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
+ - name: Set up Python
+ uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
+ with:
+ python-version: '3.11'
+ - name: Install pip-audit
+ run: pip install pip-audit==2.9.0
+ - name: Audit the lock files
+ run: scripts/audit-dependencies.sh
+
js-tests:
runs-on: ubuntu-latest
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 759d0404..cc9e6c23 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -180,6 +180,21 @@ jobs:
- name: Lock files match the requirements
run: scripts/lock-requirements.sh --check
+ dependency-audit:
+ # The locked packages against the published advisories (pip-audit);
+ # accepted advisories are in scripts/audit-exceptions.txt
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
+ - name: Set up Python
+ uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
+ with:
+ python-version: '3.11'
+ - name: Install pip-audit
+ run: pip install pip-audit==2.9.0
+ - name: Audit the lock files
+ run: scripts/audit-dependencies.sh
+
browser-smoke:
# Opens every page in headless Chromium and fails on failed requests,
# JavaScript errors, leftover template text, or a header whose user menu
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 010b8220..541c8c81 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -268,6 +268,7 @@ Every Python package, including the dependencies of dependencies, is pinned with
- Give a clear reason for a new dependency in the PR description. A feature that can be built with the existing packages is preferred, and for a heavy dependency needed only by a rarely used feature, you may be asked to keep that part in a fork.
- After a change to `requirements.txt` or `requirements-embeddings.txt`, run `scripts/lock-requirements.sh` (Docker is required) and commit the lock files. The lock files are checked in CI, and a mismatch is reported as a failure.
- To update one package: `scripts/lock-requirements.sh --upgrade-package <name>`. Releases that have been public for less than a week are not accepted.
+- The locked packages are checked against the published advisories with `scripts/audit-dependencies.sh` (pip-audit), in CI and before every release. An advisory that does not apply to Speakr is listed in `scripts/audit-exceptions.txt` with a reason and a review date.
- PRs that change dependencies, the Dockerfile, workflows or scripts, or that add minified, binary or encoded content, are reviewed line by line, so their review can take longer.
## What Happens After You Submit a PR?
diff --git a/requirements-embeddings.lock b/requirements-embeddings.lock
index c5e625ea..06fcc1ea 100644
--- a/requirements-embeddings.lock
+++ b/requirements-embeddings.lock
@@ -84,9 +84,9 @@ bcrypt==5.0.0 \
--hash=sha256:f8429e1c410b4073944f03bd778a9e066e7fad723564a52ff91841d278dfc822 \
--hash=sha256:fc746432b951e92b58317af8e0ca746efe93e66555f1b40888865ef5bf56446b
# via flask-bcrypt
-bleach==6.1.0 \
- --hash=sha256:0a31f1837963c41d46bbf1331b8778e1308ea0791db03cc4e7357b97cf42a8fe \
- --hash=sha256:3225f354cfc436b9789c66c4ee030194bee0568fbf9cbdad3bc8b5c26c5f12b6
+bleach==6.4.0 \
+ --hash=sha256:4202482733d85cedd04e59fcb2f89f4e4c7c385a78d3c3c23c30446843a37452 \
+ --hash=sha256:4b6b6a54fff2e69a3dde9d21cc6301220bee3c3cb792187d11403fd795031081
# via -r requirements.txt
blinker==1.9.0 \
--hash=sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf \
@@ -512,9 +512,9 @@ filelock==4.1.1 \
# huggingface-hub
# torch
# transformers
-flask==3.1.0 \
- --hash=sha256:5f873c5184c897c8d9d1b05df1e3d01b14910ce69607a117bd3277098a5836ac \
- --hash=sha256:d667207822eb83f1c4b50949b1623c8fc8d51f2341d65f72e1a1815397551136
+flask==3.1.3 \
+ --hash=sha256:0ef0e52b8a9cd932855379197dd8f94047b359ca0a78695144304cb45f87c9eb \
+ --hash=sha256:f4bcbefc124291925f1a26446da31a5178f9483862233b23c0c96a20701f670c
# via
# -r requirements.txt
# flask-bcrypt
@@ -1190,6 +1190,7 @@ markupsafe==3.0.4 \
--hash=sha256:fd9f8797427910198f95bced71ddfed61130d7e349213bfb8466c9c99e2c46a8 \
--hash=sha256:fdb4ca07ab75ffadab4a8b135ad59cdbb3156b99310f3d565370da74a15d6bd3
# via
+ # flask
# jinja2
# werkzeug
# wtforms
@@ -1664,9 +1665,9 @@ python-docx==1.1.0 \
--hash=sha256:5829b722141cf1ab79aedf0c34d9fe9924b29764584c0f2164eb2b02dcdf17c9 \
--hash=sha256:bac9773278098a1ddc43a52d84e22f5909c4a3080a624530b3ecb3771b07c6cd
# via -r requirements.txt
-python-dotenv==1.0.0 \
- --hash=sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba \
- --hash=sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a
+python-dotenv==1.2.2 \
+ --hash=sha256:1d8214789a24de455a8b8bd8ae6fe3c6b69a5e3d64aa8a8e5d68e694bbcb285a \
+ --hash=sha256:2c371a91fbd7ba082c2c1dc1f8bf89ca22564a087c2c287cd9b662adde799cf3
# via -r requirements.txt
pytz==2024.1 \
--hash=sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812 \
@@ -1994,7 +1995,6 @@ six==1.17.0 \
--hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 \
--hash=sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81
# via
- # bleach
# python-dateutil
# pywebpush
sniffio==1.3.1 \
@@ -2188,9 +2188,9 @@ webencodings==0.6.1 \
--hash=sha256:565f9ad031c702dae404e27a099e3e09186a3ab1b9520f06d215502b651fd910 \
--hash=sha256:7fab6269c8bf237c657876b52058ccb182e861518d1c695c1a9aaa8c1c105d5b
# via bleach
-werkzeug==3.1.3 \
- --hash=sha256:54b78bf3716d19a65be4fceccc0d1d7b89e608834989dfae50ea87564639213e \
- --hash=sha256:60723ce945c19328679790e3282cc758aa4a6040e4bb330f53d30fa546d44746
+werkzeug==3.1.9 \
+ --hash=sha256:55ca7c70a75689be937aa27f8ff4b018f06ff4838fc73045560bf0f5a1291060 \
+ --hash=sha256:6392e50c78460ba618e5b21f08a71f59c99ce99cdc6cf6e3dd7e6ccca8754fab
# via
# -r requirements.txt
# flask
diff --git a/requirements.lock b/requirements.lock
index c1d58e9a..81a09820 100644
--- a/requirements.lock
+++ b/requirements.lock
@@ -84,9 +84,9 @@ bcrypt==5.0.0 \
--hash=sha256:f8429e1c410b4073944f03bd778a9e066e7fad723564a52ff91841d278dfc822 \
--hash=sha256:fc746432b951e92b58317af8e0ca746efe93e66555f1b40888865ef5bf56446b
# via flask-bcrypt
-bleach==6.1.0 \
- --hash=sha256:0a31f1837963c41d46bbf1331b8778e1308ea0791db03cc4e7357b97cf42a8fe \
- --hash=sha256:3225f354cfc436b9789c66c4ee030194bee0568fbf9cbdad3bc8b5c26c5f12b6
+bleach==6.4.0 \
+ --hash=sha256:4202482733d85cedd04e59fcb2f89f4e4c7c385a78d3c3c23c30446843a37452 \
+ --hash=sha256:4b6b6a54fff2e69a3dde9d21cc6301220bee3c3cb792187d11403fd795031081
# via -r requirements.txt
blinker==1.9.0 \
--hash=sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf \
@@ -470,9 +470,9 @@ email-validator==2.2.0 \
--hash=sha256:561977c2d73ce3611850a06fa56b414621e0c8faa9d66f2611407d87465da631 \
--hash=sha256:cb690f344c617a714f22e66ae771445a1ceb46821152df8e165c5f9a364582b7
# via -r requirements.txt
-flask==3.1.0 \
- --hash=sha256:5f873c5184c897c8d9d1b05df1e3d01b14910ce69607a117bd3277098a5836ac \
- --hash=sha256:d667207822eb83f1c4b50949b1623c8fc8d51f2341d65f72e1a1815397551136
+flask==3.1.3 \
+ --hash=sha256:0ef0e52b8a9cd932855379197dd8f94047b359ca0a78695144304cb45f87c9eb \
+ --hash=sha256:f4bcbefc124291925f1a26446da31a5178f9483862233b23c0c96a20701f670c
# via
# -r requirements.txt
# flask-bcrypt
@@ -1113,6 +1113,7 @@ markupsafe==3.0.4 \
--hash=sha256:fd9f8797427910198f95bced71ddfed61130d7e349213bfb8466c9c99e2c46a8 \
--hash=sha256:fdb4ca07ab75ffadab4a8b135ad59cdbb3156b99310f3d565370da74a15d6bd3
# via
+ # flask
# jinja2
# werkzeug
# wtforms
@@ -1402,9 +1403,9 @@ python-docx==1.1.0 \
--hash=sha256:5829b722141cf1ab79aedf0c34d9fe9924b29764584c0f2164eb2b02dcdf17c9 \
--hash=sha256:bac9773278098a1ddc43a52d84e22f5909c4a3080a624530b3ecb3771b07c6cd
# via -r requirements.txt
-python-dotenv==1.0.0 \
- --hash=sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba \
- --hash=sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a
+python-dotenv==1.2.2 \
+ --hash=sha256:1d8214789a24de455a8b8bd8ae6fe3c6b69a5e3d64aa8a8e5d68e694bbcb285a \
+ --hash=sha256:2c371a91fbd7ba082c2c1dc1f8bf89ca22564a087c2c287cd9b662adde799cf3
# via -r requirements.txt
pytz==2024.1 \
--hash=sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812 \
@@ -1490,7 +1491,6 @@ six==1.17.0 \
--hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 \
--hash=sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81
# via
- # bleach
# python-dateutil
# pywebpush
sniffio==1.3.1 \
@@ -1601,9 +1601,9 @@ webencodings==0.6.1 \
--hash=sha256:565f9ad031c702dae404e27a099e3e09186a3ab1b9520f06d215502b651fd910 \
--hash=sha256:7fab6269c8bf237c657876b52058ccb182e861518d1c695c1a9aaa8c1c105d5b
# via bleach
-werkzeug==3.1.3 \
- --hash=sha256:54b78bf3716d19a65be4fceccc0d1d7b89e608834989dfae50ea87564639213e \
- --hash=sha256:60723ce945c19328679790e3282cc758aa4a6040e4bb330f53d30fa546d44746
+werkzeug==3.1.9 \
+ --hash=sha256:55ca7c70a75689be937aa27f8ff4b018f06ff4838fc73045560bf0f5a1291060 \
+ --hash=sha256:6392e50c78460ba618e5b21f08a71f59c99ce99cdc6cf6e3dd7e6ccca8754fab
# via
# -r requirements.txt
# flask
diff --git a/requirements.txt b/requirements.txt
index 1c4ad3e1..b3dff101 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-flask==3.1.0
+flask==3.1.3
flask-sqlalchemy==3.1.1
SQLAlchemy>=2.0,<2.1
flask-login==0.6.3
@@ -18,15 +18,15 @@ email-validator==2.2.0
openai>=2.2.0
httpx>=0.27.0,<1.0.0
pywebpush==1.14.0
-werkzeug==3.1.3
+werkzeug==3.1.9
gunicorn==23.0.0
-python-dotenv==1.0.0
+python-dotenv==1.2.2
markdown==3.5.1
pytz==2024.1
# IANA timezone data for zoneinfo when the OS has none (#412)
tzdata==2025.2
Babel==2.12.1
-bleach==6.1.0
+bleach==6.4.0
python-docx==1.1.0
numpy==1.24.3
scikit-learn==1.3.0
diff --git a/scripts/audit-dependencies.sh b/scripts/audit-dependencies.sh
new file mode 100755
index 00000000..4a1e0fc7
--- /dev/null
+++ b/scripts/audit-dependencies.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Checks the locked packages against the published advisories with pip-audit
+# (pip install pip-audit==2.9.0). Advisories that do not apply to Speakr are
+# listed in scripts/audit-exceptions.txt with a review date and a reason; an
+# exception past its review date no longer applies, so the advisory fails the
+# check again until it is looked at.
+#
+# scripts/audit-dependencies.sh
+set -eu
+cd "$(dirname "$0")/.."
+
+today=$(date -u +%Y-%m-%d)
+ignores=""
+while read -r id until reason; do
+ case "$id" in ''|'#'*) continue ;; esac
+ first=$(printf '%s\n%s\n' "$today" "$until" | sort | head -n 1)
+ if [ "$until" = never ] || [ "$first" = "$today" ]; then
+ ignores="$ignores --ignore-vuln $id"
+ else
+ echo "Exception for $id expired on $until ($reason)" >&2
+ fi
+done < scripts/audit-exceptions.txt
+
+status=0
+for lock in requirements.lock requirements-embeddings.lock; do
+ echo "== $lock"
+ # shellcheck disable=SC2086
+ pip-audit --disable-pip --require-hashes --progress-spinner off -r "$lock" $ignores || status=1
+done
+exit $status
diff --git a/scripts/audit-exceptions.txt b/scripts/audit-exceptions.txt
new file mode 100644
index 00000000..7d78034c
--- /dev/null
+++ b/scripts/audit-exceptions.txt
@@ -0,0 +1,26 @@
+# Advisories for locked packages that do not apply to Speakr, read by
+# scripts/audit-dependencies.sh. One per line:
+# <advisory id> <review date YYYY-MM-DD> <reason>
+# Past its review date an exception no longer applies.
+
+# markdown: a malformed HTML-like text can make the parser raise; no fixed
+# release. md_to_html catches the error and shows the text escaped.
+PYSEC-2026-89 2027-04-30 markdown parser error is caught in md_to_html
+# scikit-learn: TfidfVectorizer keeps all tokens; Speakr uses only cosine_similarity.
+PYSEC-2024-110 2027-04-30 scikit-learn TfidfVectorizer is not used
+# certifi: the fixed release (2026.10.19) came out on 2026-10-20; it is taken
+# after the 7-day wait for new releases.
+GHSA-6q48-6c7w-9gw2 2026-10-27 certifi 2026.10.19 is newer than 7 days
+
+# transformers and sentence-transformers (embeddings image only): code
+# execution or file writes when loading or saving an untrusted model. Speakr
+# loads one model, named by the administrator in EMBEDDING_MODEL, without
+# trust_remote_code, and never trains, saves or loads custom generation code.
+# The fixes are in transformers 5, a major upgrade.
+PYSEC-2025-217 2027-01-31 transformers X-CLIP conversion is not used
+PYSEC-2026-2288 2027-01-31 transformers Trainer is not used
+PYSEC-2026-2289 2027-01-31 only the administrator's embedding model is loaded
+PYSEC-2026-2290 2027-01-31 only the administrator's embedding model is loaded
+PYSEC-2026-3929 2027-01-31 tokenizers are never saved
+PYSEC-2026-4174 2027-01-31 load_custom_generate is not used
+PYSEC-2026-4164 2027-01-31 only the administrator's embedding model is loaded
diff --git a/src/utils/markdown.py b/src/utils/markdown.py
index b45d55e6..b8fcb76b 100644
--- a/src/utils/markdown.py
+++ b/src/utils/markdown.py
@@ -5,11 +5,15 @@ This module provides functions for converting markdown to HTML and
sanitizing HTML to prevent XSS and other security issues.
"""
+import html as html_lib
+import logging
import re
import threading
import markdown
import bleach
+logger = logging.getLogger(__name__)
+
_EXTENSIONS = [
'fenced_code', # Fenced code blocks
'tables', # Table support
@@ -137,7 +141,15 @@ def md_to_html(text):
# Reset the thread's instance to clear any state from its previous conversion
md = _markdown()
md.reset()
- html = md.convert(processed_text)
+ try:
+ html = md.convert(processed_text)
+ except Exception:
+ # Malformed HTML-like text can make the parser raise (CVE-2025-69534,
+ # no fixed release). The text is then shown escaped, as plain
+ # paragraphs, instead of failing the request.
+ logger.warning("Markdown conversion failed; showing the text as plain paragraphs", exc_info=True)
+ md.reset()
+ html = "".join(f"<p>{html_lib.escape(part)}</p>" for part in text.split("\n\n") if part.strip())
# Apply sanitization to the generated HTML
return _with_auto_direction(sanitize_html(html))
diff --git a/tests/test_markdown_conversion_failure.py b/tests/test_markdown_conversion_failure.py
new file mode 100644
index 00000000..9ed2df8e
--- /dev/null
+++ b/tests/test_markdown_conversion_failure.py
@@ -0,0 +1,18 @@
+"""A text that makes the Markdown parser raise is shown escaped, as plain
+paragraphs, instead of failing the request (CVE-2025-69534)."""
+from unittest.mock import patch
+
+from src.utils import markdown as md_module
+from src.utils.markdown import md_to_html
+
+
+def test_parser_error_falls_back_to_escaped_paragraphs():
+ with patch.object(md_module.markdown.Markdown, "convert", side_effect=AssertionError("bad")):
+ html = md_to_html("First <b>part</b>\n\nSecond part")
+ assert html == '<p dir="auto">First &lt;b&gt;part&lt;/b&gt;</p><p dir="auto">Second part</p>'
+
+
+def test_next_conversion_on_the_thread_works():
+ with patch.object(md_module.markdown.Markdown, "convert", side_effect=AssertionError("bad")):
+ md_to_html("x")
+ assert md_to_html("**ok**") == '<p dir="auto"><strong>ok</strong></p>'