Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(security): patch vulnerable deps, recall-question regex, board pairing (#1138)

Ruben Lütkec58d7dad9667
diff --git a/board-backend/board_backend/routes/pair.py b/board-backend/board_backend/routes/pair.py
index c8f95dfa98..4fd884f27c 100644
--- a/board-backend/board_backend/routes/pair.py
+++ b/board-backend/board_backend/routes/pair.py
@@ -20,6 +20,7 @@ from datetime import datetime, timedelta, timezone
import httpx
from fastapi import APIRouter, Depends, HTTPException, Request
+from sqlalchemy import update
from ..auth import (
get_db,
@@ -99,8 +100,18 @@ def accept(request: Request, payload: PairAcceptRequest) -> PairAcceptResponse:
if payload.friend_pubkey == owner.pubkey:
raise HTTPException(status_code=400, detail="cannot pair with self")
- # Consume the token
- tok.used_at = now
+ # Consume the token with one conditional UPDATE: the checks above read
+ # the row first, so two concurrent accepts could both pass them. Only
+ # the request whose UPDATE flips ``used_at`` from NULL may pair.
+ consumed = session.execute(
+ update(PairToken)
+ .where(PairToken.token == payload.token, PairToken.used_at.is_(None))
+ .values(used_at=now)
+ .execution_options(synchronize_session=False)
+ )
+ if consumed.rowcount != 1:
+ session.rollback()
+ raise HTTPException(status_code=401, detail="token already used")
existing = session.get(Friend, (owner.pubkey, payload.friend_pubkey))
if existing is None:
diff --git a/board-backend/board_backend/schemas.py b/board-backend/board_backend/schemas.py
index 7ddfef2bec..1bc8e91079 100644
--- a/board-backend/board_backend/schemas.py
+++ b/board-backend/board_backend/schemas.py
@@ -9,16 +9,61 @@ of ``BoardAggregator.export_all_for_federation()`` (Plan §A-Smoke
"""
from __future__ import annotations
+import ipaddress
from datetime import datetime
-from typing import Any
+from typing import Annotated, Any
+from urllib.parse import urlsplit
-from pydantic import BaseModel, ConfigDict, Field, StringConstraints
-from typing_extensions import Annotated
+from pydantic import AfterValidator, BaseModel, ConfigDict, Field, StringConstraints
PubkeyHex = Annotated[
str,
StringConstraints(pattern=r"^[0-9a-f]{64}$"),
]
+
+
+def _check_backend_origin(value: str) -> str:
+ """Accept only a plain ``http(s)://host[:port]`` origin for a friend backend.
+
+ The backend later GETs and POSTs to this address on its own, so a value
+ with credentials, a path, another scheme, or a link-local / unspecified
+ address (the cloud metadata endpoint lives at 169.254.169.254) would let
+ whoever holds a pair link aim it somewhere it should never call. Private
+ and loopback addresses stay allowed: friends on one Docker network or LAN
+ reach each other that way.
+ """
+ try:
+ url = urlsplit(value.strip())
+ port = url.port
+ except ValueError as exc:
+ raise ValueError("friend_url must be an http(s) origin") from exc
+ if (
+ url.scheme not in {"http", "https"}
+ or not url.hostname
+ or url.username is not None
+ or url.password is not None
+ or url.path not in {"", "/"}
+ or url.query
+ or url.fragment
+ or (port is not None and not 0 < port <= 65535)
+ ):
+ raise ValueError("friend_url must be an http(s) origin such as https://board.example.com")
+ try:
+ address = ipaddress.ip_address(url.hostname)
+ except ValueError:
+ return value.strip()
+ if isinstance(address, ipaddress.IPv6Address) and address.ipv4_mapped is not None:
+ address = address.ipv4_mapped
+ if address.is_link_local or address.is_unspecified or address.is_multicast:
+ raise ValueError("friend_url must not point at a link-local or unspecified address")
+ return value.strip()
+
+
+BackendOrigin = Annotated[
+ str,
+ StringConstraints(min_length=4, max_length=500),
+ AfterValidator(_check_backend_origin),
+]
SignatureHex = Annotated[
str,
StringConstraints(pattern=r"^[0-9a-f]{128}$"),
@@ -144,7 +189,7 @@ class PairAcceptRequest(BaseModel):
token: Annotated[str, StringConstraints(min_length=16, max_length=64)]
friend_pubkey: PubkeyHex
- friend_url: Annotated[str, StringConstraints(min_length=4, max_length=500)]
+ friend_url: BackendOrigin
friend_display_name: Annotated[str, StringConstraints(min_length=1, max_length=120)]
diff --git a/board-backend/tests/test_pair.py b/board-backend/tests/test_pair.py
index c1dd36773a..fc0f2d3753 100644
--- a/board-backend/tests/test_pair.py
+++ b/board-backend/tests/test_pair.py
@@ -212,3 +212,77 @@ def test_friends_list_endpoint(
body = resp.json()
assert len(body["friends"]) == 1
assert body["friends"][0]["display_name"] == "Bob"
+
+
+ "friend_url",
+ [
+ "http://169.254.169.254", # cloud metadata endpoint
+ "http://[::ffff:169.254.169.254]",
+ "http://0.0.0.0:8765",
+ "file:///etc/passwd",
+ "http://b:8765/api/v1/anything",
+ "http://user:secret@b:8765",
+ "http://b:8765?x=1",
+ ],
+)
+def test_pair_accept_refuses_unsafe_friend_url(
+ owner_client: TestClient, friend_keys: tuple[str, str], friend_url: str
+) -> None:
+ init = owner_client.post(
+ "/api/v1/pair/initiate", json={},
+ headers={"X-Admin-Token": "test-admin"},
+ ).json()
+ _, friend_pub = friend_keys
+ resp = owner_client.post("/api/v1/pair/accept", json={
+ "token": init["token"],
+ "friend_pubkey": friend_pub,
+ "friend_url": friend_url,
+ "friend_display_name": "Bob",
+ })
+ assert resp.status_code == 422
+ with owner_client.app.state.session_factory() as session:
+ assert session.query(Friend).count() == 0
+ assert session.get(PairToken, init["token"]).used_at is None
+
+
+def test_pair_token_consumed_by_a_concurrent_accept_is_refused(
+ owner_client: TestClient, friend_keys: tuple[str, str]
+) -> None:
+ """A second accept that read the token before the first one committed loses."""
+ from sqlalchemy import event
+
+ init = owner_client.post(
+ "/api/v1/pair/initiate", json={},
+ headers={"X-Admin-Token": "test-admin"},
+ ).json()
+ factory = owner_client.app.state.session_factory
+ engine = factory.kw["bind"]
+
+ fired: list[bool] = []
+
+ def _concurrent_winner(conn, cursor, statement, parameters, context, executemany):
+ # Just before this request consumes the token, another one does.
+ if not fired and statement.lstrip().upper().startswith("UPDATE PAIR_TOKENS"):
+ fired.append(True)
+ with engine.begin() as other:
+ other.exec_driver_sql(
+ "UPDATE pair_tokens SET used_at = CURRENT_TIMESTAMP WHERE token = ?",
+ (init["token"],),
+ )
+
+ _, friend_pub = friend_keys
+ event.listen(engine, "before_cursor_execute", _concurrent_winner)
+ try:
+ resp = owner_client.post("/api/v1/pair/accept", json={
+ "token": init["token"],
+ "friend_pubkey": friend_pub,
+ "friend_url": "http://b:8765",
+ "friend_display_name": "Bob",
+ })
+ finally:
+ event.remove(engine, "before_cursor_execute", _concurrent_winner)
+ assert fired, "the accept never reached its consuming UPDATE"
+ assert resp.status_code == 401
+ with factory() as session:
+ assert session.query(Friend).count() == 0
diff --git a/dodaios/brain/turn_planner.py b/dodaios/brain/turn_planner.py
index efd68b129a..2c162da503 100644
--- a/dodaios/brain/turn_planner.py
+++ b/dodaios/brain/turn_planner.py
@@ -817,8 +817,8 @@ def is_contextual_follow_up(text: str, context: Sequence[str]) -> bool:
# the planner (``remember`` is a save verb) although the user is asking, not
# ordering. Kept next to the lookup regex so ``is_lookup_shape`` covers both.
_RECALL_QUESTION_RE = re.compile(
- r"(?:do you (?:remember|know|recall)|weisst du(?: noch)?|" # i18n-allow: speech input
- r"erinnerst du dich|kennst du|te acuerdas|recuerdas|sabes)" # i18n-allow: speech input
+ r"\b(?:do you (?:remember|know|recall)|weisst du(?: noch)?|" # i18n-allow: speech input
+ r"erinnerst du dich|kennst du|te acuerdas|recuerdas|sabes)\b" # i18n-allow: speech input
)
diff --git a/pyproject.toml b/pyproject.toml
index d8f73d2592..c024bd6f7a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -257,7 +257,7 @@ dependencies = [
# IDE's drop analysis: pypdf is the one non-stdlib parser those need, and
# it is a pure-Python universal wheel. Lazy-imported, with honest
# per-file degradation when absent.
- "pypdf>=6.21.2", # security floor: parser advisories fixed through 6.21.2
+ "pypdf>=6.21.4", # security floor: parser advisories fixed through 6.21.4
# Phase F1 — Telegram channel bot via long-polling (ChannelAdapter).
"python-telegram-bot>=22,<23",
]
diff --git a/requirements.in b/requirements.in
index 5a3cc5a779..7caef94c23 100644
--- a/requirements.in
+++ b/requirements.in
@@ -195,7 +195,7 @@ aiosqlite>=0.21
# Document text extraction + Agentic IDE drop analysis (pure-Python, lazy-imported)
# >=6.16.1: PYSEC-2026-3910/-3911/-3913 are fixed there (pip-audit gate);
# 6.15 closed PYSEC-2026-3655/-3656 before it.
-pypdf>=6.21.2
+pypdf>=6.21.4
python-telegram-bot>=22,<23
# Portable IANA timezone data for calendar routines.
diff --git a/requirements.txt b/requirements.txt
index 7fd9779c6e..5898d4fd42 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -600,9 +600,9 @@ distro==1.9.0 \
# anthropic
# google-genai
# openai
-dnspython==2.8.0 ; platform_machine != 'ARM64' or sys_platform != 'win32' \
- --hash=sha256:01d9bbc4a2d76bf0db7c1f729812ded6d912bd318d3b1cf81d30c0f845dbf3af \
- --hash=sha256:181d3c6996452cb1189c4046c61599b84a5a86e099562ffde77d26984ff26d0f
+dnspython==2.9.1 ; platform_machine != 'ARM64' or sys_platform != 'win32' \
+ --hash=sha256:7c81caf8de1ed57b8cfc7e0ad4f528a0b8ceace473c7eb946df195dc9def751f \
+ --hash=sha256:9a6d30e55f8dc63e6052597666112bff0586b95a2474a9deda03afbbf820d37a
# via aioice
docopt==0.6.2 \
--hash=sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491
@@ -1533,9 +1533,9 @@ psutil==7.2.2 \
--hash=sha256:eed63d3b4d62449571547b60578c5b2c4bcccc5387148db46e0c2313dad0ee00 \
--hash=sha256:fd04ef36b4a6d599bbdb225dd1d3f51e00105f6d48a28f006da7f9822f2606d8
# via dodaios (pyproject.toml)
-pyasn1==0.6.4 \
- --hash=sha256:9c447d8431c947fe4c8febc4ed9e760bc29011a5b01e5c74b67025bd9fb8ce81 \
- --hash=sha256:deda9277cfd454080ec40b207fb6df82206a3a2688735233cdcd8d3d565f088b
+pyasn1==0.6.5 \
+ --hash=sha256:4017b0fce125096b8573b39c989fdb1a4b19cf761e683398184550fea0e66587 \
+ --hash=sha256:6b11616a6bcf3a40e635f082bb232fa57b5e0dd7f517bd7ddd69ec3794508a47
# via pyasn1-modules
pyasn1-modules==0.4.2 \
--hash=sha256:29253a9207ce32b64c3ac6600edc75368f98473906e8fd1043bd6b5b1de2c14a \
diff --git a/tests/unit/brain/test_turn_planner_recall_shape.py b/tests/unit/brain/test_turn_planner_recall_shape.py
new file mode 100644
index 0000000000..c56c0da41b
--- /dev/null
+++ b/tests/unit/brain/test_turn_planner_recall_shape.py
@@ -0,0 +1,42 @@
+"""Recall-shaped openers read as lookups, not orders.
+
+The recall pattern once held literal backspace characters where word
+boundaries belonged, so it never matched and a spoken "do you remember ..."
+(no question mark in speech) was treated as an order to save something.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from dodaios.brain.turn_planner import _RECALL_QUESTION_RE, is_lookup_shape
+
+
+def test_recall_pattern_holds_no_control_characters() -> None:
+ assert not any(ord(char) < 32 for char in _RECALL_QUESTION_RE.pattern)
+
+
+ "utterance",
+ [
+ "do you remember my sister",
+ "do you recall the meeting",
+ "erinnerst du dich an gestern", # i18n-allow: German speech-input fixture
+ "kennst du den film noch", # i18n-allow: German speech-input fixture
+ "te acuerdas de mi hermana", # i18n-allow: Spanish speech-input fixture
+ ],
+)
+def test_recall_openers_are_lookup_shaped(utterance: str) -> None:
+ assert is_lookup_shape(utterance)
+
+
+ "utterance",
+ [
+ "save my notes",
+ "remember that my sister is called Anna",
+ "sabeston",
+ ],
+)
+def test_orders_and_word_fragments_are_not_recall_questions(utterance: str) -> None:
+ assert not _RECALL_QUESTION_RE.search(utterance)
diff --git a/uv.lock b/uv.lock
index ff8512bbe9..1482e38542 100644
--- a/uv.lock
+++ b/uv.lock
@@ -1102,11 +1102,11 @@ wheels = [
[[package]]
name = "dnspython"
-version = "2.8.0"
+version = "2.9.1"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/8c/8b/57666417c0f90f08bcafa776861060426765fdb422eb10212086fb811d26/dnspython-2.8.0.tar.gz", hash = "sha256:181d3c6996452cb1189c4046c61599b84a5a86e099562ffde77d26984ff26d0f", size = 368251, upload-time = "2025-09-07T18:58:00.022Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/91/21/7fcd6780f61e9756aafaea760560509bb4111375daa2e23c1be7a89f33f1/dnspython-2.9.1.tar.gz", hash = "sha256:9a6d30e55f8dc63e6052597666112bff0586b95a2474a9deda03afbbf820d37a", size = 455302, upload-time = "2026-10-29T18:05:12.156Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/ba/5a/18ad964b0086c6e62e2e7500f7edc89e3faa45033c71c1893d34eed2b2de/dnspython-2.8.0-py3-none-any.whl", hash = "sha256:01d9bbc4a2d76bf0db7c1f729812ded6d912bd318d3b1cf81d30c0f845dbf3af", size = 331094, upload-time = "2025-09-07T18:57:58.071Z" },
+ { url = "https://files.pythonhosted.org/packages/61/55/f90405bbbbd3dd8f788e92cec2d39964f5c09783f0570fc35f3bb3381485/dnspython-2.9.1-py3-none-any.whl", hash = "sha256:7c81caf8de1ed57b8cfc7e0ad4f528a0b8ceace473c7eb946df195dc9def751f", size = 360364, upload-time = "2026-10-29T18:05:10.206Z" },
]
[[package]]
@@ -1404,7 +1404,7 @@ requires-dist = [
{ name = "pyobjc-framework-avfoundation", marker = "sys_platform == 'darwin' and extra == 'desktop-macos'", specifier = ">=10,<13" },
{ name = "pyobjc-framework-quartz", marker = "sys_platform == 'darwin' and extra == 'desktop-macos'", specifier = ">=10,<13" },
{ name = "pyobjc-framework-screencapturekit", marker = "sys_platform == 'darwin' and extra == 'desktop-macos'", specifier = ">=10,<13" },
- { name = "pypdf", specifier = ">=6.21.2" },
+ { name = "pypdf", specifier = ">=6.21.4" },
{ name = "pyside6-addons", marker = "(platform_machine != 'aarch64' and extra == 'desktop') or (sys_platform != 'linux' and extra == 'desktop')", specifier = ">=6.7" },
{ name = "pyside6-essentials", marker = "(platform_machine != 'aarch64' and extra == 'desktop') or (sys_platform != 'linux' and extra == 'desktop')", specifier = ">=6.7" },
{ name = "pystray", marker = "extra == 'desktop'", specifier = ">=0.19" },
@@ -3448,11 +3448,11 @@ wheels = [
[[package]]
name = "pyasn1"
-version = "0.6.4"
+version = "0.6.5"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/a4/9a/23310166d960def5897e91fe20e5b724601b02a22e84ba1f94232c0b7f67/pyasn1-0.6.4.tar.gz", hash = "sha256:9c447d8431c947fe4c8febc4ed9e760bc29011a5b01e5c74b67025bd9fb8ce81", size = 151262, upload-time = "2026-07-09T01:12:33.988Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/88/7e/3c0da41061a2021cac7cd524fd57092adbe5b515e8bf9005702e366802e2/pyasn1-0.6.5.tar.gz", hash = "sha256:6b11616a6bcf3a40e635f082bb232fa57b5e0dd7f517bd7ddd69ec3794508a47", size = 155152, upload-time = "2026-10-27T06:32:49.125Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/9a/3b/6163796d69c3977d1e4287bea4a6979161cbbdd170ebb430511e8e1999ce/pyasn1-0.6.4-py3-none-any.whl", hash = "sha256:deda9277cfd454080ec40b207fb6df82206a3a2688735233cdcd8d3d565f088b", size = 84410, upload-time = "2026-07-09T01:12:32.92Z" },
+ { url = "https://files.pythonhosted.org/packages/19/1f/3eefd5c84c35cae44549ce1c7f7e58f7945b34f5a6bce07a135438522073/pyasn1-0.6.5-py3-none-any.whl", hash = "sha256:4017b0fce125096b8573b39c989fdb1a4b19cf761e683398184550fea0e66587", size = 84807, upload-time = "2026-10-27T06:32:48.045Z" },
]
[[package]]