Security rules

NGB069: Reflected XSS in server responses

Traces request data (query string, route parameters, body, cookies, path) into raw response bodies written by Express / Node server code — res.send(), res.write(), res.end() — when the response is HTML (Express sends strings as text/html by default).

Property Value
Rule ID NGB069
Category Angular SSR security
Default severity high
CWE CWE-79
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Traces request data (query string, route parameters, body, cookies, path) into raw response bodies written by Express / Node server code — res.send(), res.write(), res.end() — when the response is HTML (Express sends strings as text/html by default). Responses that declare a non-HTML content type (res.type('json'), Content-Type: text/plain), JSON responses (res.json(), objects), and values passed through an HTML escaping function (escape-html, he.encode, _.escape, DOMPurify) are not reported. Rendering through Angular SSR is not affected: Angular escapes interpolations.

Why it matters

Server routes next to the Angular SSR engine — error pages, OAuth callbacks, health and preview endpoints — often build HTML by string concatenation. res.send(<p>No results for ${req.query.q}</p>) executes any <script> the attacker places in the link in your origin, with access to cookies that are not HttpOnly, session storage, and every API the user can call. The Angular sanitizer never sees these responses.

Detection behavior and supported patterns

  • res.send(v), res.write(v), res.end(v) on Express / Node responses (also res.status(400).send(v) chains and untyped (req, res) handlers)
  • Sources: req.query, req.params, req.body, req.path, req.url, req.originalUrl, req.cookies
  • Not reported: res.json(), non-string values, responses with a non-HTML Content-Type set in the chain or earlier in the handler, values passed through an escaping function

Example

TypeScript
app.get('/search', (req, res) => res.send(`<p>No results for ${req.query.q}</p>`));

Safer alternative

TypeScript
import escapeHtml from 'escape-html';app.get('/search', (req, res) => res.send(`<p>No results for ${escapeHtml(String(req.query.q))}</p>`));

Remediation

Return data as JSON (res.json({ q })) and render it client-side, or escape every request-derived value for HTML (escapeHtml(q) from escape-html) before building markup. Set an explicit Content-Type and a restrictive CSP on server-generated pages.

False-positive considerations

  • Responses served with X-Content-Type-Options: nosniff and a non-HTML type set elsewhere are not exploitable; set the type in the handler to make it visible.

Known limitations

  • Content types set by middleware or in another function are not seen; such responses may be reported although they are not HTML.
  • Template engines (res.render()) are not analyzed here; server-side template injection is NGB079.

References

Run it

Shell
ngbastion explain NGB069