Commit 4b3c86c1 authored by kaniini's avatar kaniini
Browse files

Merge branch 'fix/mediaproxy-capture-content-disposition-filename' into 'develop'

MediaProxy: parse filename from content-disposition for non-whitelisted types

See merge request !936
parents 8b352af4 d02f1120
Pipeline #9035 passed with stages
in 4 minutes and 28 seconds
......@@ -311,7 +311,25 @@ defp build_resp_content_disposition_header(headers, opts) do
end
if attachment? do
disposition = "attachment; filename=" <> Keyword.get(opts, :attachment_name, "attachment")
name =
try do
{{"content-disposition", content_disposition_string}, _} =
List.keytake(headers, "content-disposition", 0)
[name | _] =
Regex.run(
~r/filename="((?:[^"\\]|\\.)*)"/u,
content_disposition_string || "",
capture: :all_but_first
)
name
rescue
MatchError -> Keyword.get(opts, :attachment_name, "attachment")
end
disposition = "attachment; filename=\"#{name}\""
List.keystore(headers, "content-disposition", 0, {"content-disposition", disposition})
else
headers
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment