Files
coder/codersdk/oauth2_validation_internal_test.go
T
Bobby Ho 0ad8eebbf7 fix: allow any port on loopback OAuth2 redirect URIs (#29013)
Fix: Allow variable ports for registered HTTP loopback redirect URIs (127.0.0.1, [::1], and localhost), enabling native apps to use dynamically assigned ports. Apply this registration-matching exception at both authorization and token endpoints while preserving the presented port.

Safeguards: Keep all other URI components and non-loopback matching unchanged, and retain exact code-to-token redirect URI matching, including the port.

Implementation and verification: Add shared matching logic, automated tests, and updated documentation. All 29 manual scenarios passed, although browser click-through to a listener on an OS-chosen port was not tested.
2026-09-08 17:40:10 -07:00

20 lines
479 B
Go

package codersdk
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestIsLoopbackAddress(t *testing.T) {
t.Parallel()
for _, host := range []string{"localhost", "127.0.0.1", "::1"} {
require.True(t, isLoopbackAddress(host), host)
}
// Callers pass url.URL.Hostname(), which strips IPv6 brackets.
for _, host := range []string{"", "[::1]", "app.localhost", "127.0.0.2", "0.0.0.0", "example.com"} {
require.False(t, isLoopbackAddress(host), host)
}
}