safer path handling, safer shortcode handling
This commit is contained in:
parent
0e4cedc350
commit
cb5a9662b8
|
@ -39,7 +39,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
||||||
Logger.debug("HANDLING EMOJO")
|
Logger.debug("HANDLING EMOJO")
|
||||||
|
|
||||||
cond do
|
cond do
|
||||||
String.contains?(emojo_shortcode, "/") ->
|
!String.match?(emojo_shortcode, ~r/^[[:word:]]+$/) ->
|
||||||
Logger.error("BAD EMOJO SHORTCODE: #{emojo_shortcode}")
|
Logger.error("BAD EMOJO SHORTCODE: #{emojo_shortcode}")
|
||||||
|
|
||||||
String.starts_with?(emojo_url, "https://") ->
|
String.starts_with?(emojo_url, "https://") ->
|
||||||
|
@ -48,7 +48,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
||||||
|
|
||||||
if remote_emojo.status_code == 200 do
|
if remote_emojo.status_code == 200 do
|
||||||
with {:ok, current_dir} <- File.cwd() do
|
with {:ok, current_dir} <- File.cwd() do
|
||||||
new_file = current_dir <> "/priv/static/emoji/stolen/" <> emojo_shortcode <> Path.extname(emojo_url)
|
emojo_uri = URI.parse(emojo_url)
|
||||||
|
extension = Path.extname(Path.basename(emojo_uri.path))
|
||||||
|
filename = emojo_shortcode <> extension
|
||||||
|
|
||||||
|
new_file = Path.join([current_dir, "priv/static/emoji/stolen", filename])
|
||||||
|
|
||||||
{:ok, file} = File.open(new_file, [:write])
|
{:ok, file} = File.open(new_file, [:write])
|
||||||
IO.binwrite(file, remote_emojo.body)
|
IO.binwrite(file, remote_emojo.body)
|
||||||
|
|
Loading…
Reference in New Issue