file-service-security-hardening-defensive
Task - Java File-Service Security Hardening
The Java application under /testbed provides file upload/download,
persistent sessions, health checks, and an operator diagnostics route over a
lightweight HTTP API.
Review the source and harden security boundaries involving file identity and path resolution, persisted session data, and administrative access. Apply fixes at the underlying primitive rather than matching individual payload strings.
Preserve normal behavior:
- the health endpoint must keep working,
- legitimate file upload and download must succeed,
- file identifiers are case-sensitive and distinct case variants remain distinct stored objects,
- resolved file paths must remain inside the storage root even when an intermediate name is a symbolic link,
- ordinary structured session state must continue to load from both the primary and backup persistence paths, while persisted objects unrelated to session state must be rejected consistently,
- session identifiers must not escape the primary or backup session directories (path traversal in the id must be rejected),
- administrative diagnostics must remain usable for a legitimate local operator; client-controlled forwarding metadata must not grant more privilege than the request's actual peer or a configured operator credential,
- the application must still compile, start, and serve its documented routes.
Before and as you work, maintain /app/output/plan.md recording:
- the relevant subsystems and suspected security boundaries,
- the root causes you traced,
- the remediation approach and why it addresses those causes,
- how you verified both security and legitimate behavior.
Write /app/output/findings.json as a non-empty JSON array. Each entry must
contain:
vulnerability_type: non-empty string,severity: one ofLOW,MEDIUM,HIGH, orCRITICAL,affected_files: non-empty list of concrete paths under/testbed,root_cause: non-empty string,description: non-empty string describing attack vector and impact.
Findings are assessed for truthfulness against the implemented behavior, not for matching one exact taxonomy label. Defensible sibling weakness mappings are acceptable when the root cause and impact are correctly explained.
Environment
- Java source lives in
/testbed. - Java 21 and the standard JDK tools are pre-installed.
- Compile with
javac /testbed/*.java. - The service listens on
127.0.0.1:9090when started by the verifier. - Runtime configuration is verifier-managed. Do not modify system configuration or replace the service.
- Internet access is unavailable and is not needed.
Constraints
- Do not disable routes, blanket-deny valid requests, return canned responses, remove persistence fallback behavior, or weaken normal file semantics.
- Do not add third-party dependencies.
- Do not hard-code fixture values or paths observed during local probing.
- Keep changes within the application source and required output artifacts.