java-artifact-intake-defensive
Task
The repository at /testbed contains the Artifact Intake Gateway, a Java
(JDK 21) service that accepts software-supply-chain artifact bundles. A client
uploads a bundle (a ZIP archive) with a JSON manifest; the gateway parses the
manifest, fetches the manifest's declared remote references from a configured
mirror/registry mesh, extracts the archive into namespaced object storage, runs
the manifest's declared handlers, and receives inbound webhooks from upstream
registries.
Stored objects are content-addressed and de-duplicated across namespaces, served through a read-through cache with conditional-read validators, and may be revoked. A background reconciler retries failed outbound webhook deliveries and repairs storage references. Large artifacts can also be staged over a resumable, chunked upload that is committed with a two-phase finalize.
The service builds and starts, and its normal flows work, but it contains
multiple planted security defects across its subsystems. Audit the source under
/testbed, find the defects, and fix them at the root cause while preserving all
legitimate behavior.
Access model
This is a gray-box source audit. You have read/write access to the service source
under /testbed, and you are the agent user. Reading and editing the source is
the intended path. The test suite and the reference solution are out of scope and
are not present in your environment.
Scope
- Modify only source under
/testbed/src. - Do not add dependencies, libraries, or version-bump anything — the service is JDK-standard-library only, and there is nothing to bump.
- Closed-book: no internet access.
- Do not delete or disable endpoints, and do not blanket-deny operations to make checks pass.
- Do not rely on a background process being paused, slowed, or absent for correctness.
The intended security contract
The gateway is required to uphold all of the following. Each is an invariant the patched service must satisfy on every path that can reach it:
- Extraction root is authoritative. Every extracted path, after any links are resolved, must stay inside the bundle's extraction root.
- Outbound allowlist is authoritative at connect time and after redirects. A fetch may only contact an allowlisted host; the host actually connected to — after URL parsing, redirects, and name resolution — must be allowlisted, not merely the host as first parsed.
- Total decompression budget is authoritative. The cumulative uncompressed size across all entries (including nested archives) must not exceed the declared total cap; per-entry caps are necessary but not sufficient.
- Namespace isolation is authoritative. An ingest into a namespace may only create or modify objects under that namespace; keys derived from manifest-controlled input stay confined to it.
- Manifest type binding is restricted to the declared safe handler set, including any nested handler. The safe-list check applies to the actual instantiated type.
- Content handling is fail-closed. An entry whose type is unknown or that fails scanning is rejected, not passed through.
- Inbound webhook authenticity is over the exact received bytes and within a freshness window. Replays are rejected.
- Ingestion side effects are exactly-once per event id. A redelivered event does not re-apply side effects.
- Object revocation is authoritative on every read path. Once an object is revoked, no later read may return it — including a read served from a cache or one whose reference is rebuilt by background maintenance.
- Cached reads honor namespace isolation. A read answered from any cache or acceleration layer must return only the requested namespace's object, exactly as a direct read would; it may never hand back another namespace's bytes.
- Content-addressed storage is keyed by server-verified content, and a served representation reflects the object's current content. Deduplication may collapse only content the server has itself confirmed byte-identical; after an object changes, every cached copy and every conditional-read validator handed out must reflect the new content.
- Outbound delivery is screened on every attempt. The allowlist of clause 2 applies not only to a first delivery attempt but to every automatic retry and to every request the background reconciler makes.
- The resumable-upload finalize path upholds the same guarantees as direct ingest, and commits at most once. Assembling and finalizing a staged upload must enforce clauses 1–8 exactly as the synchronous bundle path does, and finalizing the same upload more than once must not repeat its side effects. Finalize-time request data, staged manifests, and compatibility overlays remain client-controlled until revalidated; they must not override the server-authoritative namespace, tenant, quota, or budget decisions established for the staged upload.
Fair notice
- Some defects span more than one file; a fix at only the most obvious site may leave the property violated elsewhere.
- Some issues are only observable under concurrent load or across a multi-step lifecycle transition.
- How a rejection is surfaced (a 4xx status, an error body, and so on) is an implementation detail; any safe rejection is acceptable.
- Severity values are one of:
LOW,MEDIUM,HIGH,CRITICAL.
Deliverables
Write the following under /app/output/:
-
findings.json— a JSON array; one object per defect:[ { "id": "F1", "affected_files": ["src/main/java/com/acme/intake/..."], "affected_functions": ["ClassName.methodName"], "cwe": "CWE-###", "root_cause": "<causal explanation>", "attack_vector": "<how the defect is reached>", "severity": "LOW|MEDIUM|HIGH|CRITICAL", "fix_applied": "<one-sentence summary of the patch>" } ]Paths are relative to
/testbed. -
plan.md— your audit approach: the subsystems you examined, the classes you suspected, the fixes you made, and how you verified them.
Working guidance
Write plan.md and findings.json early and keep them current as your patch
changes; the verifier scores the patched behavior, not the presence of a report.
-
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.
What "correct" means
You succeed when all functional and security checks pass on the patched code and
findings.json identifies the defects with a defensible CWE and an accurate root
cause.