Agent Wranglers

Data and secrets Required

Show short errors

Show visitors a short error with a reference number. Keep stack traces, queries and file paths in the server log.

How to do it

Catch every error in one place. Log the full detail with a random reference, and return a plain message with that reference. Turn off debug mode in production. For API error bodies, see no internal details.

Example

{ "error": "Something went wrong. Reference: 7f3c2a" }
// Express: one error handler, last in the chain
app.use((err, req, res, next) => {
  const reference = crypto.randomUUID().slice(0, 8);
  log.error({ reference, err });
  res.status(500).json({ error: `Something went wrong. Reference: ${reference}` });
});
# Python with Flask: 500 catches every error the code did not handle
@app.errorhandler(500)
def handle_error(error):
    reference = secrets.token_hex(4)
    app.logger.exception("reference=%s", reference)
    return {"error": f"Something went wrong. Reference: {reference}"}, 500

How to check

The agent sends broken input, such as a quote in a search box or invalid JSON to an API. The reply has no stack trace, query, path or version number.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers security testing playbook: https://agentwranglers.se/playbook/adversarial-testing/data-and-secrets/short-errors.