Skip to content

refactor(auth): normalize IPv6 loopback hostname checks - #210

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

refactor(auth): normalize IPv6 loopback hostname checks#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
@mldangelo-oai mldangelo-oai added duplicate This issue or pull request already exists and removed bug Something isn't working labels Aug 3, 2026
@mldangelo-oai mldangelo-oai changed the title fix: normalize IPv6 hostnames in preferredAuthUrl loopback filter refactor(auth): normalize IPv6 loopback hostname checks Aug 3, 2026
@mldangelo-oai

Copy link
Copy Markdown
Collaborator

Maintainer overlap check: all 17 authentication tests from this branch, including its new IPv6 fixtures, also pass against unchanged current-main production code. JavaScript URL parsing already canonicalizes the loopback forms covered here, so the existing duplicate label refers to functionality already present on main rather than another missing fix PR. Thank you for checking this boundary; keeping the PR open while we decide next steps.

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

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants