Secure transfer of sensitive data
def login(conn, %{"username" => username, "password" => password}) do
redirect(conn, to: "/home?username=#{username}&password=#{password}")
end
In the insecure code example, the server sends sensitive information (user credentials) as GET parameters. These parameters are included in the URL and can be easily intercepted by malicious parties. This puts the user's credentials at risk of being compromised.
def login(conn, %{"username" => username, "password" => password}) do
# store the username and password in the session
conn
|> put_session(:username, username)
|> put_session(:password, password)
|> redirect(to: "/home")
end
In the secure code example, sensitive information (user credentials) is stored in the session instead of being sent as GET parameters. This prevents the sensitive information from being included in the URL and therefore reduces the risk of it being intercepted by malicious parties.