mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-30 01:01:12 +00:00
Bypass the filter based on content-type as well in case a webp image is uploaded with the wrong file extension.
This commit is contained in:
parent
3a98960c26
commit
216c84a8f4
|
@ -10,8 +10,11 @@ defmodule Pleroma.Upload.Filter.Exiftool do
|
||||||
@behaviour Pleroma.Upload.Filter
|
@behaviour Pleroma.Upload.Filter
|
||||||
|
|
||||||
@spec filter(Pleroma.Upload.t()) :: {:ok, any()} | {:error, String.t()}
|
@spec filter(Pleroma.Upload.t()) :: {:ok, any()} | {:error, String.t()}
|
||||||
def filter(%Pleroma.Upload{name: file, tempfile: path, content_type: "image" <> _}) do
|
|
||||||
# webp is not compatible with exiftool at this time
|
# webp is not compatible with exiftool at this time
|
||||||
|
def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
|
||||||
|
|
||||||
|
def filter(%Pleroma.Upload{name: file, tempfile: path, content_type: "image" <> _}) do
|
||||||
if Regex.match?(~r/\.(webp)$/i, file) do
|
if Regex.match?(~r/\.(webp)$/i, file) do
|
||||||
{:ok, :noop}
|
{:ok, :noop}
|
||||||
else
|
else
|
||||||
|
|
|
@ -34,11 +34,15 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
|
||||||
test "verify webp files are skipped" do
|
test "verify webp files are skipped" do
|
||||||
upload = %Pleroma.Upload{
|
upload = %Pleroma.Upload{
|
||||||
name: "sample.webp",
|
name: "sample.webp",
|
||||||
content_type: "image/webp",
|
content_type: "image/webp"
|
||||||
path: Path.absname("/dev/null"),
|
}
|
||||||
tempfile: Path.absname("/dev/null")
|
|
||||||
|
bad_type = %Pleroma.Upload{
|
||||||
|
name: "sample.webp",
|
||||||
|
content_type: "image/jpeg"
|
||||||
}
|
}
|
||||||
|
|
||||||
assert Filter.Exiftool.filter(upload) == {:ok, :noop}
|
assert Filter.Exiftool.filter(upload) == {:ok, :noop}
|
||||||
|
assert Filter.Exiftool.filter(bad_type) == {:ok, :noop}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue