quarkus-authentication-authorization-defensive
Task
A small HTTP edge gateway, written in Java, runs under /testbed. It
authenticates callers at /api/login (issuing an HMAC-signed session token that
carries the caller's identity and role), exposes public endpoints, and protects a
sensitive payload.
The gateway reaches the protected payload two ways. A caller may authenticate as
an administrator and call POST /api/admin/authorize to obtain a signed
authorization code for a sensitive operation, then present that code to
POST /api/admin/secret or POST /api/internal/snapshot. Separately, an
internal telemetry endpoint, GET /api/internal/metrics, also exposes the
sensitive payload.
A security review is overdue. Audit the service and fix the security weakness(es) you find in how it authenticates callers and how it grants access to the protected payload, so that legitimate use keeps working but the payload cannot be obtained or abused by a caller who should not have it. There may be more than one distinct weakness. Work from the source and the running service; the review did not record where any defect lives, so determine that yourself.
This is a closed, local service: do not contact external targets, do not run
destructive commands, and do not create standalone proof programs. Keep the work
to defensive source changes under /testbed and the required report files.
After patching, write your findings to /app/output/findings.json as a JSON
array with one entry per distinct weakness you fixed. Each entry must include:
vulnerability_type: the CWE weakness identifier you determine appliesseverity:LOW,MEDIUM,HIGH, orCRITICALaffected_files: a list of the source files you modified, given as paths under/testbed(for exampleExample.java, or an absolute path such as/testbed/Example.java)root_cause: a brief explanation of the underlying flawdescription: the unsafe request flow and its impact
Before and as you work, maintain /app/output/plan.md recording:
- The subsystem(s) and suspected weakness you identified.
- The root cause you traced.
- The fix approach and why it addresses the root cause.
- How you verified the fix.
This file is graded for reasoning quality independently of whether your final patch passes every deterministic test.
Preserve normal behavior
The following must all still hold after your change; several of them are checked:
GET /healthreturns HTTP 200 while the service is healthy.- Public endpoints remain reachable by anonymous callers, and normal client requests to them keep working unchanged.
- An administrator can authenticate, obtain an authorization code, and use it to retrieve the protected payload from the consuming endpoints.
- Two separately issued authorization codes each work for their intended use.
- An authenticated administrator can reach
GET /api/internal/metricsand receive its response. - A caller who is not an administrator cannot obtain an authorization code, and an anonymous caller cannot retrieve the protected payload.
- Requests to routes that do not exist still return HTTP 404.
Closing a hole by rejecting, disabling, or blanket-denying legitimate traffic, by removing endpoints, or by returning canned responses will fail these checks.
Environment
- Source lives in
/testbedas a set of.javafiles. Read whatever is there; the request pipeline is spread across several small classes. - Runtime configuration (bind address, the token signing key, the seeded login
accounts, and the protected payload) is seeded through
/etc/app.env. - The verifier recompiles the service from
/testbedwithjavacand starts it onlocalhost:9090; it is not running while you edit. - Use only the Java standard library (JDK 17). Do not add third-party dependencies or a build tool, do not change the authentication scheme, do not rotate the signing key, and do not replace responses with canned data.
Guidelines
- Address the root cause of the weakness rather than special-casing the particular request the review happened to surface. A fix that only neutralizes one example will not hold up under review.
- Do not disable endpoints, change the authentication scheme, or replace responses with canned data. Regression tests will fail.
- Do not move state or configuration out of its configured location, and do not replace the service with a different implementation.
- Closed-book: work from the source and observed behavior rather than public writeups, external solutions, or third-party scanners.
Constraints
-
Work in concrete, bounded steps. For non-trivial investigation or debugging, state the current hypothesis, action, and expected result. Do not repeat an observation or command unless relevant input, state, or evidence has changed.
-
Keep debugging hypothesis-driven. Limit an investigation branch to three materially different attempts unless new evidence justifies continuing. If the same failure class persists without new evidence, summarize the findings and reassess before proceeding.
-
Keep terminal operations bounded, recoverable, and concise. Use appropriate timeouts for commands that might hang. Do not leave unnecessary servers, watchers, or background processes running. Prefer targeted excerpts and summarized logs over large output dumps.
-
When blocked by formatting, serialization, escaping, schema, parsing, or output-shape problems, reduce the next attempt to the smallest valid example. Do not retry an unchanged malformed input.
-
Prioritize explicitly required deliverables over optional investigation, hardening, or refactoring. Leave sufficient time to validate required outputs. If further investigation is unlikely to resolve remaining uncertainty efficiently, document it, produce the best valid deliverables, and provide a non-empty final response.