diff options
author | lain <lain@soykaf.club> | 2018-04-02 13:13:14 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2018-04-02 13:13:14 +0200 |
commit | 0a14d155d6a55366449bc8dea638e24200bb3dd0 (patch) | |
tree | 1c320a672a5fddeba5aa10eb43ea5470d924bce8 /lib | |
parent | 1b57522bba4bbe2843b7c68d37e0530387e5b8f3 (diff) | |
download | pleroma-0a14d155d6a55366449bc8dea638e24200bb3dd0.tar.gz |
Fail faster.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/plugs/http_signature.ex | 29 |
1 files changed, 18 insertions, 11 deletions
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 |