static_fe: Sanitize HTML in posts
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sun, 15 Mar 2020 14:45:57 +0000 (15:45 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sun, 15 Mar 2020 19:44:04 +0000 (20:44 +0100)
Note: Seems to have different sanitization with TwitterCard generator giving
the following:

<meta content=\"“alert(&#39;xss&#39;)”\" property=\"twitter:description\">

lib/pleroma/web/static_fe/static_fe_controller.ex
test/web/static_fe/static_fe_controller_test.exs

index 5027d5c233158c115519fae03e57864896fb2d8e..0b77f949c9f7b03efaa60bd6d1e58a3fe9c235ce 100644 (file)
@@ -58,10 +58,17 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
         _ -> data["url"] || data["external_url"] || data["id"]
       end
 
+    content =
+      if data["content"] do
+        Pleroma.HTML.filter_tags(data["content"])
+      else
+        nil
+      end
+
     %{
       user: user,
       title: get_title(activity.object),
-      content: data["content"] || nil,
+      content: content,
       attachment: data["attachment"],
       link: link,
       published: data["published"],
index a072cc78faaf5580456fe1f06d3036a1811adee8..c3d2ae3b41d046c7f82f7b7e25a717d593dc37d6 100644 (file)
@@ -92,6 +92,19 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
       assert html =~ "testing a thing!"
     end
 
+    test "filters HTML tags", %{conn: conn} do
+      user = insert(:user)
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "<script>alert('xss')</script>"})
+
+      conn =
+        conn
+        |> put_req_header("accept", "text/html")
+        |> get("/notice/#{activity.id}")
+
+      html = html_response(conn, 200)
+      assert html =~ ~s[&lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;]
+    end
+
     test "shows the whole thread", %{conn: conn, user: user} do
       {:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})