1 diff --git a/CHANGELOG.md b/CHANGELOG.md
2 index 468ec101293b462c8eddaddf375d0de9e8d68fcd..9d9aadc6e8a0162d8944622f783a6301fefd6cfa 100644
5 @@ -14,6 +14,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
12 +- Fix XML External Entity (XXE) loading vulnerability allowing to fetch arbitary files from the server's filesystem
17 diff --git a/changelog.d/akkoma-xml-remote-entities.security b/changelog.d/akkoma-xml-remote-entities.security
19 index 0000000000000000000000000000000000000000..5e6725e5bb5ad6a7140beb8245676a1fa0408086
21 +++ b/changelog.d/akkoma-xml-remote-entities.security
23 +Fix XML External Entity (XXE) loading vulnerability allowing to fetch arbitary files from the server's filesystem
24 diff --git a/lib/pleroma/web/xml.ex b/lib/pleroma/web/xml.ex
25 index b699446b007b07ec9e7e5f057ba6532d405a77cd..380a80ab83afe367b08a9770cac110440c6f4ccf 100644
26 --- a/lib/pleroma/web/xml.ex
27 +++ b/lib/pleroma/web/xml.ex
28 @@ -29,7 +29,10 @@ def parse_document(text) do
31 |> :binary.bin_to_list()
32 - |> :xmerl_scan.string(quiet: true)
33 + |> :xmerl_scan.string(
35 + fetch_fun: fn _, _ -> raise "Resolving external entities not supported" end
40 diff --git a/mix.exs b/mix.exs
41 index d1cdb151dd25545b31f777e8c3b57e42db673357..12f721364dd75744651e5044936d195684d8cf08 100644
44 @@ -4,7 +4,7 @@ defmodule Pleroma.Mixfile do
48 - version: version("2.5.3"),
49 + version: version("2.5.4"),
51 elixirc_paths: elixirc_paths(Mix.env()),
52 compilers: [:phoenix, :gettext] ++ Mix.compilers(),
53 diff --git a/test/fixtures/xml_external_entities.xml b/test/fixtures/xml_external_entities.xml
55 index 0000000000000000000000000000000000000000..d5ff87134734bd072f57e41ff7662638c0cc22c8
57 +++ b/test/fixtures/xml_external_entities.xml
59 +<?xml version="1.0" encoding="UTF-8"?>
60 +<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
61 +<stockCheck><productId>&xxe;</productId></stockCheck>
62 diff --git a/test/pleroma/web/web_finger_test.exs b/test/pleroma/web/web_finger_test.exs
63 index fafef54fe7040df234ee0931787a024481f6f053..be5e08776becca8ade9710f76f41a7678a2fb7c8 100644
64 --- a/test/pleroma/web/web_finger_test.exs
65 +++ b/test/pleroma/web/web_finger_test.exs
66 @@ -180,5 +180,28 @@ test "respects xml content-type" do
68 {:ok, _data} = WebFinger.finger("pekorino@pawoo.net")
71 + test "refuses to process XML remote entities" do
74 + url: "https://pawoo.net/.well-known/webfinger?resource=acct:pekorino@pawoo.net"
79 + body: File.read!("test/fixtures/xml_external_entities.xml"),
80 + headers: [{"content-type", "application/xrd+xml"}]
83 + %{url: "https://pawoo.net/.well-known/host-meta"} ->
87 + body: File.read!("test/fixtures/tesla_mock/pawoo.net_host_meta")
91 + assert :error = WebFinger.finger("pekorino@pawoo.net")
95 diff --git a/test/pleroma/web/xml_test.exs b/test/pleroma/web/xml_test.exs
97 index 0000000000000000000000000000000000000000..89d4709b6e7938cbc5c7d604ac2c479707d6ab5c
99 +++ b/test/pleroma/web/xml_test.exs
101 +defmodule Pleroma.Web.XMLTest do
102 + use Pleroma.DataCase, async: true
104 + alias Pleroma.Web.XML
106 + test "refuses to load external entities from XML" do
107 + data = File.read!("test/fixtures/xml_external_entities.xml")
108 + assert(:error == XML.parse_document(data))