fix(06-12): reject typed-nil guards and fractional JWT subjects

This commit is contained in:
Jakub Zych
2026-09-21 19:43:35 +02:00
parent 4ad2ad29f2
commit 8a9449df63
4 changed files with 38 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"net/http"
"strconv"
"strings"
@@ -148,12 +149,16 @@ func subject(claims jwt.MapClaims) string {
case string:
return strings.TrimSpace(v)
case float64:
if v <= 0 {
if math.IsNaN(v) || math.IsInf(v, 0) || v <= 0 || v != math.Trunc(v) || v > 9007199254740992 {
return ""
}
return strconv.FormatInt(int64(v), 10)
case json.Number:
return strings.TrimSpace(v.String())
n, err := strconv.ParseInt(strings.TrimSpace(v.String()), 10, 64)
if err != nil || n <= 0 {
return ""
}
return strconv.FormatInt(n, 10)
default:
return ""
}