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
- Authenticate to an Azure tenant via
az login --tenant <tenant-id>
- Get a Graph token:
az account get-access-token --resource https://graph.microsoft.com
- 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:
Summary
AzureHound fails to parse certain valid Azure AD/Entra ID JWTs with the error:
Root Cause
In
client/rest/utils.goline 90,ParseBody()usesbase64.RawStdEncodingto decode the JWT payload:Per RFC 7519, JWTs use base64url encoding (RFC 4648 §5), which uses
-and_characters instead of+and/.RawStdEncodingrejects-and_as illegal characters.Fix
Replace
base64.RawStdEncodingwithbase64.RawURLEncodingon line 90 ofclient/rest/utils.go:Reproduction
az login --tenant <tenant-id>az account get-access-token --resource https://graph.microsoft.comazurehound.exe list --jwt "<token>" -o output.jsonThis 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
az account get-access-token)References
This is a well-known class of bug in Go JWT libraries: