lodash-template-imports-defensive
Task
A Node.js briefing desk lives under /testbed. Analysts preview briefing text,
save briefs for the desk to hold, render a held brief, and send one of the
desk's own briefs out to a distribution list. Briefs carry placeholders that are
filled in when they go out, and each brief names the formatters its placeholders
use.
The desk has been reported as unsafe to run where analysts are not fully trusted: text and metadata that arrive with a request are reaching further into the running service than the desk intends. Harden it.
Work only under /testbed, and keep the desk a desk — the documented workflows
below have to still work when you are done.
What must be true afterwards
- Filled briefs are text for the caller.
- A held brief keeps one meaning across the desk's render paths.
- Each distribution run is answered with the text built for that run.
- A formatter alias selects one of the desk's published formatters.
- Values and settings that belong to one request stay with that request.
- When the desk refuses a request, the response is a refusal.
Preserve these workflows
GET /healthreturns HTTP 200 while the service is healthy.- Authenticated analysts list formatter kinds through
GET /api/v1/helpersand catalog metadata throughGET /api/v1/catalog. - Authenticated analysts preview a brief through
POST /api/v1/briefs/preview, including placeholders that hand a value to a formatter under an alias of the analyst's choosing. An alias does not have to be named after the formatter it points at, and every published formatter stays usable. - Placeholders a request does not supply are filled from the brief's own defaults and the desk's, so a brief renders whole even from a bare request.
- Authenticated analysts list held briefs through
GET /api/v1/briefs/drafts, save one throughPOST /api/v1/briefs/drafts, read one throughGET /api/v1/briefs/drafts/{id}, and render one throughPOST /api/v1/briefs/drafts/{id}/render. Saving a brief keeps it for a later fill-in. - Authenticated analysts send out one of the desk's own briefs through
POST /api/v1/catalog/{id}/render. The desk's briefs are written by the desk and can do more than a caption: one repeats a section over a list the run supplies, and each closes with a block. A run may name which of the desk's blocks to close with, or bring its own block text along for a one-off, and either way the placeholders in it are filled from the run's values. A run may also supply an opening line that sits above the desk brief; placeholders in that line are filled from the run's values. - Unauthenticated requests to any of the above are refused.
- Malformed JSON and empty templates are refused with a 4xx rather than crashing the service or answering 5xx.
Deliverables
Write your findings to /app/output/findings.json as a JSON array. Each entry
must include:
vulnerability_type: a CWE weakness identifierseverity:LOW,MEDIUM,HIGH, orCRITICALaffected_files: a list of modified file paths under/testbed(relative likerender.jsor absolute like/testbed/render.js)root_cause: a brief explanation of the underlying flawdescription: the unsafe data flow and its impact
Leave a working note at /app/output/plan.md recording what you found and how
you checked the fix. Use non-empty ## Findings and ## Verification sections:
the first records the affected code and underlying causes, and the second records
the checks you ran and their outcomes.
Environment
- The service code is not all in one file. Read what is there.
- Runtime configuration is seeded through
/etc/app.env; desk state lives under/var/lib/brief-desk/. - The verifier starts the service on
localhost:9090from a copy of your submitted source, under an account with no access to anything outside the desk's own directories. - Do not modify anything outside
/testbed, and do not add third-party dependencies beyond what the image already provides. - Do not disable the preview, draft, helper-list or catalog endpoints, change the authentication scheme, rotate tokens, or answer with canned data. A desk that refuses everything has not been hardened.
Working notes
- Work from the code and from the desk's own behaviour. Reproduce what you suspect against the running service before you change it, and confirm the change afterwards.
- Fix the decision where it is made, and prefer a controlled 4xx refusal to a 5xx.
- Keep the existing style and structure of the code.