Skip to content

Commit

Permalink
Merge pull request #46 from nerdyworm/prevent-uri-decode-error
Browse files Browse the repository at this point in the history
Handle the possibility that the RelayState is nil
  • Loading branch information
handnot2 authored Apr 21, 2019
2 parents 77bb2d8 + b107b82 commit 110d348
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/samly/sp_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Samly.SPHandler do

saml_encoding = conn.body_params["SAMLEncoding"]
saml_response = conn.body_params["SAMLResponse"]
relay_state = conn.body_params["RelayState"] |> URI.decode_www_form()
relay_state = conn.body_params["RelayState"] |> safe_decode_www_form()

with {:ok, assertion} <- Helper.decode_idp_auth_resp(sp, saml_encoding, saml_response),
:ok <- validate_authresp(conn, assertion, relay_state),
Expand Down Expand Up @@ -126,7 +126,7 @@ defmodule Samly.SPHandler do

saml_encoding = conn.body_params["SAMLEncoding"]
saml_response = conn.body_params["SAMLResponse"]
relay_state = conn.body_params["RelayState"] |> URI.decode_www_form()
relay_state = conn.body_params["RelayState"] |> safe_decode_www_form()

with {:ok, _payload} <- Helper.decode_idp_signout_resp(sp, saml_encoding, saml_response),
^relay_state when relay_state != nil <- get_session(conn, "relay_state"),
Expand All @@ -153,7 +153,7 @@ defmodule Samly.SPHandler do

saml_encoding = conn.body_params["SAMLEncoding"]
saml_request = conn.body_params["SAMLRequest"]
relay_state = conn.body_params["RelayState"] |> URI.decode_www_form()
relay_state = conn.body_params["RelayState"] |> safe_decode_www_form()

with {:ok, payload} <- Helper.decode_idp_signout_req(sp, saml_encoding, saml_request) do
Esaml.esaml_logoutreq(name: nameid, issuer: _issuer) = payload
Expand Down Expand Up @@ -193,4 +193,7 @@ defmodule Samly.SPHandler do
# Logger.error("#{inspect error}")
# conn |> send_resp(500, "request_failed")
end

defp safe_decode_www_form(nil), do: ""
defp safe_decode_www_form(data), do: URI.decode_www_form(data)
end

0 comments on commit 110d348

Please sign in to comment.