Merge branch 'src-r-r_3229_invalid-hashtag-causes-entire-post-to-drop-1' into 'develop'

Src r r 3229 invalid hashtag causes entire post to drop 1

See merge request pleroma/pleroma!4055
This commit is contained in:
Jordan H 2024-05-17 02:06:59 +00:00
commit dedadc7d2a
5 changed files with 102 additions and 4 deletions

View file

@ -0,0 +1,5 @@
- The original issue appeared to be that invalid hashtags on
Catodon instances were resulting in the post being dropped.
However, Catadon uses notes. I added a function to the
`Pleroma.Web.ActivityPub.Transmogrifier` module that accepts
a Note type and converts it to a Create type.

View file

@ -63,7 +63,7 @@ defmodule Pleroma.User.Query do
limit: pos_integer(),
actor_types: [String.t()],
birthday_day: pos_integer(),
birthday_month: pos_integer()
birthday_month: pos_integer(),
}
| map()

View file

@ -394,12 +394,17 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
def handle_incoming(%{"type" => "Note"} = data, options) do
Map.put(data, "type", "Create")
|> handle_incoming(options)
end
# disallow objects with bogus IDs
def handle_incoming(%{"id" => nil}, _options), do: :error
def handle_incoming(%{"id" => ""}, _options), do: :error
def handle_incoming(%{"id" => nil}, _options), do: {:error, "nil_id"}
def handle_incoming(%{"id" => ""}, _options), do: {:error, "empty_id"}
# length of https:// = 8, should validate better, but good enough for now.
def handle_incoming(%{"id" => id}, _options) when is_binary(id) and byte_size(id) < 8,
do: :error
do: {:error, "invalid_length"}
def handle_incoming(
%{"type" => "Listen", "object" => %{"type" => "Audio"} = object} = data,

View file

@ -0,0 +1,64 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"movedToUri": "as:movedTo",
"sensitive": "as:sensitive",
"Hashtag": "as:Hashtag",
"quoteUri": "fedibird:quoteUri",
"quoteUrl": "as:quoteUrl",
"toot": "http://joinmastodon.org/ns#",
"Emoji": "toot:Emoji",
"featured": "toot:featured",
"discoverable": "toot:discoverable",
"schema": "http://schema.org#",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value",
"misskey": "https://misskey-hub.net/ns#",
"_misskey_content": "misskey:_misskey_content",
"_misskey_quote": "misskey:_misskey_quote",
"_misskey_reaction": "misskey:_misskey_reaction",
"_misskey_votes": "misskey:_misskey_votes",
"_misskey_talk": "misskey:_misskey_talk",
"_misskey_summary": "misskey:_misskey_summary",
"isCat": "misskey:isCat",
"fedibird": "http://fedibird.com/ns#",
"vcard": "http://www.w3.org/2006/vcard/ns#",
"litepub": "http://litepub.social/ns#",
"ChatMessage": "litepub:ChatMessage",
"directMessage": "litepub:directMessage"
}
],
"id": "https://example.org/notes/9paaptbjhp2v575c",
"type": "Note",
"attributedTo": "https://example.org/users/9pa9i3o1towdkwj2",
"summary": null,
"content": "<p><span>A post with a </span><a href=\"https://example.org/tags/bad-hashtag\" rel=\"tag\">#bad-hashtag</a></p>",
"contentMap": {
"en": "<p><span>A post with a </span><a href=\"https://example.org/tags/bad-hashtag\" rel=\"tag\">#bad-hashtag</a></p>"
},
"_misskey_content": "A post with a #bad-hashtag",
"source": {
"content": "A post with a #bad-hashtag",
"mediaType": "text/x.misskeymarkdown"
},
"published": "2024-02-03T23:54:57.583Z",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://example.org/users/9pa9i3o1towdkwj2/followers"
],
"inReplyTo": null,
"attachment": [],
"sensitive": false,
"tag": [
{
"type": "Hashtag",
"href": "https://example.org/tags/bad-hashtag",
"name": "#bad-hashtag"
}
]
}

View file

@ -290,6 +290,30 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do
refute is_nil(data["cc"])
end
test "it ensures a post with an invalid has tag is not dropped" do
user = insert(:user)
data =
File.read!("test/fixtures/catodon-note-object-with-invalid-hash-tag.json")
|> Jason.decode!()
|> Map.put("actor", user.ap_id)
|> Map.put("cc", nil)
object =
data
|> Map.put("attributedTo", user.ap_id)
|> Map.put("cc", nil)
|> Map.put("id", user.ap_id <> "/notes/12345678")
data = Map.put(data, "object", object)
{:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(data)
object = Object.normalize(activity)
assert String.contains?(object.data["content"], "#bad-hashtag")
end
test "it strips internal likes" do
data =
File.read!("test/fixtures/mastodon-post-activity.json")