Repository navigation
feat(security): require auth + rate limiting on job submission only - #4
Merged
Merged
Conversation
The API had no authentication at all. Anyone who could reach it could call
POST /process/{filename}, which launches a JVM per job against a pool of 4-8
threads with a queue of 100 — a hundred queued JVM launches decoding video.
The exposure is cost and availability, not data: the outputs are animal
coordinates.
Reworks the approach from the stale securityImprovement branch, which put HTTP
Basic on every endpoint. That would have broken the browser frontend, which
reads the list, thumbnail, status and result endpoints on page load and cannot
hold a credential without publishing it. It also stripped the datasource
defaults and required four environment variables with no fallbacks, so the app
would no longer start from a clean clone.
This scopes protection to the one call that costs something:
- POST /process/** requires HTTP Basic; every other route stays public.
- Stateless session policy, so each POST carries its own credentials. CSRF
stays disabled — there is no cookie or session to ride.
- Passwords are BCrypt, never {noop}. application.yml carries a hash of the
documented local credential (dev/dev, stated openly so the repo runs from a
clone); application-prod.yml requires APP_SECURITY_USERNAME and
APP_SECURITY_PASSWORD_HASH with no defaults, and userDetailsService() throws
a named error rather than starting with a blank credential.
- A per-caller fixed-window rate limit on submission, keyed on the
authenticated principal rather than the remote address — behind an ALB every
request shares a handful of source addresses. Default 10 per minute.
In-memory and per-instance; the comment says so, and what would need to
change to run more than one replica.
Verified against a running server: GET /api/videos 200 and status 404 without
credentials, POST 401 with none and 401 with a wrong password, 202 with
dev:dev, and the 11th submission in a window 429 while reads stay unmetered.
171 unit tests pass, up from 163.
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.
Replaces the approach on the stale
securityImprovementbranch. Closes the realgap without breaking the frontend or the clone-and-run flow.
The gap
The API had no authentication.
POST /process/{filename}launches a JVM per jobagainst a pool of 4–8 threads with a queue of 100 — anyone reachable could queue
a hundred JVM launches decoding video. The exposure is cost and availability,
not data; the outputs are animal coordinates.
Why not the original branch
It put HTTP Basic on
anyRequest(). That breaks the browser frontend, which readsthe list/thumbnail/status/result endpoints on page load and cannot hold a
credential without publishing it. It also stripped the datasource defaults and
required four env vars with no fallbacks, so the app would no longer start from a
clean clone. And it used
{noop}— plaintext password comparison.What this does instead
POST /process/**requires HTTP Basic. Every other route stays public.session to ride when credentials are sent explicitly per request.
{noop}.application.ymlcarries a hash of the documentedlocal credential (
dev/dev, stated openly so the repo runs from a clone).application-prod.ymlrequiresAPP_SECURITY_USERNAMEandAPP_SECURITY_PASSWORD_HASHwith no defaults, anduserDetailsService()throws a named error rather than starting with a blank credential.
hundred jobs. Per-caller fixed window, default 10/min, keyed on the
authenticated principal rather than remote address — behind an ALB every
request shares a handful of source IPs. In-memory and per-instance; the class
comment names that tradeoff and what would need to change for multiple replicas.
Verified against a running server
GET /api/videos(no creds)GET /process/{id}/status(no creds)POST /process(no creds)POST /process(wrong password)POST /process(dev:dev)171 unit tests pass, up from 163.
Note for the frontend
Salamander-Labs will need to send credentials on submission. Reads are unaffected,
so the page still loads and polls without one. Worth deciding whether a public
demo should let anonymous visitors submit jobs at all.