To prevent exposure of internal technical information.
defmodule MyApp.Router do
use Plug.Router
plug :match
plug :dispatch
get "/" do
conn
|> put_resp_header("X-Server-IP", "192.168.0.1")
|> send_resp(200, "Welcome to MyApp!")
end
end
This code is vulnerable because it sets a response header (
X-Server-IP
) with the internal IP address of the server (
192.168.0.1
). This exposes internal technical information that could be exploited by an attacker.
defmodule MyApp.Router do
use Plug.Router
plug :match
plug :dispatch
get "/" do
send_resp(conn, 200, "Welcome to MyApp!")
end
end
In this secure code example, the response header setting the
X-Server-IP
has been removed. The application no longer exposes the server's internal IP address in its responses.