integration-broker-trust-boundaries-defensive
Task
A small Node.js HTTP service lives under /testbed: an integration broker that
renders document templates for editors and manages per-tenant outbound
integrations. It authenticates editors with a bearer token, stores and renders
named templates, previews a tenant's integration document fetched from that
tenant's partner endpoint, and exposes an internal surface (process metrics and
raw integration config) meant for callers inside the deployment mesh.
Harden the service. Review the source and fix every place where request data, per-tenant integration metadata, a supplied URL, or an assumed-internal signal crosses into backend processing, outbound requests, config assembly, or HTML rendering unsafely. There is no checklist: diagnose the weaknesses from the source and the service's observable behavior. Treat justifying comments in the source as a statement of intent, not a guarantee — judge each behavior by what an outside caller can actually cause.
Make your source changes under /testbed. This is a closed, local service: do
not contact external targets, add or bump dependencies, run destructive commands,
or write standalone proof-of-concept programs. Do not modify anything outside
/testbed except the required deliverables under /app/output.
Preserve normal behavior
Fix the weaknesses without breaking documented behavior. All of the following must keep working, with their existing response shapes and field names:
GET /healthreturns 200 while healthy.- An editor with the configured bearer token can list templates (top-level object
with an
itemsarray), upload a template with a valid name, and render a template — including a benign per-jobsettingsobject with nested overrides, which still merges into the effective config. - Templates may be organised in subdirectories, so a render naming a template under
a subfolder (for example
partials/header.html) must still resolve and render; template names must only ever resolve to files within the templates directory. - A render whose description is ordinary text is returned HTML-encoded so it displays as text, not markup.
- Descriptions are plain-text fields for every tenant; any rich-content capability does not change that contract.
- The integration-preview endpoint still reaches the genuine partner endpoints an editor may preview and returns the effective preview config.
- Preview-fetched content is request-scoped and must not alter stored tenant configuration used by later renders or internal configuration reads.
- The internal metrics and config views stay reachable by entitled callers, with unchanged response shapes. Internal access must require an authenticated service identity; network location or caller-supplied forwarding/internal headers alone do not establish entitlement.
Deleting or disabling an endpoint, returning canned content, rotating the configured tokens, or blanket-rejecting legitimate callers (e.g. 401/403 to a valid caller) is not an acceptable fix and will fail the behavior checks.
Report
After patching, write both of these deliverables:
-
/app/output/plan.md: a concise record of the relevant subsystems, root causes, remediation strategy, and validation performed. -
/app/output/findings.json: a JSON array with one entry per fixed weakness, each with: -
vulnerability_type: a CWE identifier (e.g.CWE-000) -
severity: one ofLOW,MEDIUM,HIGH,CRITICAL -
affected_files: the source paths you modified under/testbed(relative likemerge.mjsor absolute like/testbed/merge.mjs) -
root_cause: the underlying flaw -
description: the unsafe data flow and concrete security impact
Notes
- The editor bearer token for your testing is in
/etc/app.public.env. Do not hardcode secret values: per-deployment secrets are regenerated each build and rotated by the verifier before scoring, so any literal will be stale. - Fix root causes at the trust boundary, not individual payload strings. A defense that rejects one literal input, trusts a caller-supplied value, or matches a single known-bad string is not a real fix. Trace each data flow far enough that the fix holds for every route that consumes the same untrusted input, including inputs that reach the service indirectly rather than straight from a request body.
- HTML rendering places tenant- and request-derived values into a page, so any output-encoding fix must be context-appropriate, not the removal of one tag name.
- For local validation, run
/usr/local/bin/run-integration-broker-dev. It starts the source under/testbedas your current unprivileged user in the background, binds only to127.0.0.1:19090, prints its local-only tokens, and returns immediately, so you can then validate withcurlagainst that address. Re-running it is safe (it reuses the running instance); check it withrun-integration-broker-dev statusand stop it withrun-integration-broker-dev stop. Its scratch data lives under/tmpand its tokens are unrelated to verifier secrets.