Skip to content

JWT parsing fails with 'illegal base64 data' due to RawStdEncoding vs RawURLEncoding #186

@Mike-Crowley

Description

@Mike-Crowley

Summary

AzureHound fails to parse certain valid Azure AD/Entra ID JWTs with the error:

failed to create new Azure client: illegal base64 data at input byte 1107

Root Cause

In client/rest/utils.go line 90, ParseBody() uses base64.RawStdEncoding to decode the JWT payload:

} else if bytes, err := base64.RawStdEncoding.DecodeString(parts[1]); err != nil {

Per RFC 7519, JWTs use base64url encoding (RFC 4648 §5), which uses - and _ characters instead of + and /. RawStdEncoding rejects - and _ as illegal characters.

Fix

Replace base64.RawStdEncoding with base64.RawURLEncoding on line 90 of client/rest/utils.go:

} else if bytes, err := base64.RawURLEncoding.DecodeString(parts[1]); err != nil {

Reproduction

  1. Authenticate to an Azure tenant via az login --tenant <tenant-id>
  2. Get a Graph token: az account get-access-token --resource https://graph.microsoft.com
  3. Run: azurehound.exe list --jwt "<token>" -o output.json

This fails when the base64-encoded JWT payload contains - or _ characters, which depends on the claim values (user display name, tenant name, etc.). Some tenants produce tokens that happen to avoid these characters, making the bug intermittent.

Environment

  • AzureHound v2.11.0 (Windows amd64)
  • Tokens obtained via Azure CLI (az account get-access-token)

References

This is a well-known class of bug in Go JWT libraries:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions