mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 11:12:15 +03:00
Ignores invalid query param part
This commit is contained in:
parent
6dd9b0bb2f
commit
710f6f568a
@ -83,7 +83,7 @@ defmodule PlausibleWeb.Api.ExternalController do
|
|||||||
else
|
else
|
||||||
uri = params["url"] && URI.parse(params["url"])
|
uri = params["url"] && URI.parse(params["url"])
|
||||||
host = if uri && uri.host == "", do: "(none)", else: uri && uri.host
|
host = if uri && uri.host == "", do: "(none)", else: uri && uri.host
|
||||||
query = if uri && uri.query, do: URI.decode_query(uri.query), else: %{}
|
query = decode_query_params(uri)
|
||||||
|
|
||||||
ref = parse_referrer(uri, params["referrer"])
|
ref = parse_referrer(uri, params["referrer"])
|
||||||
country_code = visitor_country(conn)
|
country_code = visitor_country(conn)
|
||||||
@ -347,4 +347,15 @@ defmodule PlausibleWeb.Api.ExternalController do
|
|||||||
do: true
|
do: true
|
||||||
|
|
||||||
defp right_uri?(_), do: false
|
defp right_uri?(_), do: false
|
||||||
|
|
||||||
|
defp decode_query_params(nil), do: nil
|
||||||
|
defp decode_query_params(%URI{query: nil}), do: nil
|
||||||
|
|
||||||
|
defp decode_query_params(%URI{query: query_part}) do
|
||||||
|
try do
|
||||||
|
URI.decode_query(query_part)
|
||||||
|
rescue
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -688,6 +688,22 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
|
|||||||
assert pageview.utm_source == "%balle%"
|
assert pageview.utm_source == "%balle%"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "ignores invalid query param part", %{conn: conn} do
|
||||||
|
params = %{
|
||||||
|
n: "pageview",
|
||||||
|
u:
|
||||||
|
"https://test.com/?utm_source=Bing%20%7C%20Text%20%7C%20Leads%20%7C%20EIGEN%20NAAM-most%20broad%20(Various%20search%20term%20matches)%20%7C%20Afweging,%20Consumptie%20%7C%20T%3A%",
|
||||||
|
d: "invalid-query-test.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
conn = post(conn, "/api/event", params)
|
||||||
|
|
||||||
|
assert conn.status == 202
|
||||||
|
|
||||||
|
pageview = get_event("invalid-query-test.com")
|
||||||
|
assert pageview.utm_source == ""
|
||||||
|
end
|
||||||
|
|
||||||
test "can use double quotes in query params", %{conn: conn} do
|
test "can use double quotes in query params", %{conn: conn} do
|
||||||
q = URI.encode_query(%{"utm_source" => "Something \"quoted\""})
|
q = URI.encode_query(%{"utm_source" => "Something \"quoted\""})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user