fix: hide GraphQL stack traces and messages in production (#16593)

Resolves [Code Scanning Alert
180](https://github.com/twentyhq/twenty/security/code-scanning/180).

- Normalize unexpected GraphQL errors in convertExceptionToGraphql to a
generic "Internal Server Error" instead of exposing exception.name
directly to clients.
- Only attach stack and response (original error message) in
development, so production responses don’t leak internal class names,
implementation details, or stack traces, while observability is
preserved via `ExceptionHandlerService`/Sentry.
- Keep behavior consistent with `convertHttpExceptionToGraphql`, which
also only exposes detailed response and stack information when `NODE_ENV
=== DEVELOPMENT`.
This commit is contained in:
Abdullah.
2025-12-17 22:29:40 +05:00
committed by GitHub
parent b0e256221a
commit c13b955a36
@@ -150,12 +150,14 @@ const convertHttpExceptionToGraphql = (exception: HttpException) => {
export const convertExceptionToGraphql = (exception: Error) => {
const error = new BaseGraphQLError(
exception.name,
'Internal Server Error',
ErrorCode.INTERNAL_SERVER_ERROR,
);
error.stack = exception.stack;
error.extensions['response'] = exception.message;
if (process.env.NODE_ENV === NodeEnvironment.DEVELOPMENT) {
error.stack = exception.stack;
error.extensions['response'] = exception.message;
}
return error;
};