grafana/k6 · error
failed to parse symmetric JWK
Error message
failed to parse symmetric JWK: %w
What it means
Returned by extractSymmetricJWK when the key data passed to crypto.subtle.importKey(format='jwk') is not valid JSON — json.Unmarshal fails, so the raw bytes can never represent a JWK object. The wrapped error details the exact JSON syntax problem (offset, unexpected token, etc.).
Solutions
- Pass a properly serialized JWK object: JSON.stringify(jwk) or the raw JSON string
- Validate the JSON in the script before import, e.g. with JSON.parse in a try/catch
- Check for truncated key material or BOM characters in embedded key files
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/js/modules/k6/webcrypto/jwk.go:53 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/c0b0189813586389.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/webcrypto/jwk.go:54
}
func (jwk *symmetricJWK) validate() error {
if jwk.Kty != JWKOctKeyType {
return fmt.Errorf("invalid key type: %s", jwk.Kty)
}
if jwk.K == "" {
return errors.New("key (k) is required")
}
return nil
}
// extractSymmetricJWK extracts the symmetric key from a given JWK key (JSON data).
func extractSymmetricJWK(jsonKeyData []byte) ([]byte, error) {
sk := symmetricJWK{}
if err := json.Unmarshal(jsonKeyData, &sk); err != nil {
return nil, fmt.Errorf("failed to parse symmetric JWK: %w", err)
}
if err := sk.validate(); err != nil {
return nil, fmt.Errorf("invalid symmetric JWK: %w", err)
}
skBytes, err := base64URLDecode(sk.K)
if err != nil {
return nil, fmt.Errorf("failed to decode symmetric key: %w", err)
}
return skBytes, nil
}
// exportSymmetricJWK exports a symmetric key as a map of JWK key parameters.
func exportSymmetricJWK(key *CryptoKey) (*JsonWebKey, error) {
rawKey, ok := key.handle.([]byte)
if !ok {View on GitHub (pinned to 8d06114777)