Repository navigation
Feat/hosted access auth - #2
Merged
Merged
Conversation
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.
…es, Key Vault, SWA)
…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>
Owner
Author
|
LGTM |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LOL