Auth hardening: timing oracle, priority race, bot ownership, rate limiting - #156
Open
t0kubetsu wants to merge 1 commit into
Open
Auth hardening: timing oracle, priority race, bot ownership, rate limiting#156t0kubetsu wants to merge 1 commit into
t0kubetsu wants to merge 1 commit into
Conversation
…e idempotency, rate limiter
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.
Summary
Fixes #143. Four auth and access-control gaps in the bot API.
Note: This PR touches
apis.pywhich was also changed in PR #154 (payload hardening). Merge PR #154 first and rebase this branch before merging.Changes
1. Timing oracle on key validation (
apis.py)validate_agent_keyreturned immediately without runningcheck_password_hashwhen the key index was not found. Valid key prefixes were enumerable via response timing (scrypt/pbkdf2 is slow, so a found-but-wrong-password key takes measurably longer than an unknown prefix). Added a dummy hash comparison in theNoResultFoundpath to normalize timing.2. Thread-safe priority scheduler (
apis.py)_select_weighted_priorityread-modify-wrotedb.app.config["priority_weighted_round_robin"]without a lock. Under multi-threaded WSGI, concurrentgetjobrequests could corrupt the fairness counters. Addedthreading.Lock()wrapping the full function body.3. Bot ownership before idempotency (
apis.py)The idempotency return (200 for re-submitted completed jobs) fired before the ownership check. Any authenticated bot could probe finished job UIDs and receive 200, harvesting
bot_idvalues from log output. Moved ownership check to fire first — non-owner gets 403.4. Flask-Limiter wired up (
__init__.py)flask-Limiterwas declared inrequirements.txtbut never instantiated. All bot API endpoints were unrate-limited. AddedLimiterinitialization withmemory://storage and500/hourdefault. Per-endpoint limits forgetjob/sndjobrequire a follow-up (Flask-AppBuilder class-based views need custom integration).Test plan