Hardcoded JWT Signing Key (ARCH5137)
Ce contenu n’est pas encore disponible dans votre langue.
Key go.security.hardcoded-jwt-signing-key · Severity error · Category security · CWE CWE-321
Embedding a JWT/HMAC signing key as a literal in source compromises token integrity the moment the source leaks. An attacker can then sign their own valid tokens.
Incorrect
Section titled “Incorrect”token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)signed, _ := token.SignedString([]byte("super-secret-key"))Correct
Section titled “Correct”secret := []byte(os.Getenv("JWT_SIGNING_KEY"))token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)signed, _ := token.SignedString(secret)Read the signing key from an environment variable or a secret manager; never embed it in code.