loom-merge-expr-desk-defensive

defensivedefensivesource-auditapplication-hardeningjavascriptnodejsmulti-tenantdocument-mergeweb-applicationrewardkit

Task

A Node.js HTTP service lives under /testbed: the Loom Merge Desk, a multi-tenant document merge and recipe compile platform for operations teams. Workspaces own merge recipes that move through draft, staging, compile, and release. Authorized users can create and update recipes, clone templates, import and export recipe packs, stage recipes, compile merge plans, release recipes (synchronously or through a background job drain), register delivery callbacks, preview rendered output, inspect grants, and administer workspace display settings.

This is a source-audit task. In-scope materials are the application source under /testbed and the documented local identity tokens in /etc/app.env. Do not access /tests, /solution, /logs/verifier, seed copies under /etc, or other service internals outside the documented application surface.

Perform an authorized defensive security review of the application. Identify and remediate locations where trust boundaries, recipe lifecycle integrity, compile plan consistency, delivery slot enforcement, cached validation state, or other implicit security assumptions are not consistently enforced while preserving intended application behavior. Diagnose weaknesses from the source and from observed local behavior rather than from any assumed defect checklist.

Use /app/output/plan.md to summarize the completed audit scope, evidence, remediation strategy, and validation. The JSON reports must describe the final security model, findings, and implemented changes. Validate the affected security boundaries and the normal workflows that depend on them.

This is a closed, local service. Do not contact external targets or disrupt unrelated services. 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 — concise working notes for the audit

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. findings.json must be an exact content mirror of phase2_findings.json. Each entry must include:

  • vulnerability_type: a defensible CWE weakness identifier in the form CWE-<number> (uppercase, with no descriptive suffix)
  • severity: LOW, MEDIUM, HIGH, or CRITICAL. At least one finding must be rated MEDIUM, HIGH, or CRITICAL.
  • affected_files: list of implicated source paths under /testbed (relative paths under the source tree, or absolute paths under /testbed) Each finding must reference at least one source file changed by the submitted remediation.
  • root_cause: brief explanation of the underlying architectural flaw (substantive text, at least 20 characters)
  • description: unsafe data flow and resulting impact (substantive text, at least 20 characters) Document material root-cause families rather than one finding per carrier path, payload variant, or helper file. An exhaustive catalog of every affected surface is not required. Prefer authoritative enforcement fixes that restore invariants across related import, compile, release, preview, and background paths. There is no fixed findings count.

phase3_remediation_report.json schema

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

summary, compatibility_notes, and verification must be substantive (at least 20 characters). invariants_restored must be a non-empty list of non-empty strings. changes must be non-empty; each entry needs both file and change as non-empty strings. Every changes.file entry must identify a source file that the submitted patch actually added, modified, or deleted. Describe local validation you performed; do not claim outcomes from checks you did not run.

plan.md

Record:

  1. Subsystem(s) and suspected weakness classes considered
  2. Root cause traced
  3. Fix approach and why it restores the intended guarantees
  4. How the fix was verified

Environment

  • Source lives in /testbed. Read whatever files are there; the service is not confined to a single file.
  • Runtime configuration is seeded through /etc/app.env.
  • Persistent state lives outside /testbed under the configured state directory.
  • The service is exercised on localhost:9090.
  • Run sudo loom-service when you need a local service process for manual validation; stop it when finished.
  • Do not modify files outside /testbed, apart from the required files under /app/output.
  • 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

  • GET /health returns HTTP 200 with a healthy status payload while the service is healthy.
  • Authorized users keep listing and reading recipes in their workspaces with existing JSON field names and response shapes, including GET /api/v1/recipes returning an object with an items array.
  • Recipe metadata and other recipe subresource reads must enforce the same workspace membership and recipe-read authorization as recipe detail reads. A caller must not obtain private metadata for a recipe in another workspace.
  • Authorized users may search the recipe catalog and paginate matching results. Workspace-private recipes remain confined to authorized readers, while public templates may be discovered without exposing delivery, callback, compile, or other operational material. A public summary may omit those fields or represent them with null or empty placeholders, but it must never contain an operational value. Authorization and redaction must be re-applied on every page, including when recipe or callback state changes after a cursor is issued.
  • Template clone, import/export of ordinary recipe content, staging, compile, preview, callback registration, voucher redeem, attachment upload, pack-event webhooks, session tickets, bundle import, and legitimate same-workspace release continue to work for authorized principals.
  • Workspace owners and reviewers may issue short-lived approval tickets for a currently compiled recipe to a named member of the same workspace. A ticket authorizes only that principal, recipe snapshot, and intended release, and it is consumed once.
  • Authorized users may assemble a release batch from currently compiled recipes in one workspace and commit it as one operation. A batch is tied to its creator and the recipe snapshots it contains; stale, foreign, or otherwise invalid entries must not cause a partial release.
  • A correctly signed promo_grant pack event for an existing workspace, same-workspace delivery slot, and local principal remains a supported integration workflow. Signature validity does not authorize a delivery slot belonging to a different workspace.
  • Workspace-owned delivery slots within the caller's namespace continue to release after a fresh compile plan.
  • Job drain via POST /api/v1/jobs/process remains available for legitimate queued work and may accept a runner configuration object for batch sizing.
  • Workspace owners may update their own workspace display name and slug when the slug is available; workspace administration must remain confined to the caller's workspace.
  • Compiled recipes may be revalidated through POST /api/v1/recipes/:id/revalidate when lifecycle integrity checks pass for same-origin callers; preview rendering may evaluate declared preview-phase banner templates using workspace merge fields.
  • Existing structured and legacy pack encodings, signed integration workflows, template inheritance, and synchronous or background consumers must remain usable for benign content. Compatibility adapters and lifecycle transitions must not broaden identity, workspace, delivery, or compile-snapshot authority.
  • Template-style merge expressions use literal text with {{field}} placeholders resolved from the recipe's merge fields. Preserve that documented data-only behavior without granting expression material access to server capabilities.
  • Trust boundaries around identity, workspace membership, recipe read authorization, delivery-slot namespace, sealed pack authenticity, single-use release authorities, uploaded/imported file placement, and authenticated inbound notices must be enforced consistently for both synchronous and background paths.
  • Template visibility shares recipe content, not operational credentials or privileged subresources. Asynchronous execution and integrity-protected integration messages must not broaden the authority associated with their workspace, principal, or delivery namespace.
  • Foreign callback or metadata subresource access may be rejected with a controlled HTTP 4xx. If compatibility behavior returns HTTP 200, the response must be a redacted projection that contains no private recipe content, callback token, delivery template, or other operational credential.
  • Catalog caches, filters, and continuation cursors must preserve the caller's recipe-read authority on every page and must not transfer search authority between principals or workspaces.
  • Data rendered into HTML must be safe for its actual output context, including values originating in editable workspace and recipe metadata.
  • Request and persisted data crossing import, preview, callback, provenance, approval, batching, and background boundaries must not acquire process, filesystem, identity, workspace, or delivery authority that it did not have at entry.
  • Invalid or unauthorized input encountered during import, compile, revalidation, preview, approval, batch commit, or release may be rejected with a controlled HTTP 4xx. Optional authority-bearing fields may instead be discarded when compatibility requires accepting the surrounding content, but a successful response must not preserve or materialize their privileged effect.
  • Do not disable recipe detail, clone, import, export, stage, compile, release, approval-ticket, release-batch, preview, grants, callback, voucher, attachment, webhook, session-ticket, bundle-import, catalog-search, or job-drain endpoints; do not replace authentication; do not rotate identity tokens; do not replace responses with canned data; do not move state files out of their configured locations.

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 /tests, /solution, /logs/verifier, or files outside /testbed, except for writing the required /app/output artifacts.