Your AI Assistant Won't Save You from Verbose Error Messages
Von Seaworthy · 25. September 2026
Photo by Angelo Abear on Unsplash
I have seen this pattern too many times. A developer uses an AI coding assistant to scaffold a new API endpoint. The assistant writes clean, working code. The endpoint returns a helpful error message when something goes wrong. Then someone probes the endpoint with a malformed request, and the response includes a full stack trace, a SQL query, or a file path. The assistant did not warn about this. It rarely does.
Verbose error messages are a data exposure problem. They leak implementation details, internal paths, database schema, library versions, and sometimes secrets. Attackers use this information to map your system and craft targeted attacks. Yet developers who rely on AI assistants often skip the security basics because the code works. That needs to change.
Here is a typical example of the problem. This is a Node.js Express handler that catches an error and sends the full error object to the client.
app.get('/user/:id', async (req, res) => {
try {
const user = await db.query('SELECT * FROM users WHERE id = ?', [req.params.id]);
if (!user) throw new Error('User not found');
res.json(user);
} catch (err) {
res.status(500).json({ error: err.message, stack: err.stack });
}
});
The response on failure might look like this:
{
"error": "ER_BAD_FIELD_ERROR: Unknown column 'id' in 'where clause'",
"stack": "Error: ER_BAD_FIELD_ERROR... at Query.Sequence... at /app/node_modules/mysql/lib/protocol/sequences/Query.js:123:45"
}
That response tells an attacker you use MySQL, the exact table and column names, and the file path of your dependencies. That is a gift.
The fix is not complicated. Return a generic message to the client. Log the detailed error on the server. Here is the corrected handler.
app.get('/user/:id', async (req, res) => {
try {
const user = await db.query('SELECT * FROM users WHERE id = ?', [req.params.id]);
if (!user) throw new Error('User not found');
res.json(user);
} catch (err) {
console.error('Database error:', err); // full details in server logs
res.status(500).json({ error: 'An unexpected error occurred. Please try again later.' });
}
});
Now the client learns nothing useful for exploitation. The developer still gets the full context in logs.
Why does this keep happening? AI coding assistants are trained on public code, and much of that code is written for tutorials, quick prototypes, or internal tools where verbose errors are convenient. The assistants optimize for getting the happy path working. They do not consistently apply security review. When you ask for an API endpoint, you get a working endpoint, not a hardened one.
I am not saying AI assistants are useless. They save time. But they are not a substitute for knowing the basics. Error handling is a basic. If you skip it because the code compiles, you are building on sand.
The same problem appears in other frameworks. Python Flask with app.debug = True in production will send the Werkzeug debugger, which allows code execution. Django with DEBUG = True leaks settings and URLs. Ruby on Rails in development mode shows detailed error pages. AI assistants often generate code that sets these flags without warning.
Framework defaults are not your friend here. Each ecosystem has its own conventions for how much error detail becomes visible to the outside world. In Express, the default error handler in development mode sends the stack, and many tutorials leave NODE_ENV unset. In Spring Boot, the server.error.include-stacktrace setting defaults to never in recent versions, but older guides tell you to enable it for debugging and never mention turning it back off. In ASP.NET Core, the developer exception page is wired up automatically in the development environment, and it will happily show you the full call stack, query parameters, and cookie values. If your deployment pipeline does not set the environment correctly, that page goes live. AI assistants copy these patterns because they appear in the training data, not because anyone weighed the risk.
There is another layer that many teams miss. Error messages often flow into other systems before a human ever sees them. A client-side logger might ship them to a third-party monitoring service. A retry queue might store them for diagnostics. An API gateway might echo them into its own logs. If your handler attaches the raw error object to a response body, that object can travel further than intended. The fix is the same: shape the error at the boundary. Decide what leaves your process, and treat everything else as internal.
Check your production configuration. Turn off debug modes. Use environment variables to control error verbosity. Never let the client see a stack trace. Log everything server-side, but sanitize what goes out.
Here is a quick checklist for any endpoint you build with AI help:
- Catch all exceptions and return a generic message with an appropriate status code.
- Log the full error with a request ID so you can correlate client reports with server logs.
- Disable debug modes in production. Verify the actual runtime config, not just the code.
- Review generated error handlers. AI assistants often forget to differentiate between development and production.
- Test with malformed input to see what leaks.
Verbose errors are not a feature. They are a vulnerability. Treat them that way.
If you want a tool that helps catch this kind of issue automatically, Seaworthy is a security platform that scans code and configurations for common exposure patterns.
Dieser Artikel wurde von KI generiert und fasst öffentlich verfügbare Quellen zusammen.
Seaworthy scannt dein Repository nach den Problemen, die in Artikeln wie diesem behandelt werden.
Sicherheitslücken, offengelegte Geheimnisse und Fehlkonfigurationen — erkannt, bevor du bereitstellst. Kostenlos, kein Konto nötig.