Skip to content

fix(main): sanitize remoteConfigURL to prevent 400 Bad Request on bandwidth reports (#82) - #106

Open
Adityakk9031 wants to merge 1 commit into
fosrl:mainfrom
Adityakk9031:fix/issue-82
Open

fix(main): sanitize remoteConfigURL to prevent 400 Bad Request on bandwidth reports (#82)#106
Adityakk9031 wants to merge 1 commit into
fosrl:mainfrom
Adityakk9031:fix/issue-82

Conversation

@Adityakk9031

Copy link
Copy Markdown

Summary

Fixes #82.

After updating to Gerbil v1.4, bandwidth reporting failed every 10 seconds with:

Failed to report peer bandwidth: API returned non-OK status: 400 Bad Request

Root Cause

Gerbil v1.4 changed bandwidth reporting to construct the reporting endpoint dynamically from remoteConfigURL:

remoteConfigURL + "/gerbil/receive-bandwidth"

The existing sanitization logic in main.go:

remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil/get-config")
remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/")

failed when REMOTE_CONFIG ended with a trailing slash, for example:

http://pangolin:3001/api/v1/gerbil/get-config/

In this case:

  1. TrimSuffix(..., "/gerbil/get-config") failed because of the trailing /.
  2. TrimSuffix(..., "/") only removed the final slash.
  3. The URL remained:
http://pangolin:3001/api/v1/gerbil/get-config

Gerbil then constructed an invalid endpoint:

http://pangolin:3001/api/v1/gerbil/get-config/gerbil/receive-bandwidth

This targeted a non-existent route, causing the server to return 400 Bad Request every 10 seconds.

Fix

Updated remoteConfigURL sanitization to remove trailing slashes before and after stripping legacy endpoint suffixes.

// Clean up the remote config URL for backwards compatibility.
remoteConfigURL = strings.TrimRight(remoteConfigURL, "/")
remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil/get-config")
remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil/receive-bandwidth")
remoteConfigURL = strings.TrimSuffix(remoteConfigURL, "/gerbil")
remoteConfigURL = strings.TrimRight(remoteConfigURL, "/")

The normalization now correctly handles all supported formats, including:

http://pangolin:3001/api/v1
http://pangolin:3001/api/v1/
http://pangolin:3001/api/v1/gerbil/get-config
http://pangolin:3001/api/v1/gerbil/get-config/
http://pangolin:3001/api/v1/gerbil/receive-bandwidth/

All of these normalize to:

http://pangolin:3001/api/v1

which results in the correct bandwidth reporting endpoint:

http://pangolin:3001/api/v1/gerbil/receive-bandwidth

Testing

  • ✅ Tested REMOTE_CONFIG values with and without trailing slashes.
  • ✅ Tested legacy /gerbil/get-config and /gerbil/receive-bandwidth URLs.
  • ✅ Verified all configurations normalize to the expected base URL.
  • ✅ Confirmed bandwidth reporting succeeds without returning 400 Bad Request.

… reports (fosrl#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 fosrl#82
@Adityakk9031

Copy link
Copy Markdown
Author

@oschwartz10612 and @miloschwartz have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed to report peer bandwidth: API returned non-OK status: 400 Bad Request

1 participant