- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们对代码进行了安全审核,其中提到我们的代码容易受到 XML EXternal Entity (XXE) 攻击。
Explanation
XML External Entities attacks benefit from an XML feature to build documents dynamically at the time of processing. An XML entity allows inclusion of data dynamically from a given resource. External entities allow an XML document to include data from an external URI. Unless configured to do otherwise, external entities force the XML parser to access the resource specified by the URI, e.g., a file on the local machine or on a remote system. This behavior exposes the application to XML External Entity (XXE) attacks, which can be used to perform denial of service of the local system, gain unauthorized access to files on the local machine, scan remote machines, and perform denial of service of remote systems.
The following XML document shows an example of an XXE attack.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe SYSTEM "file:///dev/random" >]><foo>&xxe;</foo>This example could crash the server (on a UNIX system), if the XML parser attempts to substitute the entity with the contents of the /dev/random file.
Recommendation
The XML unmarshaller should be configured securely so that it does not allow external entities as part of an incoming XML document.
To avoid XXE injection do not use unmarshal methods that process an XML source directly as
java.io.File
,java.io.Reader
orjava.io.InputStream
. Parse the document with a securely configured parser and use an unmarshal method that takes the secure parser as the XML source as shown in the following example:DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setExpandEntityReferences(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(<XML Source>);
Model model = (Model) u.unmarshal(document);
以下代码是审计发现 XXE 攻击的地方:
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
System.out.println("outputing to : " + outputLocation);
File outputFile = new File(outputLocation);
StreamResult result = new StreamResult(outputFile);
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
如何在我的代码中实现上述建议?我在哪里遗漏了东西?
最佳答案
您可以对 DocumentBuilderFactory
使用相同的方法:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
...
为了让每个人都自动使用它,您需要创建自己的实现(通过扩展您当前使用的实现;使用调试器来查找)。在构造函数中设置该功能。
然后,您可以将要在系统属性 javax.xml.parsers.DocumentBuilderFactory
中使用的新工厂传递给 Java VM,每个人都会使用它。
关于java - 如何防范XXE攻击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57047719/
我想创建一个游戏,您可以在其中尝试避开“攻击”您的物体(圆圈)。我这样做的方式: 首先计算对象和我之间的 x_and y 差值(在这段代码中 AI_x 是对象的 x 位置(AI_y:y 位置),x,y
前言 传统的 DDOS 防御通常使用“硬抗”的方式,导致开销很大,而且有时效果并不好。例如使用 DNS 切换故障 IP 的方案,由于域名会受到缓存等因素的影响通常有分钟级延时,前端难以快速生效。例
我们目前正在使用 OWASP Antisamy 项目来保护我们的应用程序免受 XSS 攻击。当任何给定的表单提交给服务器时,每个输入字段都会被清理。它工作正常,但我们在公司名称、组织名称等字段上遇到问
正则表达式: ^\d+(\.\d+)*$ 我试图打破它: 1234567890.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.
我正在创建一个网页,用户可以在其中交互并在远程计算机上执行基本的文件系统操作(创建文件/目录、删除文件/目录、导航文件系统)。 该网页是基本的 HTML(UTF-8 编码)和 Javascript。我
两个客户端 Alice 和 Bob 使用服务器登录并通过服务器交换消息。登录时,他们都发送他们的公钥以存储在服务器上。当 Alice 想与 Bob 通话时,她用 Bob 的公钥加密一个对称 key ,
一直在阅读 MitB 攻击,有些事情让我担心。 来自 WIKI : The use of strong authentication tools simply creates an increased
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
我正在使用 Summernote 所见即所得编辑器(如下所示),发现它使用 HTML 标签来格式化文本。 如何保护我的应用程序免受 XSS 攻击?我将输入存储为纯文本,并使用输出:{!! $body
我有一个应用程序,用户可以在其中注册并输入他们的手机和其他数据。 为了验证用户是否有效,在我将其保存到我的数据库之前,我向用户发送了一 strip 有代码的短信。之后他们应该在表单中输入代码。 问题是
由于 xpath 注入(inject)攻击正在攻击网站,因此我们需要保护 xml 文档作为 xpath 查询参数化的解决方案。如果有人可以解释xpath查询的参数化是什么意思,请帮忙?以及这种参数化如
我想知道电子邮件地址是否可以用于 XSS 攻击。 假设有一个网站,您可以在其中注册并提供他的电子邮件地址。如果有人想攻击给定的网站,他或她可能会创建一个电子邮件地址,例如: ""@stmpname
这可能更适合 Serverfault,但许多只来这里的 web 开发人员可能会从这个问题的可能答案中受益。 问题是:您如何有效地保护自己免受针对您的网络服务器的拒绝服务攻击? 看完这篇 article
检查引荐来源网址是否足以防止跨站点请求伪造攻击?我知道引荐来源网址可能会被欺骗,但是攻击者有没有办法为客户端做到这一点?我知道代币是常态,但这行得通吗? 最佳答案 这是一个 3 年前的问题,有四个不同
我从输入类型中获取值,如下所示: var num = $(document).find('#num').val(); 我尝试使用以下代码来避免输入类型受到 XSS 攻击: num = j
我需要使用超链接动态更新以下代码中的“src”链接,该超链接又指向另一个 .js 文件。以下只是用于“src”的示例 URL。我的问题是,允许在运行时更改“src”,此代码是否容易受到 XSS 攻击?
我在 OWASP 和网络上看到了很多关于如何避免/防止 XSS 攻击的信息。但是,我还没有找到任何提及在检测到 XSS 攻击时如何响应的内容。 应返回什么 HTTP 状态代码(即 400、403...
保护站点免受 DoS 攻击的最佳方法是什么?知道流行的网站/服务如何处理这个问题吗? 应用程序、操作系统、网络、托管级别有哪些工具/服务? 如果有人能分享他们处理过的真实经历,那就太好了。 谢谢 最佳
我到处寻找缓解方法 this vulnerability ,我发现类似: Just disable http compression. 嗯,这很痛苦,因为压缩可以节省大量带宽,而且还可以让您的网页加载
服务器,一个运行 Spring 2.5.6 的独立 SE 应用程序和一个嵌入式 jetty 。客户端、Swing 应用程序使用 HttpInvoker 连接到服务器。 服务器公开了很多服务,现在出现了
我是一名优秀的程序员,十分优秀!