Don't track route not found errors
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
defmodule MusicLibrary.ErrorIgnorer do
|
||||
@moduledoc """
|
||||
Ignores errors that should not be tracked by ErrorTracker.
|
||||
|
||||
Bot scanners and crawlers routinely hit non-existent paths, generating
|
||||
NoRouteError exceptions that are not actionable. We ignore them here
|
||||
rather than blocking specific paths in the endpoint.
|
||||
"""
|
||||
@behaviour ErrorTracker.Ignorer
|
||||
|
||||
@ignored_kinds [
|
||||
to_string(Phoenix.Router.NoRouteError)
|
||||
]
|
||||
|
||||
@impl true
|
||||
def ignore?(%ErrorTracker.Error{kind: kind}, _context) when kind in @ignored_kinds, do: true
|
||||
def ignore?(_error, _context), do: false
|
||||
end
|
||||
@@ -43,8 +43,6 @@ defmodule MusicLibraryWeb.Endpoint do
|
||||
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :music_library
|
||||
end
|
||||
|
||||
plug :reject_bot_scanners
|
||||
|
||||
plug Phoenix.LiveDashboard.RequestLogger,
|
||||
param_key: "request_logger",
|
||||
cookie_key: "request_logger"
|
||||
@@ -61,29 +59,4 @@ defmodule MusicLibraryWeb.Endpoint do
|
||||
plug Plug.Head
|
||||
plug Plug.Session, @session_options
|
||||
plug MusicLibraryWeb.Router
|
||||
|
||||
defp reject_bot_scanners(%{request_path: "/wp-" <> _} = conn, _opts),
|
||||
do: conn |> send_resp(404, "") |> halt()
|
||||
|
||||
defp reject_bot_scanners(%{request_path: "/wordpress" <> _} = conn, _opts),
|
||||
do: conn |> send_resp(404, "") |> halt()
|
||||
|
||||
@blocked_paths [
|
||||
"/.env",
|
||||
"/admin",
|
||||
"/blog/wp-includes/wlwmanifest.xml",
|
||||
"/files.php",
|
||||
"/grsiuk.php",
|
||||
"/jq.php",
|
||||
"/style.php",
|
||||
"/vgtyu.php",
|
||||
"/vx.php",
|
||||
"/xleet.php",
|
||||
"/xmlrpc.php"
|
||||
]
|
||||
|
||||
defp reject_bot_scanners(%{request_path: path} = conn, _opts) when path in @blocked_paths,
|
||||
do: conn |> send_resp(404, "") |> halt()
|
||||
|
||||
defp reject_bot_scanners(conn, _opts), do: conn
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user