{"record":{"id":"ebbffc8cc9bb9436","repo":"larksuite/cli","slug":"inline-image-content-type-q-does-not-match-an-all","errorCode":null,"errorMessage":"inline image content type %q does not match an allowed image format; supported: image/jpeg, image/png, image/gif, image/webp","messagePattern":"inline image content type %q does not match an allowed image format; supported: image/jpeg, image/png, image/gif, image/webp","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/filecheck/filecheck.go","lineNumber":168,"sourceCode":"\n// CheckInlineImageFormat validates that the file is an allowed inline image\n// format by checking both extension and content-sniffed MIME type.\n// Both must match the whitelist to prevent extension spoofing and MIME forgery.\n// On success it returns the detected MIME type; callers MUST use this as the\n// final Content-Type instead of trusting any user-supplied or inherited value.\nfunc CheckInlineImageFormat(filename string, content []byte) (string, error) {\n\text := strings.ToLower(strings.TrimPrefix(filepath.Ext(filename), \".\"))\n\tif _, ok := allowedInlineExtensions[ext]; !ok {\n\t\treturn \"\", fmt.Errorf(\"inline image extension %q is not allowed; supported formats: jpg, jpeg, png, gif, webp\", ext) //nolint:forbidigo // intermediate mail file-format check; mail command layer wraps into typed ValidationError.\n\t}\n\tdetected := http.DetectContentType(content)\n\t// DetectContentType may return params (e.g. \"text/plain; charset=utf-8\"),\n\t// strip to the base media type.\n\tif i := strings.IndexByte(detected, ';'); i != -1 {\n\t\tdetected = strings.TrimSpace(detected[:i])\n\t}\n\tif _, ok := allowedInlineMIMETypes[detected]; !ok {\n\t\treturn \"\", fmt.Errorf(\"inline image content type %q does not match an allowed image format; supported: image/jpeg, image/png, image/gif, image/webp\", detected) //nolint:forbidigo // intermediate mail file-format check; mail command layer wraps into typed ValidationError.\n\t}\n\treturn detected, nil\n}\n","sourceCodeStart":150,"sourceCodeEnd":172,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/filecheck/filecheck.go#L150-L172","documentation":"CheckInlineImageFormat validates that an inline image attached to a mail message has a MIME type on the allowlist (jpeg, png, gif, webp). It detects the actual content type of the file bytes (sniffing, not trusting the extension), strips any parameters, and rejects anything outside the allowlist. This guards the mail compose path against inline image formats the mail backend cannot render.","triggerScenarios":"Attaching or embedding an inline image in a mail shortcut whose sniffed content type is not one of image/jpeg, image/png, image/gif, image/webp — e.g. an SVG, BMP, TIFF, AVIF, HEIC, or ICO file passed as an inline attachment or template-embedded image.","commonSituations":"Users embedding screenshots saved as BMP/TIFF, designers attaching SVG logos inline, iPhone HEIC photos, or files renamed to .png/.jpg without actually being that format (detection is content-based, so renaming a WebP to .jpeg is fine but a renamed PDF is not).","solutions":["Convert the image to JPEG, PNG, GIF, or WebP before attaching it inline.","If the image is decorative, send it as a regular file attachment instead of an inline/embedded image, if the flow allows non-image types there.","Verify the file is actually the format it claims (e.g. `file image.png`); corrupted or mislabeled files can be detected as an unexpected type."],"exampleFix":"// before\nattachInline(\"logo.svg\")\n// error: inline image content type \"image/svg+xml\" does not match an allowed image format\n\n// after\n// convert first: convert logo.svg -resize 200x logo.png\nattachInline(\"logo.png\")","handlingStrategy":"validation","validationCode":"var allowed = map[string]bool{\"image/jpeg\": true, \"image/png\": true, \"image/gif\": true, \"image/webp\": true}\nct, err := DetectContentType(path) // or http.DetectContentType(bytes)\nif err != nil || !allowed[strings.TrimSpace(strings.SplitN(ct, \";\", 2)[0])] {\n    return fmt.Errorf(\"skipping inline image %s: unsupported type %s\", path, ct)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict inline images to jpeg/png/gif/webp at input-collection time.","Convert SVG/HEIC/BMP/TIFF to PNG or JPEG before attaching inline.","Trust the sniffed content type, not the file extension, when pre-validating."],"tags":["mail","validation","image-format"],"backgroundTag":"unsupported-content-type","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}