Skip to content

fix: prevent token leak via URL userinfo host confusion#2000

Merged
gavinbarron merged 2 commits into
devfrom
mmainer/sec-user-info-host-confusion
Jun 16, 2026
Merged

fix: prevent token leak via URL userinfo host confusion#2000
gavinbarron merged 2 commits into
devfrom
mmainer/sec-user-info-host-confusion

Conversation

@MIchaelMainer

Copy link
Copy Markdown
Contributor

Summary

Changes Made

  1. src/GraphRequestUtil.ts — isValidEndpoint (root cause fix)

Replaced the hand-rolled indexOf(":") host extraction with new URL() parsing:

  • Rejects non-HTTPS URLs
  • Rejects any URL containing userinfo (username/password) — blocks the host-confusion attack
  • Uses parsedUrl.hostname (which correctly resolves the actual host, excluding userinfo and port)
  1. src/GraphRequest.ts — parsePath (defense-in-depth)

Added new URL() validation at the entry point of path parsing:

  • Rejects malformed URLs with a clear error
  • Throws if userinfo is present — prevents credentialed URLs from ever entering the request pipeline
  • After validation, uses the original string for host/path extraction (preserving encoding and port for backward compatibility)

Motivation

A vulnerability in the Microsoft Graph SDK for JavaScript allows an attacker to exploit a host-classification bug in the isValidEndpoint function, causing the SDK to misclassify attacker-controlled URLs as valid Microsoft Graph endpoints. This results in the SDK attaching and sending the caller's Microsoft Graph bearer token to the attacker's host. The issue is confirmed in version 3.0.7 and earlier, specifically when using the node-fetch runtime. The root cause is improper URL parsing that fails to correctly identify the real host when userinfo is included in the URL. The vulnerability can lead to the exposure of sensitive tokens, which can be replayed against Microsoft Graph services within the token's granted scopes.

Test plan

Regression tests added

  • test/common/core/GraphRequestUtil.ts — tests for isGraphURL and isCustomHost covering all attack vectors
  • test/common/core/urlParsing.ts — tests that parsePath throws on userinfo URLs

@MIchaelMainer MIchaelMainer requested a review from a team as a code owner June 15, 2026 23:24
Comment thread src/GraphRequest.ts
@gavinbarron gavinbarron merged commit 5438ae9 into dev Jun 16, 2026
9 checks passed
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.

3 participants