aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2020-10-28 15:06:47 +0000
committerfeld <feld@feld.me>2020-10-28 15:06:47 +0000
commit342c2e1bc0055b71a9772ef031eab3e8bc88d29b (patch)
tree3849f7dbb2a5906ebe1d25f7af9b2d79cbe7e5a1 /lib
parent1204aaa2e35983f7361d61ee7906ccf3d09d84e4 (diff)
parentd2b140a525b6ba04542f13678a2243147010f713 (diff)
downloadpleroma-342c2e1bc0055b71a9772ef031eab3e8bc88d29b.tar.gz
Merge branch 'issue/2261' into 'develop'
[#2261] FrontStatic plug: excluded invalid url See merge request pleroma/pleroma!3106
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/plugs/frontend_static.ex26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/pleroma/web/plugs/frontend_static.ex b/lib/pleroma/web/plugs/frontend_static.ex
index ceb10dcf8..1b0b36813 100644
--- a/lib/pleroma/web/plugs/frontend_static.ex
+++ b/lib/pleroma/web/plugs/frontend_static.ex
@@ -34,22 +34,26 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
end
def call(conn, opts) do
- frontend_type = Map.get(opts, :frontend_type, :primary)
- path = file_path("", frontend_type)
-
- if path do
- conn
- |> call_static(opts, path)
+ with false <- invalid_path?(conn.path_info),
+ frontend_type <- Map.get(opts, :frontend_type, :primary),
+ path when not is_nil(path) <- file_path("", frontend_type) do
+ call_static(conn, opts, path)
else
- conn
+ _ ->
+ conn
end
end
- defp call_static(conn, opts, from) do
- opts =
- opts
- |> Map.put(:from, from)
+ defp invalid_path?(list) do
+ invalid_path?(list, :binary.compile_pattern(["/", "\\", ":", "\0"]))
+ end
+ defp invalid_path?([h | _], _match) when h in [".", "..", ""], do: true
+ defp invalid_path?([h | t], match), do: String.contains?(h, match) or invalid_path?(t)
+ defp invalid_path?([], _match), do: false
+
+ defp call_static(conn, opts, from) do
+ opts = Map.put(opts, :from, from)
Plug.Static.call(conn, opts)
end
end