{"record":{"id":"46d37c8512658a70","repo":"grafana/k6","slug":"exponent-e-is-required","errorCode":null,"errorMessage":"exponent (e) is required","messagePattern":"exponent \\(e\\) is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/webcrypto/jwk.go","lineNumber":318,"sourceCode":"\tD   string `json:\"d,omitempty\"`  // Private exponent\n\tP   string `json:\"p,omitempty\"`  // First prime factor\n\tQ   string `json:\"q,omitempty\"`  // Second prime factor\n\tDp  string `json:\"dp,omitempty\"` // Exponent1\n\tDq  string `json:\"dq,omitempty\"` // Exponent2\n\tQi  string `json:\"qi,omitempty\"` // Coefficient\n}\n\nfunc (jwk *rsaJWK) validate() error {\n\tif jwk.Kty != \"RSA\" {\n\t\treturn fmt.Errorf(\"invalid key type: %s\", jwk.Kty)\n\t}\n\n\tif jwk.N == \"\" {\n\t\treturn errors.New(\"modulus (n) is required\")\n\t}\n\n\tif jwk.E == \"\" {\n\t\treturn errors.New(\"exponent (e) is required\")\n\t}\n\n\t// TODO: consider validating the other fields in future\n\treturn nil\n}\n\nfunc importRSAJWK(jsonKeyData []byte) (any, CryptoKeyType, int, error) {\n\tvar jwk rsaJWK\n\tif err := json.Unmarshal(jsonKeyData, &jwk); err != nil {\n\t\treturn nil, UnknownCryptoKeyType, 0, fmt.Errorf(\"failed to parse input as RSA JWK key: %w\", err)\n\t}\n\n\tif err := jwk.validate(); err != nil {\n\t\treturn nil, UnknownCryptoKeyType, 0, fmt.Errorf(\"invalid RSA JWK key: %w\", err)\n\t}\n\n\t// decode the various key components\n\tnBytes, err := base64URLDecode(jwk.N)","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/js/modules/k6/webcrypto/jwk.go#L300-L336","documentation":"Thrown when crypto.subtle.importKey receives a JWK with kty 'RSA' that is missing the 'e' (public exponent) member. rsaJWK.validate() checks n first, then e (internal/js/modules/k6/webcrypto/jwk.go:317), so this error means the modulus was present but the exponent was not. The importKey promise rejects with this message.","triggerScenarios":"Calling crypto.subtle.importKey('jwk', { kty: 'RSA', n: '...' }, { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, true, ['verify']) — the JWK has a modulus but no e member.","commonSituations":"Hand-editing a JWK and dropping the exponent; JSON with 'E' uppercase or 'exp' (a JWT-claims name) instead of 'e'; a JWK round-tripped through code that renamed or stripped short fields.","solutions":["Add the 'e' member as unpadded base64url — for the standard exponent 65537 that is 'AQAB'","Re-export the JWK with crypto.subtle.exportKey('jwk', key) so no field is lost","Validate that both n and e are present before importKey"],"exampleFix":"// before\nconst jwk = { kty: 'RSA', n: 'vHkg...' };\nconst key = await crypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']);\n\n// after\nconst jwk = { kty: 'RSA', n: 'vHkg...', e: 'AQAB' };\nconst key = await crypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']);","handlingStrategy":"validation","validationCode":"if (!jwk || typeof jwk.e !== 'string' || jwk.e === '') {\n  throw new Error(`RSA JWK needs a public exponent (e), e.g. 'AQAB' for 65537`);\n}\nawait crypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, true, ['encrypt']);","typeGuard":"function hasRsaExponent(v) {\n  return !!v && v.kty === 'RSA' && typeof v.e === 'string' && v.e !== '';\n}","tryCatchPattern":"try {\n  const key = await crypto.subtle.importKey('jwk', jwk, alg, true, usages);\n} catch (err) {\n  if (/exponent \\(e\\) is required/.test(String(err))) {\n    throw new Error(`RSA JWK missing exponent — for 65537 use e: 'AQAB'`);\n  }\n  throw err;\n}","preventionTips":["Use 'AQAB' (65537) as the default exponent when constructing JWKs","Beware near-miss field names: 'E', 'exp', 'exponent' are all wrong","Round-trip keys through exportKey/importKey to prove the JWK is complete"],"tags":["webcrypto","jwk","rsa","importkey","key-validation"],"backgroundTag":"jwk-validation-failed","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"}