Skip to content

fix: normalize IPv6 hostnames in preferredAuthUrl loopback filter - #210

Open
nidsnitesh wants to merge 1 commit into
openai:mainfrom
nidsnitesh:fix/auth-ipv6-loopback-filter
Open

fix: normalize IPv6 hostnames in preferredAuthUrl loopback filter#210
nidsnitesh wants to merge 1 commit into
openai:mainfrom
nidsnitesh:fix/auth-ipv6-loopback-filter

Conversation

@nidsnitesh

Copy link
Copy Markdown

Summary

Fixes an issue where IPv6 loopback and IPv4-mapped loopback URLs (e.g. [::1], [::ffff:127.0.0.1], [0:0:0:0:0:0:0:1]) could bypass loopback filtering in preferredAuthUrl.

Details

\x60preferredAuthUrl\x60 parses CLI terminal output to extract valid OAuth login verification URLs while filtering out local listening servers.

Previously, the code compared new URL(url).hostname directly against literal strings like "[::1]" or prefix "[::ffff:7f". Differences in bracket representation, IPv4-mapped notation (127.0.0.1 vs 7f00:1), and expanded zero-segments meant certain loopback URLs were not filtered out.

Fix

  • Implemented isLoopbackHost helper that strips outer brackets ([/]) and handles:
    • IPv4 loopback (127.0.0.0/8, 0.0.0.0)
    • IPv6 loopback (::1, 0:0:0:0:0:0:0:1)
    • IPv6 unspecified (::, 0:0:0:0:0:0:0:0)
    • IPv4-mapped and IPv4-compatible IPv6 loopback (::ffff:127.x, ::ffff:7f..., ::127.x, etc.)
  • Added additional test assertions in sdk/typescript/tests-ts/auth.test.ts.

The preferredAuthUrl function previously compared raw URL hostnames against
bracketed strings like '[::1]' and '[::ffff:7f...'. Depending on URL parser
implementations and IPv6 formats, bracket presence and IPv6 string
representations (such as ::ffff:127.0.0.1 or expanded zero segments) could
bypass the loopback check.

This commit introduces an isLoopbackHost helper that strips outer brackets
and checks IPv4/IPv6 loopback, unspecified, IPv4-mapped, and IPv4-compatible
IP forms, preventing loopback URLs from being selected as authentication endpoints.
@github-actions github-actions Bot added the bug Something isn't working label Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant