~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
"""Direct path table for ``fastapi_app._is_multipart_upload_path``.
``BodySizeLimitMiddleware`` grants an upload-sized body cap (~600 GB by
default: 200 files x 3 GB) only when BOTH conditions hold
(``fastapi_app.py:772-776``): the request carries a ``multipart/``
Content-Type label AND the path returns True here. Neither half alone is
enough: an honestly ``multipart/``-labelled body on a non-upload path
falls through to the JSON cap, and so does an honestly JSON-labelled
body on a real upload path. Those negative controls are already pinned
in ``tests/web/test_body_size_limit.py`` (forged-label on a JSON route,
traversal- and lookalike-shaped paths such as
``/library/api/collections/42/upload/../../evil`` and
``/library/api/collections/42/uploadx``, plus the label-matters case at
``test_honest_json_on_an_upload_path_still_gets_the_json_cap``, :317).
What a forged ``multipart/`` label DOES buy is the upload cap on a path
this predicate accepts — the label costs nothing to fake, so on the label
side the boundary is entirely this path table. Every path that does not
get the upload cap falls to the JSON cap, and that cap is not uniform:
``/notes/`` gets the larger 100 MB ``_LARGE_JSON_BODY_PREFIXES`` cap
(``fastapi_app.py:648``, consumed at ``:785-789``) rather than the 16 MB
cap every other path gets.
What was never pinned directly is the predicate itself as an
authorization table: which exact path shapes carry the large-cap grant.
It is a security boundary expressed as string matching, so its edges
deserve a unit-level net independent of the middleware's streaming
behavior:
- exact-match entry (``/api/upload/pdf``) and the anchored regex for
collection uploads (single ``[^/]+`` segment id);
- near-misses that must NOT match: trailing slash, extra path segments,
a missing id segment and a present-but-empty one, prefix lookalikes,
junk BEFORE the upload prefix, case variants;
- the empty path.
One property of the anchors is worth stating rather than pinning: Python's
``$`` also matches immediately before a trailing newline, so
``"/library/api/collections/abc123/upload\n"`` satisfies this predicate.
That is not a hole in the grant table, because Starlette's own routing
shares it — ``compile_path`` builds ``"^" + ... + "$"`` and matches with
``.match()`` (starlette 1.3.1, the version this project pins via
``starlette>=1.3.1,<1.4`` — ``routing.py:124``, ``:159``, ``:242``) — so a
newline-suffixed path that this predicate accepts is routed to the same
upload endpoint the cap is meant for. Tightening one side without the
other is what would create a mismatch, which is why the note is here
rather than as an assertion.
The two anchors and the single-segment property are the load-bearing
ones: an unanchored or multi-segment-tolerant regex would silently widen
the multi-hundred-MB event-loop-stall grant (see the stall measurements
on ``_DEFAULT_MAX_JSON_BODY_SIZE`` in ``fastapi_app.py``) to whatever new
routes happen to share the prefix.
"""
import pytest
from local_deep_research.web.fastapi_app import _is_multipart_upload_path
class TestLargeCapGrantPaths:
@pytest.mark.parametrize(
"path",
[
"/api/upload/pdf",
"/library/api/collections/abc123/upload",
"/library/api/collections/550e8400-e29b-41d4-a716-446655440000/upload",
],
)
def test_exact_upload_routes_get_the_large_cap(self, path):
assert _is_multipart_upload_path(path)
class TestNearMisses:
@pytest.mark.parametrize(
"path",
[
# The two rows the trailing ``$`` is load-bearing for.
# Measured against the ``$``-stripped regex over all 17
# negative rows in this list: exactly these two start
# matching, and the other 15 are rejected for reasons ``$``
# has nothing to do with (not the ``/api/upload/pdf``
# frozenset member, not the ``/library/api/collections/``
# literal prefix, ``[^/]+`` unable to span a ``/``, or case).
# So dropping ``$`` is invisible to every row but these.
"/library/api/collections/abc123/upload/",
"/library/api/collections/abc123/upload/extra",
# Extra segments after the exact-match entry (this one is a
# frozenset non-member, not a regex-anchor case).
"/api/upload/pdf/extra",
# Two segments where the id should be: [^/]+ must not span /.
"/library/api/collections/a/b/upload",
# Missing id segment entirely.
"/library/api/collections/upload",
# Present-but-EMPTY id segment. Distinct from the row above:
# this one still has both slashes, so it is what catches a
# ``[^/]+`` -> ``[^/]*`` slip, which the missing-segment row
# alone would not (verified: it matches under ``[^/]*``).
"/library/api/collections//upload",
# Prefix lookalikes.
"/api/upload/pdfx",
"/api/upload/pd",
"/xapi/upload/pdf",
# Junk BEFORE the upload prefix. ``.match()`` anchors at the
# start by itself, so a bare match->search swap changes
# nothing and these rows stay green; what they catch is the
# regex rewritten WITHOUT the leading ``^`` and applied with
# ``.search()``. These two rows are the ONLY ones here that
# such a rewrite would widen — measured by driving all 17
# negative rows against ``/library/api/collections/[^/]+/upload$``
# with ``.search()``.
"/evil/library/api/collections/abc123/upload",
"/redirect/library/api/collections/abc123/upload",
# Case variants — path matching is case-sensitive.
"/API/UPLOAD/PDF",
"/Library/API/Collections/abc/upload",
# Non-upload routes that merely share a prefix with the API.
"/api/upload",
"/api/news/upload/pdf",
# Degenerate input.
"",
"/",
],
)
def test_lookalikes_do_not_get_the_large_cap(self, path):
assert not _is_multipart_upload_path(path)
class TestGrantShapeProperties:
def test_id_segment_matches_raw_percent_encoding_without_slashes(self):
# [^/]+ is intentionally permissive within ONE segment (ids are
# caller-generated); the boundary pin is "no literal slashes", not
# a charset. Pinned so tightening to a uuid charset is deliberate.
# NOTE: pinned at the STRING level only. To this predicate %2F is
# three opaque characters inside one segment, so these literal
# fixture strings match. On the wire, Uvicorn percent-DECODES
# scope["path"] (undecoded bytes live in scope["raw_path"]), so a
# request's %2F arrives at the predicate as a LITERAL slash and
# splits the segment — these assertions pin the predicate's own
# text handling, not the ASGI decoding layer above it.
#
# INVERTED PIN: this test FAILS if the predicate is ever hardened
# to reject raw %2F within a segment (e.g. by rejecting or
# decoding percent-escapes itself). That is deliberate — update
# this test then, it is not a regression.
assert _is_multipart_upload_path(
"/library/api/collections/collection%20name/upload"
)
assert _is_multipart_upload_path(
"/library/api/collections/col%2Flection/upload"
)