Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

## [Unreleased]

## [0.5.3] - 2026-11-06

Security release. Upgrade if your embedding-cache `backend` URL carries a password.

### Security
- **The embedding-cache backend URL is no longer logged with its credentials.** On every
successful connect, the `embedding_cache.connected` INFO line printed `backend` verbatim,
so a `redis://:<password>@host:port/db` URL put the password in the container log (and in
any log pipeline collecting it). The `FATAL:` stderr message on a failed startup echoed
the same URL. Both now go through `redact_backend_url()`, which keeps scheme, host, port
and db and drops the userinfo, every other query parameter (redis-py accepts
`?password=`) and the fragment. The userinfo ends at the last `@` before the first `?` or
`#`, so a password with an unencoded `/` or `@` is still removed. If any `@` is left after
that (in a query value such as `?password=a@b`, in the fragment, or after a `?`/`#` inside
the password), the URL is ambiguous and is logged as `scheme://<redacted>`.
- **The `FATAL:` message no longer quotes arbitrary exception text.** redis-py's own errors
(which name only host:port or the socket path) are still shown. Any other exception, such
as urllib's `ValueError` for a bad port, which quotes the port fragment of a malformed URL
and so can carry part of a password, is reduced to its type. The redis-py text is withheld
too, and the message says to percent-encode the password, whenever the URL isn't clean:
when the redacted form has no host (`<redacted>`, or a URL that doesn't start with a valid `scheme://`, which redis-py
still parses for `unix:` and uses the whole remainder, userinfo included, as the socket
path), or when the userinfo has spilled into what redis-py reads as host, port or path
(the text before the URL's last `@` is not the userinfo the URL parser found, as with a
password holding `@` then `/`).
- **certifi:** the lockfile now pins 2026.10.23 (PYSEC-2026-4320, fixed in 2026.10.18). The
image and CI don't install from the lockfile; they resolve the newest certifi at build
time, which already includes the fix.
- If you ran 0.5.2 or earlier with a password in the backend URL, treat that password as
exposed to whatever stores your container logs, and rotate it after upgrading.

## [0.5.2] - 2026-10-07

Dependency release. Picks up fastapi 0.142.2 for the published image. p2 of
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ollama-queue-proxy"
version = "0.5.2"
version = "0.5.3"
description = "Drop-in HTTP proxy for Ollama with priority queuing, per-client auth, and model-aware failover"
readme = "README.md"
license = { text = "MIT" }
Expand Down
2 changes: 1 addition & 1 deletion src/ollama_queue_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# This drifted twice before the check existed: `__version__` stuck at 0.3.1 through
# v0.3.2, and at 0.4.0 through v0.5.0, while `main.py` advertised 0.2.0 to every
# OpenAPI consumer from v0.3.0 onward without ever being bumped.
__version__ = "0.5.2"
__version__ = "0.5.3"
86 changes: 84 additions & 2 deletions src/ollama_queue_proxy/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import hashlib
import json
import logging
import re
import time
from urllib.parse import parse_qs, urlsplit

import redis.asyncio as aioredis
from redis.exceptions import RedisError

from .config import EmbeddingCacheConfig

Expand All @@ -25,6 +28,82 @@
errors: dict[str, int] = {}


_SCHEME_RE = re.compile(r"[A-Za-z][A-Za-z0-9+.-]*")


def redact_backend_url(url: str) -> str:
"""Return the backend URL with credentials removed, for logs and error messages.

Keeps scheme, host, port and db (path, or the ``db`` query parameter); drops the
userinfo, every other query parameter (redis-py accepts ``?password=``) and the
fragment. Works on the raw string rather than ``urlsplit``, whose netloc ends early
when a password holds an unencoded ``/``:

- the userinfo boundary is the LAST ``@`` before the first ``?`` or ``#``;
- if an ``@`` is left anywhere after that (in the query, the fragment, or past a
``?``/``#`` inside the password), the split is ambiguous and the whole location
is replaced with ``<redacted>`` rather than guessing a host.
"""
scheme, sep, rest = url.partition("://")
# A "scheme" that isn't one means the first "://" sits inside the userinfo of a URL
# written without one (redis-py still parses "unix:..."), so it can hold password text.
if not sep or not _SCHEME_RE.fullmatch(scheme):
return "<unrecognised backend URL>"
cut = min((i for i in (rest.find("?"), rest.find("#")) if i != -1), default=len(rest))
location, tail = rest[:cut], rest[cut:]
location = location.rpartition("@")[2]
if "@" in location or "@" in tail:
return f"{scheme}://<redacted>"
query = tail[1:].partition("#")[0] if tail.startswith("?") else ""
db = parse_qs(query).get("db", [""])[0]
suffix = f"?db={db}" if db.isdigit() else ""
return f"{scheme}://{location}{suffix}"


def _userinfo_bled(url: str) -> bool:
"""True when the URL's userinfo may have spilled into what redis-py parses as host,
port or path: the raw text before the LAST ``@`` after ``://`` is not exactly the
userinfo ``urlsplit`` found (it stops the netloc at the first ``/``, ``?`` or ``#``).
A password holding ``@`` then ``/`` keeps an ``@`` in the netloc, so "is there an
``@`` in the netloc" is not enough.
"""
scheme_sep, after = url.partition("://")[1:]
if not scheme_sep:
# No "://": redis-py still parses "unix:..." and "unix:/..." and uses the whole
# remainder, userinfo included, as the socket path. Nothing to compare against,
# so any "@" fails closed.
return "@" in url
if "@" not in after:
return False
try:
netloc = urlsplit(url).netloc
except ValueError:
return True
return netloc.rpartition("@")[0] != after.rpartition("@")[0]


def _startup_error_detail(url: str, exc: Exception) -> str:
"""Describe a startup failure without echoing anything that could be a credential.

redis-py's own errors name only host:port or the socket path. Anything else, such as
urllib's ``ValueError`` for a bad port, can quote part of a malformed URL, so only
the exception type is given. redis-py's text is withheld too whenever the URL is not
clean: ``redact_backend_url`` could not name a host (unrecognised or ``<redacted>``),
or the userinfo bled into host, port or path (``_userinfo_bled``). Then redis-py's
host:port or socket path can hold password characters.
"""
redacted = redact_backend_url(url)
unclean = redacted == "<unrecognised backend URL>" or redacted.endswith("://<redacted>")
if unclean or _userinfo_bled(url):
return (
f"{type(exc).__name__} (detail withheld: the URL may hold an unencoded "
"credential; percent-encode reserved characters in the password)"
)
if isinstance(exc, RedisError):
return f"{type(exc).__name__}: {exc}"
return type(exc).__name__


def _canonical_json(obj) -> bytes:
return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode(
"utf-8"
Expand Down Expand Up @@ -79,11 +158,14 @@ async def startup(self) -> None:
socket_connect_timeout=self._cfg.connect_timeout,
)
await self._client.ping()
logger.info("embedding_cache.connected backend=%s", self._cfg.backend)
logger.info(
"embedding_cache.connected backend=%s", redact_backend_url(self._cfg.backend)
)
except Exception as e:
print(
f"FATAL: embedding cache startup failed — could not connect to "
f"'{self._cfg.backend}': {e}. "
f"'{redact_backend_url(self._cfg.backend)}': "
f"{_startup_error_detail(self._cfg.backend, e)}. "
"Fix the backend address or set embedding_cache.enabled: false.",
file=sys.stderr,
)
Expand Down
Loading
Loading