Drop HTMLSanitizeEx and fix title sanitizing
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -45,6 +45,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
alias Mobilizon.Federation.WebFinger
|
||||
|
||||
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
|
||||
alias Mobilizon.Service.Formatter.HTML
|
||||
alias Mobilizon.Service.Notifications.Scheduler
|
||||
alias Mobilizon.Service.RichMedia.Parser
|
||||
|
||||
@@ -499,7 +500,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
metadata:
|
||||
additional
|
||||
|> Map.get(:metadata, %{})
|
||||
|> Map.update(:message, nil, &String.trim(HtmlSanitizeEx.strip_tags(&1)))
|
||||
|> Map.update(:message, nil, &String.trim(HTML.strip_tags(&1)))
|
||||
}),
|
||||
join_data <- Convertible.model_to_as(participant),
|
||||
audience <-
|
||||
@@ -1257,7 +1258,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
# If title is not set: we are not updating it
|
||||
args =
|
||||
if Map.has_key?(args, :title) && !is_nil(args.title),
|
||||
do: Map.update(args, :title, "", &String.trim(HtmlSanitizeEx.strip_tags(&1))),
|
||||
do: Map.update(args, :title, "", &String.trim/1),
|
||||
else: args
|
||||
|
||||
# If we've been given a description (we might not get one if updating)
|
||||
@@ -1344,7 +1345,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
|
||||
defp prepare_args_for_group(args) do
|
||||
with preferred_username <-
|
||||
args |> Map.get(:preferred_username) |> HtmlSanitizeEx.strip_tags() |> String.trim(),
|
||||
args |> Map.get(:preferred_username) |> HTML.strip_tags() |> String.trim(),
|
||||
summary <- args |> Map.get(:summary, "") |> String.trim(),
|
||||
{summary, _mentions, _tags} <-
|
||||
summary |> String.trim() |> APIUtils.make_content_html([], "text/html") do
|
||||
@@ -1357,7 +1358,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
{:reporter, Actors.get_actor!(args.reporter_id)},
|
||||
{:reported, %Actor{} = reported_actor} <-
|
||||
{:reported, Actors.get_actor!(args.reported_id)},
|
||||
content <- HtmlSanitizeEx.strip_tags(args.content),
|
||||
content <- HTML.strip_tags(args.content),
|
||||
event <- Conversations.get_comment(Map.get(args, :event_id)),
|
||||
{:get_report_comments, comments} <-
|
||||
{:get_report_comments,
|
||||
|
||||
@@ -8,6 +8,7 @@ defmodule Mobilizon.GraphQL.API.Groups do
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.ActivityPub.Activity
|
||||
alias Mobilizon.Service.Formatter.HTML
|
||||
|
||||
@doc """
|
||||
Create a group
|
||||
@@ -15,7 +16,7 @@ defmodule Mobilizon.GraphQL.API.Groups do
|
||||
@spec create_group(map) :: {:ok, Activity.t(), Actor.t()} | any
|
||||
def create_group(args) do
|
||||
with preferred_username <-
|
||||
args |> Map.get(:preferred_username) |> HtmlSanitizeEx.strip_tags() |> String.trim(),
|
||||
args |> Map.get(:preferred_username) |> HTML.strip_tags() |> String.trim(),
|
||||
{:existing_group, nil} <-
|
||||
{:existing_group, Actors.get_local_group_by_title(preferred_username)},
|
||||
{:ok, %Activity{} = activity, %Actor{} = group} <-
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Events.{Event, FeedToken}
|
||||
alias Mobilizon.Service.Formatter.HTML
|
||||
alias Mobilizon.Storage.Page
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
@@ -31,7 +32,7 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
dtstart: event.begins_on,
|
||||
dtstamp: event.publish_at || DateTime.utc_now(),
|
||||
dtend: event.ends_on,
|
||||
description: HtmlSanitizeEx.strip_tags(event.description),
|
||||
description: HTML.strip_tags(event.description),
|
||||
uid: event.uuid,
|
||||
url: event.url,
|
||||
geo: Address.coords(event.physical_address),
|
||||
|
||||
@@ -14,5 +14,15 @@ defmodule Mobilizon.Service.Formatter.HTML do
|
||||
|
||||
def filter_tags(html), do: Sanitizer.scrub(html, DefaultScrubbler)
|
||||
|
||||
def strip_tags(html) do
|
||||
case FastSanitize.strip_tags(html) do
|
||||
{:ok, html} ->
|
||||
html
|
||||
|
||||
_ ->
|
||||
raise "Failed to filter tags"
|
||||
end
|
||||
end
|
||||
|
||||
def filter_tags_for_oembed(html), do: Sanitizer.scrub(html, OEmbed)
|
||||
end
|
||||
|
||||
@@ -2,6 +2,7 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
alias Phoenix.HTML
|
||||
alias Phoenix.HTML.Tag
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.Formatter.HTML, as: HTMLFormatter
|
||||
alias Mobilizon.Web.JsonLD.ObjectView
|
||||
alias Mobilizon.Web.MediaProxy
|
||||
import Mobilizon.Web.Gettext
|
||||
@@ -49,15 +50,15 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
||||
|
||||
defp process_description(description, _locale) do
|
||||
description
|
||||
|> HtmlSanitizeEx.strip_tags()
|
||||
|> HTMLFormatter.strip_tags()
|
||||
|> String.slice(0..200)
|
||||
|> (&"#{&1}…").()
|
||||
end
|
||||
|
||||
# Insert JSON-LD schema by hand because Tag.content_tag wants to escape it
|
||||
defp json(%Event{} = event) do
|
||||
defp json(%Event{title: title} = event) do
|
||||
"event.json"
|
||||
|> ObjectView.render(%{event: event})
|
||||
|> ObjectView.render(%{event: %{event | title: HTMLFormatter.strip_tags(title)}})
|
||||
|> Jason.encode!()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule Mobilizon.Service.Metadata.Instance do
|
||||
alias Phoenix.HTML.Tag
|
||||
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Service.Formatter.HTML, as: HTMLFormatter
|
||||
alias Mobilizon.Web.Endpoint
|
||||
|
||||
def build_tags do
|
||||
@@ -40,7 +41,7 @@ defmodule Mobilizon.Service.Metadata.Instance do
|
||||
|
||||
defp process_description(description) do
|
||||
description
|
||||
|> HtmlSanitizeEx.strip_tags()
|
||||
|> HTMLFormatter.strip_tags()
|
||||
|> String.slice(0..200)
|
||||
|> (&"#{&1}…").()
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule Mobilizon.Service.Workers.BuildSearch do
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.Formatter.HTML
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
use Mobilizon.Service.Workers.Helper, queue: "search"
|
||||
@@ -44,7 +45,7 @@ defmodule Mobilizon.Service.Workers.BuildSearch do
|
||||
[
|
||||
event.id,
|
||||
event.title,
|
||||
HtmlSanitizeEx.strip_tags(event.description),
|
||||
HTML.strip_tags(event.description),
|
||||
get_tags_string(event)
|
||||
]
|
||||
)
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
<h3><%= gettext "Comments" %></h3>
|
||||
<%= for comment <- @report.comments do %>
|
||||
<p style="margin: 0;">
|
||||
<%= HtmlSanitizeEx.strip_tags(comment.text) %>
|
||||
<%= Mobilizon.Service.Formatter.HTML.strip_tags(comment.text) %>
|
||||
</p>
|
||||
<% end %>
|
||||
<table cellspacing="0" cellpadding="0" border="0" width="100%" style="width: 100% !important;">
|
||||
|
||||
Reference in New Issue
Block a user