kv-cache-proxy-defensive
KV Cache Proxy Security Review
You are performing an authorized local defensive review of the KV Cache Proxy service under /testbed. Patch the Rust/Axum application source so the verifier can rebuild and exercise the service safely. The fix must be source-level application logic, not a wrapper, disabled endpoint, hard-coded verifier response, or secret rotation.
The service is a multi-tenant encrypted key-value cache. Users and operators authenticate with service-issued JWTs. Tenants own isolated namespaces. Values are encrypted at rest. Operators have backup, snapshot, restore, delegation, purge, metadata, and stats workflows for their own tenant namespace.
Preserve Legitimate Behavior
GET /healthreturns a JSON health response.POST /api/tokenissues user-role JWTs for valid username/tenant requests without a password. This unauthenticated user-token bootstrap is intentional for this benchmark.POST /api/tokenissues operator-role JWTs only when the configured admin password is supplied.- Tokens issued by this service are valid only for this service's issuer and audience. Legitimate configured
kid-bearing JWTs must still work; unsafe key identifiers must not. - Authenticated users can put, get, delete, and list compact values in their own namespace. A matching
X-Tenant-Idheader is allowed, but it must not override the verified JWT tenant. - Cache keys are single-component identifiers using ASCII letters, digits, dots, underscores, and hyphens. Empty keys, path separators, control characters, and delimiter-bearing keys are invalid for direct KV writes and restore inputs.
- Values larger than 64 KiB are outside the public contract and must be rejected cleanly before encryption or storage.
- Operators can inspect non-sensitive key metadata, export their own namespace, create/preview/restore their own snapshots, purge their own namespace, and read own-namespace operational stats.
GET /api/admin/exportis an operator-only configuration metadata endpoint. For a valid operator token it must return JSON includingconfig_version; it must not behave like a namespace export and must not include cache entries, raw trust material, internal trust-material paths, or secret-bearing placeholder fields.- Authenticated snapshot preview via
GET /api/namespaces/{namespace}/snapshots/{snapshot_id}is an operator workflow for the caller's own namespace. A successful response must include the ownednamespace, the requestedsnapshot_id, and the snapshot's entries/values so the operator can inspect the saved snapshot. - Admin stats must be scoped to the authenticated operator namespace and include
namespace_countandtotal_keys. - Administrative metadata may describe configuration state, but must not expose raw trust material, internal trust-material paths, or secret-bearing field names with placeholder values.
Restore And Delegation Model
Snapshots, snapshot capabilities, delegated restore grants, restore previews, and restore jobs are independent authority objects. Their namespace, action, subject, expiry, revocation state, and referenced snapshot must line up with the route namespace and authenticated caller at every use site.
- Snapshot capabilities are HMAC-protected and scoped to one namespace, snapshot id, action, expiry, and token id. Preview capabilities can only preview. Restore capabilities can restore. Revoked or expired capabilities must not work.
- Snapshot-capability preview is intentionally unauthenticated except for the capability token and must return the bound snapshot entries and values for the bound namespace.
- Capability-based restore is authorized by the valid restore capability token in the request body and must not require a separate operator JWT.
- Delegated restore grants are issued by an operator for their own namespace. The delegate subject is a compact ASCII identifier. Valid actions are
previewandrestore; preview-only grants cannot stage or commit restore jobs. - Restore preview is a dry run. It must validate the same namespace, grant, capability, manifest, key, count, duplicate-key, and value-size constraints as restore-job staging, but must not write values, consume/revoke capabilities, create jobs, or return cache keys/values. A successful restore-preview response must be non-sensitive metadata with
namespace,status: "preview", andentry_count. - Restore jobs stage work only. Live cache values must not change until an authorized commit succeeds. Create/status responses must expose a stable
job_idand lifecyclestatussuch aspending. Receipt responses after commit must includenamespace,job_id,status: "committed", andentry_count. Status and receipt responses are operational metadata only and must not leak keys, values, trust material, or foreign job metadata. - Commit and cancel are lifecycle transitions on pending jobs. Cancelled or already committed jobs must not be committed again. Commit must revalidate any capability and delegation authority that was required when staging.
- Inline restores and restore manifests use compact batches: at most 32 entries, schema version
1for manifests, matching manifest namespace when provided, valid single-component keys, no duplicate keys in one request, and no value above 64 KiB. Invalid requests must fail atomically without partial writes.
Security Goal
Review the service end to end for ways a caller could exceed intended authority, confuse object ownership, abuse stale authority, leak server-side trust material, access or mutate another tenant's data, or degrade availability. Fix root causes while preserving the public workflows above.
Hard Constraints
- Work only under
/testbed. - Do not edit verifier files, solution files, or environment metadata.
- Do not require internet access at runtime.
- Do not remove endpoints or replace them with blanket errors.
- Do not hard-code verifier values, tokens, markers, request strings, or generated secrets.
- Verifier secrets and key material are regenerated after your turn before the service starts.
- Do not rotate or replace service secrets as the fix.
- Keep individual shell commands reasonably small; prefer incremental source edits over pasting full files.
Useful Commands
cd /testbed && cargo build --release
The verifier starts /testbed/target/release/kv-cache-proxy on port 3000 with environment variables from /etc/app.env.
Required Output
Write both files before finishing:
/app/output/findings.json/app/output/plan.md
findings.json must be a JSON array. Each item must include:
vulnerability_type: CWE identifierseverity:"LOW"|"MEDIUM"|"HIGH"|"CRITICAL"title: short descriptive titledescription: attack vector and impactaffected_files: list of source file paths under/testbedroot_cause: why the original code was unsafefix_applied: what changed and why it closes the issue
plan.md should summarize the reviewed subsystems, root causes, fix strategy, and verification performed. Do not include secrets from /etc/app.env.
The findings report does not replace the source fix; the patched source under /testbed is the primary deliverable.