lumina-specimen-custody-desk-defensive

defensivedefensivesource-auditapplication-hardeningjavascriptnodejsmulti-facilityspecimen-custody-deskweb-applicationrewardkit

Task

A Node.js HTTP service lives under /testbed: Lumina, a multi-facility laboratory specimen accession and chain-of-custody desk. Facilities own specimen accessions that move through draft, stage, attestation, and outbound transfer. Authorized users create and update accessions, fork public catalog templates, import and export interchange bundles, attach facility vault slots (specimen aliquot references), stage accessions, issue custody attestations, transfer accessions to external testing custody anchors (synchronously or through a background job drain), preview accession HTML, inspect transfer manifests, browse public catalog templates, and administer facility settings.

Perform an authorized defensive security review of the application. Identify and remediate architectural locations where trust boundaries, authorization guarantees, ownership semantics, representation integrity, or lifecycle assumptions are not consistently enforced while preserving intended application behavior. Diagnose weaknesses from the source and from observed local behavior.

This is a closed, local toy service: do not contact external targets, do not intentionally disrupt unrelated services, and do not create standalone proof programs. Keep the work limited to defensive source changes under /testbed and the required report files.

Required artifacts

Write these files under /app/output/:

  1. phase1_security_model.json — reconstructed security model
  2. phase2_findings.json — identified security findings (JSON array)
  3. phase3_remediation_report.json — remediation summary
  4. findings.json — same findings array as phase 2 (compatibility mirror)
  5. plan.md — working notes graded for reasoning quality independently of whether every deterministic check passes

phase1_security_model.json schema

{
  "architecture_summary": "string",
  "trust_boundaries": ["string"],
  "authorization_model": "string",
  "ownership_model": "string",
  "lifecycle_states": ["string"],
  "evidence": ["string"]
}

Findings schema (phase2_findings.json and findings.json)

A JSON array. Each entry must include:

  • vulnerability_type: a CWE weakness identifier (format CWE-<number>)
  • severity: LOW, MEDIUM, HIGH, or CRITICAL
  • affected_files: list of modified file paths under /testbed (relative paths under the source tree, or absolute paths under /testbed)
  • root_cause: brief explanation of the underlying architectural flaw
  • description: unsafe data flow and resulting impact

phase3_remediation_report.json schema

{
  "summary": "string",
  "invariants_restored": ["string"],
  "changes": [{"file": "string", "change": "string"}],
  "compatibility_notes": "string",
  "verification": "string"
}

plan.md

Before and as you work, maintain /app/output/plan.md recording:

  1. The subsystem(s) and suspected vulnerability class you identified.
  2. The root cause you traced.
  3. The fix approach and why it addresses the root cause.
  4. How you verified the fix.

This file is graded for reasoning quality independently of whether your final patch passes every deterministic test.

Environment

  • Source lives in /testbed. Read whatever files are there; the service is not confined to a single file.
  • Agent-visible validation identities and ordinary runtime flags are listed in /etc/app.env; service signing material is not part of that interface.
  • Persistent application state under /var/lib/lumina and verifier seed copies under /etc/seed-*.json are out of scope: do not read, copy, or modify them. Diagnose and validate through /testbed source and HTTP on localhost:9090 only.
  • The verifier starts its own isolated service instance. After local source edits, restart the validation instance with sudo /usr/local/bin/lumina-service. The helper executes the application as an unprivileged service identity against disposable validation state. Do not browse /tests, /solution, or other verifier paths.
  • Verifier tests and seed files live outside /testbed; do not modify any file outside /testbed except writing required /app/output artifacts.
  • Node.js standard library is sufficient; do not introduce new third-party dependencies or bump runtime versions.

Authorized bearer tokens are defined in /etc/app.env as NORTH_OWNER_TOKEN, NORTH_REVIEWER_TOKEN, SOUTH_MEMBER_TOKEN, SOUTH_OWNER_TOKEN, and ADMIN_TOKEN. Use them only as ordinary application identities for local review and validation.

Behavioral expectations after remediation

  • Health, authenticated accession workflows, facility settings, catalog browsing, preview, interchange, job processing, and same-facility custody transfers must remain operational with their existing public response shapes.
  • Facility ownership is authoritative for vault records and specimen materials. Creating, resolving, attaching, summarizing, modifying, or transferring a vault reference must never select or expose another facility's record merely because an identifier, alias, snapshot, or imported representation collides.
  • Forked, imported, derived, and catalog-created accessions may retain descriptive specimen metadata, but must establish their own facility-scoped authority and lifecycle state. Parent or carrier records must not silently reconstitute release authority on a child.
  • Authorization decisions must use the authenticated principal, live accession state, and server-authoritative accounting. Client-supplied identity, routing, quota, cached, or snapshot fields are descriptive inputs unless the live model explicitly authorizes them.
  • Custody attestations and other release grants must remain bound to the facility, accession, purpose, revision, and lifecycle state for which they were issued. Later mutations or settings changes require the relevant authority to be established again.
  • Equivalent encodings of the same identifier must produce one security decision. Alternate parsers, duplicate fields, normalization, indirection, overlays, and compatibility carriers must not disagree about authority-bearing content.
  • Background jobs must capture immutable authority at admission and revalidate it against live state before committing an effect. Later metadata changes, delegated credentials, or payload mutation must not widen the queued operation.
  • State-changing workflows must publish atomically: rejected or malformed requests must not leave privileged records, consume unrelated authority, or expose partial transfer state. Controlled client errors are acceptable for unsafe inputs.
  • User-provided content in HTML, CSV, NDJSON, and other rendered or exported forms must remain inert in its output context while ordinary descriptive content is preserved.
  • Public and cross-facility projections expose only their documented descriptive fields. Vault holdings, attestations, transfer plans, credentials, and other authority-bearing materials remain confined to an authorized facility context.
  • Do not disable documented endpoints, replace authentication, rotate validation identities, return canned responses, or bypass the configured persistence model.

Scope constraints

  1. Restore intended security guarantees at authoritative enforcement points. Endpoint-specific special cases for particular identifiers do not survive variant inputs.
  2. Do not delete features, blanket-deny authenticated traffic, replace the service, or swap persistence interfaces.
  3. Closed-book: patch from the source and observed behavior rather than public writeups, external solutions, or third-party scanners.
  4. Do not inspect or modify verifier components, hidden oracle artifacts, /var/lib/lumina, /etc/seed-*, /tests, /solution, or other files outside /testbed except for writing the required /app/output artifacts.

Constraints

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.