Skip to content

Feat/hosted access auth - #2

Merged
kavishkartha05 merged 45 commits into
mainfrom
feat/hosted-access-auth
Nov 3, 2026
Merged

kavishkartha05 merged 45 commits into
mainfrom
feat/hosted-access-auth

Conversation

@kavishkartha05

Copy link
Copy Markdown
Owner

LOL

kavishkartha05 and others added 30 commits November 2, 2026 12:15
Caps, quota limits, reaper timings, SSRF and allowlist switches, and the
LLM benchmark flag, all configurable from the environment. The allowlist
and LLM flag default on/off according to AUTH_ENABLED.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Reject non-http(s) schemes, credentials, malformed URLs, and any target that
is or resolves to a loopback, private, link-local (incl. 169.254.169.254),
CGNAT, multicast, unspecified or reserved address, plus the IPv6 equivalents
(::1, fc00::/7, fe80::/10, IPv4-mapped, NAT64 and 6to4 with embedded private
IPv4). Legacy decimal, octal and hex IPv4 spellings are decoded before the
check, and one bad DNS record rejects the whole answer. Tests use a fake DNS
fixture so they never touch the network.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Connections go only to addresses validated by the SSRF check, so a second DNS
answer cannot rebind the name to an internal host. The Host header, TLS SNI
and certificate verification still use the original hostname. Redirects stay
off and environment proxies are ignored. The transport refuses to start if
httpx internals change, instead of silently going unpinned.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ALLOWED_TARGET_HOSTS is checked before any DNS lookup and compares whole
hostnames after lowercasing, trailing-dot removal and punycode, so
httpbin.org.evil.com, sub.httpbin.org and URL credential tricks do not
match. Wildcards, ports and paths are not valid entries. SSRF checks still
run for allowlisted hosts. Enforcement defaults to on when auth is enabled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The target is validated before the run row is created (422 with a readable
reason, no address in the message) and validated again right before
connecting. The addresses from that second check are passed to the engine,
which connects only to them, so a DNS answer that changes between accept and
connect fails the run without sending anything.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
num_requests <= 500, concurrency <= 20 and a new per-request timeout_s <= 10
are enforced in the request schemas from settings (also for the LLM request),
so every client is bound by them. The engine runs under asyncio.wait_for with
a 60 s wall-clock limit; a run that hits it is cancelled and marked failed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
At most 2 runs may be pending or running at once, and 1 per access code. Each
code and the app as a whole also have a daily budget (sum of num_requests
since 00:00 UTC; 2,000 per code and 10,000 overall by default). Everything is
computed from the runs table, so it survives restarts. Exceeding a limit
returns 429 with a readable message and a Retry-After header. The check and
the insert run under one lock. Quotas apply only when auth is enabled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Runs left pending or running longer than the wall-clock limit plus a grace
period (their worker died or was restarted) are marked failed, which also
frees their active-run slot. It runs once in the app lifespan before serving
and then every REAPER_INTERVAL_SECONDS; a failed pass is logged and retried.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The flag defaults to off when auth is enabled and on when it is not. When off,
authenticated callers get a 404 identical to an unknown route; callers
without a session still get 401. When on, the route gets the same protection
as the REST benchmark: SSRF and allowlist checks, pinned connections,
capped request counts, timeout, and the wall-clock limit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
GET /health now runs SELECT 1 with a timeout and returns 503 when the
database is unreachable. The body says only that the database is down; the
error type goes to the log, not to the public response.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
index_run now uses the run id as the document id, so a run's document can be
found by an exact doc_id filter; older documents are found by their text and
only deleted when the full run id is in it. The admin reset route removes the
documents of exactly the runs it is about to delete, before deleting them; if
Azure fails it returns 502 and keeps the rows so no orphan can be left.
Deletion is skipped when Azure Search is not configured.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A small FastAPI service (separate from the backend, since the backend must
refuse loopback targets) with latency_ms, jitter_ms, error_rate and
error_status query parameters. It has its own caps: delay limit with 422 on
excess, an in-flight limit with immediate 503, no body reads, a fixed tiny
response, GET/POST only and no docs endpoints. The Dockerfile runs it as an
unprivileged user with a connection limit and a health check.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add the guardrail variables and defaults to .env.example and a Guardrails
section to the backend README. A test asserts that no code hard-codes the
Azure index name, so a separate production index only needs AZURE_SEARCH_INDEX.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…d render script

Also replaces the last .map calls in RunsTable with explicit loops.
kavishkartha05 and others added 5 commits November 2, 2026 14:28
…ed ACR property)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kavishkartha05

Copy link
Copy Markdown
Owner Author

LGTM

kavishkartha05 and others added 10 commits November 2, 2026 16:05
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… parameter

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… Express

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kavishkartha05
kavishkartha05 merged commit 0509381 into main Nov 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant