From f17612c5d9f045ec6bb8f025e80b9528146df995 Mon Sep 17 00:00:00 2001 From: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:13:37 +0530 Subject: [PATCH] fix: sanitize remoteConfigURL to prevent 400 Bad Request on bandwidth reports (#82) When REMOTE_CONFIG was provided with a trailing slash (e.g. .../gerbil/get-config/ or .../gerbil/), the old TrimSuffix logic failed to strip /gerbil/get-config due to the trailing slash, resulting in invalid endpoint URLs like http://pangolin:3001/api/v1/gerbil/get-config/gerbil/receive-bandwidth. This caused Express/Traefik to return 400 Bad Request every 10 seconds. Fix: Robustly strip trailing slashes before and after removing legacy subpaths (/gerbil/get-config, /gerbil/receive-bandwidth, /gerbil). Fixes #82 --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index a6c5205..3bbf76d 100644 --- a/main.go +++ b/main.go @@ -429,9 +429,12 @@ func main() { logger.Fatal("You must provide either a config file or a remote config URL, not both") } - // clean up the reomte config URL for backwards compatibility + // clean up the remote config URL for backwards compatibility + remoteConfigURL = strings.TrimRight(remoteConfigURL, "/") remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil/get-config") - remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/") + remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil/receive-bandwidth") + remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil") + remoteConfigURL = strings.TrimRight(remoteConfigURL, "/") var key wgtypes.Key // if generateAndSaveKeyTo is provided, generate a private key and save it to the file. if the file already exists, load the key from the file