{"record":{"id":"6dfc230d136afb44","repo":"grafana/k6","slug":"invalid-key-type-s","errorCode":null,"errorMessage":"invalid key type: %s","messagePattern":"invalid key type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":40,"sourceCode":"\n// JsonWebKey represents a JSON Web Key (JsonWebKey) key.\ntype JsonWebKey map[string]any //nolint:revive // we name this type JsonWebKey to match the spec\n\n// Set sets a key-value pair in the JWK.\nfunc (jwk *JsonWebKey) Set(key string, value any) {\n\t(*jwk)[key] = value\n}\n\n// symmetricJWK represents a symmetric JWK key.\n// It is used to unmarshal symmetric keys from JWK format.\ntype symmetricJWK struct {\n\tKty string `json:\"kty\"`\n\tK   string `json:\"k\"`\n}\n\nfunc (jwk *symmetricJWK) validate() error {\n\tif jwk.Kty != JWKOctKeyType {\n\t\treturn fmt.Errorf(\"invalid key type: %s\", jwk.Kty)\n\t}\n\n\tif jwk.K == \"\" {\n\t\treturn errors.New(\"key (k) is required\")\n\t}\n\n\treturn nil\n}\n\n// extractSymmetricJWK extracts the symmetric key from a given JWK key (JSON data).\nfunc extractSymmetricJWK(jsonKeyData []byte) ([]byte, error) {\n\tsk := symmetricJWK{}\n\tif err := json.Unmarshal(jsonKeyData, &sk); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse symmetric JWK: %w\", err)\n\t}\n\n\tif err := sk.validate(); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid symmetric JWK: %w\", err)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/webcrypto/jwk.go#L22-L58","documentation":"Returned by the symmetricJWK validator during JWK import (crypto.subtle.importKey with jwk format). The JSON parsed successfully but its `kty` (key type) field is anything other than \"oct\", which is the only key type accepted for symmetric (HMAC/AES) key import. The actual kty value is included in the message, revealing what kind of key was supplied instead.","triggerScenarios":"Thrown at internal/js/modules/k6/webcrypto/jwk.go:39 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a JWK with \"kty\": \"oct\" for symmetric key import","For EC keys (kty EC) or RSA keys (kty RSA), pass the JWK to the appropriate algorithm import — k6 dispatches on the algorithm, so verify the algorithm name matches the key type"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}