logo

Sensitive Information Sent Insecurely - Elixir


Need

Secure transfer of sensitive data


Context

  1. Usage of Elixir (1.10 and above) for building scalable and fault-tolerant applications
  2. Usage of Phoenix web framework for building scalable and fault-tolerant web applications

Description

Insecure Code Example

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.

Steps

  1. Instead of sending sensitive information as GET parameters, send them as POST parameters.
  2. Update the routes and the form to use the POST method instead of GET.
  3. Modify the function to accept POST parameters instead of GET parameters.
  4. Test the changes to make sure everything works as expected.

Secure Code Example

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.


References

  • 017 - Sensitive Information Sent Insecurely

  • Last updated

    2023/09/18