From 4873e390179dd0941a5bbee15fed1824bb7886d7 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 24 May 2026 11:29:43 -0500 Subject: [PATCH] Fix remediation table rendering by emitting valid JSON Struts' escapeJavaScript escapes a single quote as \' which is not a valid JSON escape sequence and breaks JSON.parse for the remediation DataTable when a value contains a quote. Add a jsonEscape() helper backed by Jackson's JsonStringEncoder and use it for the string values rendered in vulnsJson.jsp. --- .../WEB-INF/jsp/remediation/vulnsJson.jsp | 47 +++++++++---------- .../fuse/actions/remediation/OpenVulns.java | 15 ++++++ 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/WebContent/WEB-INF/jsp/remediation/vulnsJson.jsp b/WebContent/WEB-INF/jsp/remediation/vulnsJson.jsp index cf300e30..fe6d9e8d 100644 --- a/WebContent/WEB-INF/jsp/remediation/vulnsJson.jsp +++ b/WebContent/WEB-INF/jsp/remediation/vulnsJson.jsp @@ -1,30 +1,29 @@ <%@page import="org.apache.struts2.components.Include"%><%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %><% boolean first=true;%>{ "data" : [ <% if(first){ first=false;}else{ %>,<%}%>[ "", -"" , -"\n", -" \n", -"" , +"" , +"\n", +" \n", +"" , "Out for Verification", -"" , +"" , "", -"", +"", -"", -"", +"", +"", {}, -{ - "aid" :"", - "appId" :"", - "vid" : "", - "dist" : "", - "notes" : "", - "name" : "", - "vulnName" : "", - "tracking" : "", +{ + "aid" :"", + "appId" :"", + "vid" : "", + "dist" : "", + "name" : "", + "vulnName" : "", + "tracking" : "", "isVer" : ${isVer}, "severity" : { "overall" : "${vuln.overall}", @@ -33,15 +32,15 @@ }, "reports": [ , - { - "name": " - Retest Report.docx", - "type": " Retest", - "updated": "", + { + "name": " - Retest Report.docx", + "type": " Retest", + "updated": "", "guid" : "", "isRetest": }] }] -], -"recordsTotal" : ${count}, -"recordsFiltered" : ${count} +], +"recordsTotal" : ${count}, +"recordsFiltered" : ${count} } diff --git a/src/com/fuse/actions/remediation/OpenVulns.java b/src/com/fuse/actions/remediation/OpenVulns.java index 81a10471..92c6430b 100644 --- a/src/com/fuse/actions/remediation/OpenVulns.java +++ b/src/com/fuse/actions/remediation/OpenVulns.java @@ -17,6 +17,7 @@ import com.fuse.dao.query.VulnerabilityQueries; import com.fuse.utils.Combo; import com.fuse.utils.FSUtils; +import com.fasterxml.jackson.core.io.JsonStringEncoder; import com.mongodb.BasicDBObject; @Namespace("/portal") @@ -380,6 +381,20 @@ public Long getCount() { public void setCount(Long count) { this.count = count; } + + /** + * Escapes a value for safe inclusion inside a JSON string literal. Struts' + * escapeJavaScript escapes a single quote as \' which is NOT a valid JSON + * escape sequence and breaks JSON.parse on the client (the DataTable). This + * produces strictly valid JSON: it escapes ", \\ and control characters and + * leaves single quotes untouched. + */ + public String jsonEscape(String value) { + if (value == null) { + return ""; + } + return new String(JsonStringEncoder.getInstance().quoteAsString(value)); + }