mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-23 01:35:28 +00:00
StealEmoji: make final paths infeasible to predict
Certain attacks rely on predictable paths for their payloads. If we weren’t so overly lax in our (id, URL) check, the current counterfeit activity exploit would be one of those. It seems plausible for future attacks to hinge on or being made easier by predictable paths too. In general, letting remote actors place arbitrary data at a path within our domain of their choosing (sans prefix) just doesn’t seem like a good idea. Using fully random filenames would have worked as well, but this is less friendly for admins checking emoji dirs. The generated suffix should still be more than enough; an attacker needs on average 140 trillion attempts to correctly guess the final path.
This commit is contained in:
parent
ee5ce87825
commit
a4fa2ec9af
|
@ -37,7 +37,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
|||
|
||||
defp add_emoji(shortcode, extension, filedata) do
|
||||
{:ok, pack} = load_or_create_pack()
|
||||
filename = shortcode <> "." <> extension
|
||||
# Make final path infeasible to predict to thwart certain kinds of attacks
|
||||
# (48 bits is slighty more than 8 base62 chars, thus 9 chars)
|
||||
salt =
|
||||
:crypto.strong_rand_bytes(6)
|
||||
|> :crypto.bytes_to_integer()
|
||||
|> Base62.encode()
|
||||
|> String.pad_leading(9, "0")
|
||||
|
||||
filename = shortcode <> "-" <> salt <> "." <> extension
|
||||
|
||||
Pack.add_file(pack, shortcode, filename, filedata)
|
||||
end
|
||||
|
||||
|
@ -71,7 +80,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
|||
|
||||
e ->
|
||||
Logger.warning(
|
||||
"MRF.StealEmojiPolicy: Failed to add #{shortcode}.#{extension}: #{inspect(e)}"
|
||||
"MRF.StealEmojiPolicy: Failed to add #{shortcode} as #{extension}: #{inspect(e)}"
|
||||
)
|
||||
|
||||
nil
|
||||
|
|
Loading…
Reference in a new issue