Skip to content

feat(security): require auth + rate limiting on job submission only - #4

Merged
konradkelly merged 1 commit into
mainfrom
feat/scoped-api-auth
Aug 13, 2026
Merged

konradkelly merged 1 commit into
mainfrom
feat/scoped-api-auth

Conversation

@konradkelly

Copy link
Copy Markdown
Owner

Replaces the approach on the stale securityImprovement branch. Closes the real
gap without breaking the frontend or the clone-and-run flow.

The gap

The API had no authentication. POST /process/{filename} launches a JVM per job
against 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 reads
the 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.
  • Stateless sessions; CSRF stays disabled, correctly — there is no cookie or
    session to ride when credentials are sent explicitly per request.
  • BCrypt, not {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.
  • Rate limiting, separately from auth. A valid credential can still queue a
    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

Request Result
GET /api/videos (no creds) 200
GET /process/{id}/status (no creds) 404 — not 401
POST /process (no creds) 401
POST /process (wrong password) 401
POST /process (dev:dev) 202
11th submission within the window 429, reads unaffected

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.

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.
@konradkelly
konradkelly merged commit 3435c92 into main Aug 13, 2026
2 checks passed
@konradkelly
konradkelly deleted the feat/scoped-api-auth branch August 13, 2026 08:14
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