我有以下Fortify安全问题:
JSON注入:确保使用安全序列化函数执行所有序列化,该函数在单引号或双引号内分隔不受信任的数据并转义任何特殊字符.
以下是我的代码:
public String saveJson(String json, long ID, String userId) throws SQLException, JsonParseException, JsonMappingException, IOException
{
ObjectMapper objectMapper = new ObjectMapper();
List<item> listOfNewItems = objectMapper.readValue(json, new TypeReference<List<item>>(){});
userId= userFactory.getUser().getID();
String message = saveJson(listOfNewItems,ID,userId);
return message;
}
Run Code Online (Sandbox Code Playgroud)
我想尝试使用
org.codehaus.jackson.io.JsonStringEncoder.getInstance().quoteAsString(json);
Run Code Online (Sandbox Code Playgroud)
或者可能
objectMapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false);
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
Run Code Online (Sandbox Code Playgroud)
但不确定?
有关错误的更多详细信息:
将未经验证的输入写入JSON
有任何想法吗?