To prevent unauthorized disclosure of technical details which could be exploited for crafting new attack vectors.
defmodule MyAppWeb.MyController do
use MyAppWeb, :controller
def index(conn, _params) do
conn
|> put_resp_header("server", "Plug/1.12.0")
|> send_resp(200, "Hello, world!")
end
end
In the insecure code, the server includes a 'server' response header that reveals the version of the Plug package it's using. This information could be used by an attacker to find vulnerabilities in that specific version and exploit them.
defmodule MyAppWeb.MyController do
use MyAppWeb, :controller
def index(conn, _params) do
send_resp(conn, 200, "Hello, world!")
end
end
In the secure code, the server doesn't include any headers that reveal technical details about its configuration. This makes it harder for an attacker to find and exploit vulnerabilities.