forked from AkkomaGang/akkoma
strip \r and \r from content-disposition filenames
This commit is contained in:
parent
dcc36df8cf
commit
bab1ab5b6c
2 changed files with 19 additions and 1 deletions
|
@ -35,7 +35,7 @@ def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do
|
||||||
conn =
|
conn =
|
||||||
case fetch_query_params(conn) do
|
case fetch_query_params(conn) do
|
||||||
%{query_params: %{"name" => name}} = conn ->
|
%{query_params: %{"name" => name}} = conn ->
|
||||||
name = String.replace(name, "\"", "\\\"")
|
name = escape_header_value(name)
|
||||||
|
|
||||||
put_resp_header(conn, "content-disposition", "filename=\"#{name}\"")
|
put_resp_header(conn, "content-disposition", "filename=\"#{name}\"")
|
||||||
|
|
||||||
|
@ -98,4 +98,11 @@ defp get_media(conn, unknown, _) do
|
||||||
|> send_resp(:internal_server_error, dgettext("errors", "Internal Error"))
|
|> send_resp(:internal_server_error, dgettext("errors", "Internal Error"))
|
||||||
|> halt()
|
|> halt()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp escape_header_value(value) do
|
||||||
|
value
|
||||||
|
|> String.replace("\"", "\\\"")
|
||||||
|
|> String.replace("\\r", "")
|
||||||
|
|> String.replace("\\n", "")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,4 +40,15 @@ test "sends Content-Disposition header when name param is set", %{
|
||||||
&(&1 == {"content-disposition", "filename=\"\\\"cofe\\\".gif\""})
|
&(&1 == {"content-disposition", "filename=\"\\\"cofe\\\".gif\""})
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "removes control characters from the Content-Disposition header", %{
|
||||||
|
attachment_url: attachment_url
|
||||||
|
} do
|
||||||
|
conn = get(build_conn(), attachment_url <> "?name=\"cofe\".gif\\r\\n")
|
||||||
|
|
||||||
|
assert Enum.any?(
|
||||||
|
conn.resp_headers,
|
||||||
|
&(&1 == {"content-disposition", "filename=\"\\\"cofe\\\".gif\""})
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue