To prevent the increase in the chance of exploiting a stored XSS
defmodule Vulnerable do
use Plug.Router
plug :put_secure_browser_headers
plug :match
plug :dispatch
get "" do
conn
|> put_resp_header("x-xss-protection", "1; mode=block")
|> send_resp(200, "OK")
end
match _ do
send_resp(conn, 404, "Not found")
end
end
In this Elixir code snippet, the application is using the deprecated X-XSS Protection header.
defmodule Secure do
use Plug.Router
plug :put_secure_browser_headers
plug :match
plug :dispatch
get "" do
conn
|> put_resp_header("content-security-policy", "default-src 'self'")
|> send_resp(200, "OK")
end
match _ do
send_resp(conn, 404, "Not found")
end
end
In this Elixir code snippet, the application is using CSP (Content Security Policy) header instead of the deprecated X-XSS Protection header.