简体   繁体   English

Checkmarx 扫描问题 - 对来自输入的未净化 xml 数据进行反序列化

[英]Checkmarx scan issue - deserilization of unsanitized xml data from the input

I am currently facing issue during checkmarx scan .我目前在checkmarx 扫描期间遇到问题。 It is highlighting that we are deserializing of Untrusted data in the last line mentioned below.它强调我们在下面提到的最后一行中反序列不受信任的数据 How to rectify this issue?如何纠正这个问题?

Scan Issue: Deserialization of Untrusted Data扫描问题:不可信数据的反序列化

Note: We do not have any xsd注意:我们没有任何 xsd

String message = request.getParameter("param_name"); // Input xml string
XStream parser = new XStream(new StaxDriver());
MyMessage messageObj = (MyMessage) parser.fromXML(message); // This line is flagged by CHECKMARX SCAN 

I will assume that you intended to say that you're getting results for Deserialization of Untrusted Data .我假设您打算说您正在获得Deserialization of Untrusted Data 的结果。

The reason you're getting that message is that XStream will happily attempt to create an instance of just about any object specified in the XML by default.您收到该消息的原因是,默认情况下, XStream将愉快地尝试创建几乎在 XML 中指定的任何 object 的实例。 The technique is to allow only the types you intend to be deserialized.该技术是只允许您打算反序列化的类型。 One would presume you've ensured those types are safe.人们会假设您已经确保这些类型是安全的。

I ran this code derived from your example and verified that the two lines I added were detected as sanitization.我运行了从您的示例派生的这段代码,并验证了我添加的两行是否被检测为清理。

String message = request.getParameter("param_name");
XStream parser = new XStream(new StaxDriver());
parser.addPermission(NoTypePermission.NONE);
parser.allowTypes(new Class[] {MyMessage.class, String.class});
MyMessage messageObj = (MyMessage) parser.fromXML(message);

I added the String.class type since I'd presume some of your properties on MyMessage are String .我添加了String.class类型,因为我假设您在MyMessage上的某些属性是String String itself, like most primitives, is generally safe for deserialization.与大多数原语一样, String本身对于反序列化通常是安全的。 While the string itself is safe, you'll want to make sure how you use it is safe.虽然字符串本身是安全的,但您需要确保使用它的方式是安全的。 (eg if you are deserializing a string and passing it to the OS as part of a shell exec, that could be a different vulnerability.) (例如,如果您正在反序列化一个字符串并将其作为 shell exec 的一部分传递给操作系统,那可能是一个不同的漏洞。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM