{"record":{"id":"241107bade81dda9","repo":"JuliusBrussee/caveman","slug":"bedrock-invalid-api-key","errorCode":null,"errorMessage":"bedrock: invalid API key","messagePattern":"bedrock: invalid API key","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/providers/bedrock/signing.go","lineNumber":66,"sourceCode":"\t// Before the signature below covers these headers: a caller must not be able\n\t// to nominate a signed header (x-amz-date, x-amz-security-token) — or the\n\t// Authorization header itself — for removal after this hop builds it.\n\tproviders.RemoveConnectionHeaders(out, req.Header)\n\tif out.Get(\"content-type\") == \"\" {\n\t\tout.Set(\"content-type\", \"application/json\")\n\t}\n\n\tauthKind, err := credentialAuthKind(credential)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif credential.Scheme == \"sigv4\" && authKind != \"aws_access_keys\" {\n\t\treturn nil, ErrSigV4Configuration\n\t}\n\tif authKind == \"bedrock_api_key\" {\n\t\tkey := strings.TrimSpace(credential.Key)\n\t\tif key == \"\" || strings.ContainsAny(key, \"\\r\\n\") {\n\t\t\treturn nil, fmt.Errorf(\"bedrock: invalid API key\")\n\t\t}\n\t\tif mantle {\n\t\t\tout.Set(\"x-api-key\", key)\n\t\t} else {\n\t\t\tout.Set(\"Authorization\", \"Bearer \"+key)\n\t\t}\n\t\treturn out, nil\n\t}\n\n\tcreds, err := parseAWSCredentials(credential.Key)\n\tif err != nil {\n\t\tif credential.Scheme == \"sigv4\" {\n\t\t\treturn nil, ErrSigV4Configuration\n\t\t}\n\t\treturn nil, err\n\t}\n\n\t// Sign against the SAME URL the proxy will forward to. The caller passes the","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/providers/bedrock/signing.go#L48-L84","documentation":"SanitizeAndMapHeaders validates the credential when authKind is \"bedrock_api_key\": the key must be non-empty and must not contain CR or LF characters, since it is sent verbatim as an x-api-key or Authorization: Bearer header. An empty/whitespace-only key, or one containing embedded newlines, is rejected to prevent malformed or header-injection credentials reaching Bedrock.","triggerScenarios":"Credential.AuthKind is explicitly \"bedrock_api_key\" and either credential.Key is empty or trims to empty, or credential.Key contains a \\r or \\n character.","commonSituations":"Storing the API key in a config file or env var with a trailing newline that was not trimmed; pasting a multi-line value or a key plus notes into a secret store; leaving the Key field empty while setting AuthKind to bedrock_api_key; YAML/env interpolation pulling in blank values.","solutions":["Trim the credential key and remove any embedded newlines before storing it (e.g. strings.TrimSpace and strip \\r\\n)","Verify the Bedrock API key was copied completely and is a single-line value","If you actually intend IAM SigV4 auth, set AuthKind to \"aws_access_keys\" with an accessKeyId:secretAccessKey[:sessionToken] value instead of bedrock_api_key"],"exampleFix":"// before\ncredential := providers.Credential{AuthKind: \"bedrock_api_key\", Key: keyFromEnv + \"\\n\"}\n// after\ncredential := providers.Credential{AuthKind: \"bedrock_api_key\", Key: strings.TrimSpace(strings.ReplaceAll(keyFromEnv, \"\\n\", \"\"))}","handlingStrategy":"validation","validationCode":"func validBedrockAPIKey(key string) bool {\n\tkey = strings.TrimSpace(key)\n\treturn key != \"\" && !strings.ContainsAny(key, \"\\r\\n\")\n}\nif !validBedrockAPIKey(cred.Key) { return errors.New(\"bedrock API key must be a single non-empty line\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim credentials when loading from env/config files","Reject multi-line values at config load time with a clear message","Store API keys in single-line secret-store fields only"],"tags":["bedrock","authentication","config"],"backgroundTag":"missing-api-key","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}