Prevent credit card information from being exposed in responses
defmodule MyApp.UserController do
use MyApp, :controller
def show(conn, %{"id" => id}) do
user = Repo.get!(User, id)
render(conn, "show.json", user: user)
end
end
defmodule MyApp.UserView do
use MyApp, :view
def render("show.json", %{user: user}) do
%{id: user.id, name: user.name, credit_card: user.credit_card}
end
end
This code is returning the user's credit card information in the response to the 'show' request. If an attacker can access the responses to these requests, they can obtain sensitive credit card information.
defmodule MyApp.UserController do
use MyApp, :controller
def show(conn, %{"id" => id}) do
user = Repo.get!(User, id)
render(conn, "show.json", user: user)
end
end
defmodule MyApp.UserView do
use MyApp, :view
def render("show.json", %{user: user}) do
%{id: user.id, name: user.name}
end
end
The secure code does not include the user's credit card information in the response, thus protecting sensitive data.