<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](xml.etree.elementtree.xhtml "xml.etree.ElementTree --- The ElementTree XML API") | - [上一頁](html.entities.xhtml "html.entities --- HTML 一般實體的定義") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [結構化標記處理工具](markup.xhtml) ? - $('.inline-search').show(0); | # XML處理模塊 **源碼:** [Lib/xml/](https://github.com/python/cpython/tree/3.7/Lib/xml/) \[https://github.com/python/cpython/tree/3.7/Lib/xml/\] - - - - - - 用于處理XML的Python接口分組在 `xml` 包中。 警告 XML 模塊對于錯誤或惡意構造的數據是不安全的。 如果需要解析不受信任或未經身份驗證的數據,請參閱 [XML 漏洞](#xml-vulnerabilities) 和 [defusedxml 和 defusedexpat 軟件包](#defused-packages) 部分。 值得注意的是 [`xml`](#module-xml "xml: Package containing XML processing modules") 包中的模塊要求至少有一個 SAX 兼容的 XML 解析器可用。在 Pythonm中包含 Expat 解析器,因此 [`xml.parsers.expat`](pyexpat.xhtml#module-xml.parsers.expat "xml.parsers.expat: An interface to the Expat non-validating XML parser.") 模塊將始終可用。 [`xml.dom`](xml.dom.xhtml#module-xml.dom "xml.dom: Document Object Model API for Python.") 和 [`xml.sax`](xml.sax.xhtml#module-xml.sax "xml.sax: Package containing SAX2 base classes and convenience functions.") 包的文檔是 DOM 和 SAX 接口的 Python 綁定的定義。 XML 處理子模塊包括: - [`xml.etree.ElementTree`](xml.etree.elementtree.xhtml#module-xml.etree.ElementTree "xml.etree.ElementTree: Implementation of the ElementTree API."): ElementTree API,一個簡單而輕量級的XML處理器 - [`xml.dom`](xml.dom.xhtml#module-xml.dom "xml.dom: Document Object Model API for Python."):DOM API 定義 - [`xml.dom.minidom`](xml.dom.minidom.xhtml#module-xml.dom.minidom "xml.dom.minidom: Minimal Document Object Model (DOM) implementation."):最小的 DOM 實現 - [`xml.dom.pulldom`](xml.dom.pulldom.xhtml#module-xml.dom.pulldom "xml.dom.pulldom: Support for building partial DOM trees from SAX events."):支持構建部分 DOM 樹 - [`xml.sax`](xml.sax.xhtml#module-xml.sax "xml.sax: Package containing SAX2 base classes and convenience functions."):SAX2 基類和便利函數 - [`xml.parsers.expat`](pyexpat.xhtml#module-xml.parsers.expat "xml.parsers.expat: An interface to the Expat non-validating XML parser."):Expat解析器綁定 ## XML 漏洞 XML 處理模塊對于惡意構造的數據是不安全的。 攻擊者可能濫用 XML 功能來執行拒絕服務攻擊、訪問本地文件、生成與其它計算機的網絡連接或繞過防火墻。 下表概述了已知的攻擊以及各種模塊是否容易受到攻擊。 種類 sax etree minidom pulldom xmlrpc billion laughs **易受攻擊** **易受攻擊** **易受攻擊** **易受攻擊** **易受攻擊** quadratic blowup **易受攻擊** **易受攻擊** **易受攻擊** **易受攻擊** **易受攻擊** external entity expansion 安全 (4) 安全 (1) 安全 (2) 安全 (4) 安全 (3) [DTD](https://en.wikipedia.org/wiki/Document_type_definition) \[https://en.wikipedia.org/wiki/Document\_type\_definition\] retrieval 安全 (4) 安全 安全 安全 (4) 安全 decompression bomb 安全 安全 安全 安全 **易受攻擊** 1. [`xml.etree.ElementTree`](xml.etree.elementtree.xhtml#module-xml.etree.ElementTree "xml.etree.ElementTree: Implementation of the ElementTree API.") 不會擴展外部實體并在實體發生時引發 `ParserError`。 2. [`xml.dom.minidom`](xml.dom.minidom.xhtml#module-xml.dom.minidom "xml.dom.minidom: Minimal Document Object Model (DOM) implementation.") 不會擴展外部實體,只是簡單地返回未擴展的實體。 3. `xmlrpclib` 不擴展外部實體并省略它們。 4. 從 Python 3.7.1 開始,默認情況下不再處理外部通用實體。 billion laughs / exponential entity expansion (狂笑/遞歸實體擴展)[Billion Laughs](https://en.wikipedia.org/wiki/Billion_laughs) \[https://en.wikipedia.org/wiki/Billion\_laughs\] 攻擊 -- 也稱為遞歸實體擴展 -- 使用多級嵌套實體。 每個實體多次引用另一個實體,最終實體定義包含一個小字符串。 指數級擴展導致幾千 GB 的文本,并消耗大量內存和 CPU 時間。 quadratic blowup entity expansion(二次爆炸實體擴展)二次爆炸攻擊類似于 [Billion Laughs](https://en.wikipedia.org/wiki/Billion_laughs) \[https://en.wikipedia.org/wiki/Billion\_laughs\] 攻擊,它也濫用實體擴展。 它不是嵌套實體,而是一遍又一遍地重復一個具有幾千個字符的大型實體。攻擊不如遞歸情況有效,但它避免觸發禁止深度嵌套實體的解析器對策。 external entity expansion實體聲明可以包含的不僅僅是替換文本。 它們還可以指向外部資源或本地文件。 XML 解析器訪問資源并將內容嵌入到 XML 文檔中。 [DTD](https://en.wikipedia.org/wiki/Document_type_definition) \[https://en.wikipedia.org/wiki/Document\_type\_definition\] retrievalPython 的一些 XML 庫 [`xml.dom.pulldom`](xml.dom.pulldom.xhtml#module-xml.dom.pulldom "xml.dom.pulldom: Support for building partial DOM trees from SAX events.") 從遠程或本地位置檢索文檔類型定義。 該功能與外部實體擴展問題具有相似的含義。 decompression bombDecompression bombs(解壓炸彈,又名 [ZIP bomb](https://en.wikipedia.org/wiki/Zip_bomb) \[https://en.wikipedia.org/wiki/Zip\_bomb\])適用于所有可以解析壓縮 XML 流(例如 gzip 壓縮的 HTTP 流或 LZMA 壓縮的文件)的 XML 庫。 對于攻擊者來說,它可以將傳輸的數據量減少三個量級或更多。 PyPI上 [defusedxml](https://pypi.org/project/defusedxml/) \[https://pypi.org/project/defusedxml/\] 的文檔包含有關所有已知攻擊向量的更多信息以及示例和參考。 ## `defusedxml` 和 `defusedexpat` 軟件包 [defusedxml](https://pypi.org/project/defusedxml/) \[https://pypi.org/project/defusedxml/\] 是一個純 Python 軟件包,它修改了所有標準庫 XML 解析器的子類,可以防止任何潛在的惡意操作。 對于解析不受信任的XML數據的任何服務器代碼,建議使用此程序包。 該軟件包還提供了有關更多 XML 漏洞(如 XPath 注入)的示例漏洞和擴展文檔。 [defusedexpat](https://pypi.org/project/defusedexpat/) \[https://pypi.org/project/defusedexpat/\] 提供了一個修改過的 libexpat 和一個打過補丁的 `pyexpat` 模塊,它有針對實體擴展DoS攻擊的對策。 `defusedexpat` 模塊仍然允許合理且可配置的實體擴展量。 這些修改可能包含在 Python 的某些未來版本中,但不會包含在 Python 的任何修復版本中,因為它們會破壞向后兼容性。 ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](xml.etree.elementtree.xhtml "xml.etree.ElementTree --- The ElementTree XML API") | - [上一頁](html.entities.xhtml "html.entities --- HTML 一般實體的定義") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [結構化標記處理工具](markup.xhtml) ? - $('.inline-search').show(0); | ? [版權所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 軟件基金會是一個非盈利組織。 [請捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [發現了問題](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 創建。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看