diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/gopher/server.ex | 10 | ||||
-rw-r--r-- | lib/pleroma/plugs/http_signature.ex | 29 |
2 files changed, 26 insertions, 13 deletions
diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index cfce4c05c..82e241f21 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -51,8 +51,9 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do def info(text) do text = String.replace(text, ~r/[\t\n]/, "") + String.split(text, "\r") - |> Enum.map(fn (text) -> + |> Enum.map(fn text -> "i#{text}\tfake\(NULL)\t0\r\n" end) |> Enum.join("") @@ -82,7 +83,12 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do link("Post ##{activity.id} by #{user.nickname}", "/notices/#{activity.id}") <> info("#{like_count} likes, #{announcement_count} repeats") <> - "\r\n" <> info(HtmlSanitizeEx.strip_tags(String.replace(activity.data["object"]["content"], "<br>", "\r"))) + "\r\n" <> + info( + HtmlSanitizeEx.strip_tags( + String.replace(activity.data["object"]["content"], "<br>", "\r") + ) + ) end) |> Enum.join("\r\n") end diff --git a/lib/pleroma/plugs/http_signature.ex b/lib/pleroma/plugs/http_signature.ex index af160f3ee..8b9ccdd2d 100644 --- a/lib/pleroma/plugs/http_signature.ex +++ b/lib/pleroma/plugs/http_signature.ex @@ -14,19 +14,26 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do def call(conn, opts) do user = conn.params["actor"] Logger.debug("Checking sig for #{user}") + [signature | _] = get_req_header(conn, "signature") - if get_req_header(conn, "signature") do - conn = - conn - |> put_req_header( - "(request-target)", - String.downcase("#{conn.method}") <> " #{conn.request_path}" - ) + cond do + signature && String.contains?(signature, user) -> + conn = + conn + |> put_req_header( + "(request-target)", + String.downcase("#{conn.method}") <> " #{conn.request_path}" + ) + + assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn)) - assign(conn, :valid_signature, HTTPSignatures.validate_conn(conn)) - else - Logger.debug("No signature header!") - conn + signature -> + Logger.debug("Signature not from actor") + assign(conn, :valid_signature, false) + + true -> + Logger.debug("No signature header!") + conn end end end |