From b235f545f259e8cf9c0e16793e1a448b1e9f105b Mon Sep 17 00:00:00 2001 From: liamwhite Date: Sat, 18 May 2024 16:29:27 -0400 Subject: [PATCH] Truncate incoming referrer string (#260) --- lib/philomena_web/plugs/user_attribution_plug.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/philomena_web/plugs/user_attribution_plug.ex b/lib/philomena_web/plugs/user_attribution_plug.ex index f2fb2ed6..bfbd5da8 100644 --- a/lib/philomena_web/plugs/user_attribution_plug.ex +++ b/lib/philomena_web/plugs/user_attribution_plug.ex @@ -24,7 +24,7 @@ defmodule PhilomenaWeb.UserAttributionPlug do attributes = [ ip: remote_ip, fingerprint: fingerprint(conn, conn.path_info), - referrer: conn.assigns.referrer, + referrer: referrer(conn.assigns.referrer), user: user, user_agent: user_agent(conn) ] @@ -47,4 +47,7 @@ defmodule PhilomenaWeb.UserAttributionPlug do defp fingerprint(conn, _) do conn.cookies["_ses"] end + + defp referrer(nil), do: nil + defp referrer(r), do: String.slice(r, 0, 255) end