Skip to content

Commit dde791e

Browse files
committed
Sanitize error responses in UI REST API
Log full exception details server-side and return only the exception message to HTTP clients instead of the full stack trace.
1 parent efa7c73 commit dde791e

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

storm-webapp/src/main/java/org/apache/storm/daemon/ui/UIHelpers.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import jakarta.servlet.Servlet;
2626
import jakarta.ws.rs.core.Response;
2727
import jakarta.ws.rs.core.SecurityContext;
28-
import java.io.PrintWriter;
29-
import java.io.StringWriter;
3028
import java.util.ArrayList;
3129
import java.util.Collections;
3230
import java.util.Comparator;
@@ -494,13 +492,16 @@ public static String getJsonResponseBody(Object data, String callback, boolean n
494492
* @return Map to be converted into json.
495493
*/
496494
public static Map exceptionToJson(Exception ex, int statusCode) {
497-
StringWriter sw = new StringWriter();
498-
ex.printStackTrace(new PrintWriter(sw));
495+
LOG.error("HTTP {} error", statusCode, ex);
496+
String message = ex.getMessage();
497+
if (message == null || message.isEmpty()) {
498+
message = ex.getClass().getName();
499+
}
499500
return ImmutableMap.of(
500501
"error", statusCode
501502
+ " "
502503
+ HttpStatus.getMessage(statusCode),
503-
"errorMessage", sw.toString());
504+
"errorMessage", message);
504505
}
505506

506507
public static Response makeStandardResponse(Object data, String callback) {

0 commit comments

Comments
 (0)