projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Startup: suggest updating OTP when the version is too low for gun
[akkoma]
/
lib
/
pleroma
/
plugs
/
uploaded_media.ex
diff --git
a/lib/pleroma/plugs/uploaded_media.ex
b/lib/pleroma/plugs/uploaded_media.ex
index 15f447ded319d97767592f0ffb17b999d40b1fac..94147e0c42250c647984a3955dd98100208bc04f 100644
(file)
--- a/
lib/pleroma/plugs/uploaded_media.ex
+++ b/
lib/pleroma/plugs/uploaded_media.ex
@@
-1,5
+1,5
@@
# Pleroma: A lightweight social networking server
# Pleroma: A lightweight social networking server
-# Copyright © 2017-20
19
Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-20
20
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.UploadedMedia do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.UploadedMedia do
@@
-7,15
+7,21
@@
defmodule Pleroma.Plugs.UploadedMedia do
"""
import Plug.Conn
"""
import Plug.Conn
+ import Pleroma.Web.Gettext
require Logger
@behaviour Plug
# no slashes
@path "media"
require Logger
@behaviour Plug
# no slashes
@path "media"
+ @default_cache_control_header "public, max-age=1209600"
+
def init(_opts) do
static_plug_opts =
def init(_opts) do
static_plug_opts =
- []
+ [
+ headers: %{"cache-control" => @default_cache_control_header},
+ cache_control_for_etags: @default_cache_control_header
+ ]
|> Keyword.put(:from, "__unconfigured_media_plug")
|> Keyword.put(:at, "/__unconfigured_media_plug")
|> Plug.Static.init()
|> Keyword.put(:from, "__unconfigured_media_plug")
|> Keyword.put(:at, "/__unconfigured_media_plug")
|> Plug.Static.init()
@@
-27,14
+33,17
@@
defmodule Pleroma.Plugs.UploadedMedia do
conn =
case fetch_query_params(conn) do
%{query_params: %{"name" => name}} = conn ->
conn =
case fetch_query_params(conn) do
%{query_params: %{"name" => name}} = conn ->
+ name = String.replace(name, "\"", "\\\"")
+
conn
conn
- |> put_resp_header("
Content-D
isposition", "filename=\"#{name}\"")
+ |> put_resp_header("
content-d
isposition", "filename=\"#{name}\"")
conn ->
conn
end
conn ->
conn
end
+ |> merge_resp_headers([{"content-security-policy", "sandbox"}])
- config = Pleroma.Config.get(
[Pleroma.Upload]
)
+ config = Pleroma.Config.get(
Pleroma.Upload
)
with uploader <- Keyword.fetch!(config, :uploader),
proxy_remote = Keyword.get(config, :proxy_remote, false),
with uploader <- Keyword.fetch!(config, :uploader),
proxy_remote = Keyword.get(config, :proxy_remote, false),
@@
-43,7
+52,7
@@
defmodule Pleroma.Plugs.UploadedMedia do
else
_ ->
conn
else
_ ->
conn
- |> send_resp(
500, "Failed"
)
+ |> send_resp(
:internal_server_error, dgettext("errors", "Failed")
)
|> halt()
end
end
|> halt()
end
end
@@
-62,7
+71,7
@@
defmodule Pleroma.Plugs.UploadedMedia do
conn
else
conn
conn
else
conn
- |> send_resp(
404, "Not found"
)
+ |> send_resp(
:not_found, dgettext("errors", "Not found")
)
|> halt()
end
end
|> halt()
end
end
@@
-82,7
+91,7
@@
defmodule Pleroma.Plugs.UploadedMedia do
Logger.error("#{__MODULE__}: Unknown get startegy: #{inspect(unknown)}")
conn
Logger.error("#{__MODULE__}: Unknown get startegy: #{inspect(unknown)}")
conn
- |> send_resp(
500, "Internal Error"
)
+ |> send_resp(
:internal_server_error, dgettext("errors", "Internal Error")
)
|> halt()
end
end
|> halt()
end
end