Sonar问题,用于使用XSD文件验证XML的访问权限
我正在使用XSD
验证XML文件,并且我正在为Schemafactory对象创建声纳问题 XML解析器不应容易受到XXE攻击
的攻击,因此我设置了以下属性
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
,但是当我运行代码时,我将获得http://javax.xml.xml.xml.xml.constants/property/ AccessExternalDTD未被识别。
错误,请帮助我找出问题。
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
try {
Schema schema = schemaFactory.newSchema(new File(getResource(schemaFile)));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File(getResource(xmlFile))));
return true;
} catch (SAXException | IOException e) {
xsdInvalidData.add(xmlFile + "=" + e.getMessage());
logger.error(xmlFile + "invalid xsd and enter in catch " + e.getMessage());
return false;
}
I am validating xml file with XSD
and I am getting sonar issue for SchemaFactory object creationXML parsers should not be vulnerable to XXE attacks
so I have set the below properties
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
but when I run the code, then I am getting the http://javax.xml.XMLConstants/property/accessExternalDTD is not recognized.
error, Please help me to figure out the issue.
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
try {
Schema schema = schemaFactory.newSchema(new File(getResource(schemaFile)));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File(getResource(xmlFile))));
return true;
} catch (SAXException | IOException e) {
xsdInvalidData.add(xmlFile + "=" + e.getMessage());
logger.error(xmlFile + "invalid xsd and enter in catch " + e.getMessage());
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认
javax.xml.validation.schemafactory
不支持任何东西。您可能需要找到不同的实现。The default
javax.xml.validation.SchemaFactory
doesn't support anything. You'll probably need to find a different implementation.