Harden API: SSRF guard, bearer auth, bounded caches, stateless scalin… - #4
Merged
Conversation
…g, tests+CI Phase 0 — correctness: single DAILY/ADMIN_LIMIT source, secrets-based tokens, awaited get_user_by_token, shared setup_bot_commands, README fixes. Phase 1 — security: SSRF allow-list on /stream /video-stream /info /playlist; Authorization: Bearer header (deprecated ?token= kept as fallback); pinned deps; Redis SCAN instead of KEYS. Phase 2 — stability: stdlib OrderedDict LRU+TTL BoundedCache for MEMORY_CACHE, LOCKS, stream job state; asyncio.Semaphore caps yt-dlp/ffmpeg spawns (YTDLP_MAX_PROCS). Phase 3 — tests+CI: pytest + fakeredis route-contract suite (TESTING=1 guards bot/cookie startup); GitHub Actions runs ruff + pytest. Phase 4 — scaling: stream job state in Redis (stateless API, scalable via WEB_CONCURRENCY / --scale); zero-dep /metrics + JSON logging; compose split into scalable api + single bot. Also: default BASE_URL to https; ignore runtime cache + pytest cache.
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.
…g, tests+CI
Phase 0 — correctness: single DAILY/ADMIN_LIMIT source, secrets-based tokens, awaited get_user_by_token, shared setup_bot_commands, README fixes.
Phase 1 — security: SSRF allow-list on /stream /video-stream /info /playlist; Authorization: Bearer header (deprecated ?token= kept as fallback); pinned deps; Redis SCAN instead of KEYS.
Phase 2 — stability: stdlib OrderedDict LRU+TTL BoundedCache for MEMORY_CACHE, LOCKS, stream job state; asyncio.Semaphore caps yt-dlp/ffmpeg spawns (YTDLP_MAX_PROCS).
Phase 3 — tests+CI: pytest + fakeredis route-contract suite (TESTING=1 guards bot/cookie startup); GitHub Actions runs ruff + pytest.
Phase 4 — scaling: stream job state in Redis (stateless API, scalable via WEB_CONCURRENCY / --scale); zero-dep /metrics + JSON logging; compose split into scalable api + single bot.
Also: default BASE_URL to https; ignore runtime cache + pytest cache.