From 06467057be17d900450f8eac98cb7845a65bdf29 Mon Sep 17 00:00:00 2001
From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Date: Mon, 27 Apr 2026 13:31:43 +0530
Subject: [PATCH] fix: oversized email signature images in Letter render
(#14144)
# Pull Request Template
## Description
This PR fixes an issue where signature images (with
`?cw_image_height=...`) render at their original large size in the email
bubble.
### Cause
Renderer output:
```html
```
Email UI and clients (Gmail, Outlook) apply CSS like:
`img { max-width: 100%; height: auto; }`
This overrides `height="24px"`.
Other channels work because they use inline styles (`style="height:
24px;"`).
### Solution
Use inline style instead:
```html
```
### Why backend fix
* Fixes root cause and aligns Ruby + JS renderers
* Works in both Chatwoot UI and recipient inboxes
* Covers all email-rendered content
* Minimal change
Fixes
https://linear.app/chatwoot/issue/CW-6948/email-signature-image-renders-oversized-in-chatwoot-ui
## Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
## How Has This Been Tested?
#### Screenshots
**Before**
**After**
## Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
---
lib/base_markdown_renderer.rb | 8 ++++++--
spec/lib/base_markdown_renderer_spec.rb | 2 +-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/base_markdown_renderer.rb b/lib/base_markdown_renderer.rb
index df49918b3..f530e71ee 100644
--- a/lib/base_markdown_renderer.rb
+++ b/lib/base_markdown_renderer.rb
@@ -29,11 +29,15 @@ class BaseMarkdownRenderer < CommonMarker::HtmlRenderer
def render_img_tag(src, title, height = nil)
title_attribute = title.present? ? " title=\"#{title}\"" : ''
- height_attribute = height ? " height=\"#{height}\" width=\"auto\"" : ''
+ # Use inline style instead of the HTML height attribute: email clients and
+ # the in-app Letter view both run images through CSS (e.g. prose /
+ # lettersanitizer's `img { height: auto }`) which overrides presentational
+ # attributes. Inline style has higher specificity and survives.
+ style_attribute = height ? " style=\"height: #{height};\"" : ''
plain do
# plain ensures that the content is not wrapped in a paragraph tag
- out("
")
+ out("
")
end
end
end
diff --git a/spec/lib/base_markdown_renderer_spec.rb b/spec/lib/base_markdown_renderer_spec.rb
index 262e78daf..f8bdae4be 100644
--- a/spec/lib/base_markdown_renderer_spec.rb
+++ b/spec/lib/base_markdown_renderer_spec.rb
@@ -12,7 +12,7 @@ describe BaseMarkdownRenderer do
context 'when image has a height' do
it 'renders the img tag with the correct attributes' do
markdown = ''
- expect(render_markdown(markdown)).to include('
')
+ expect(render_markdown(markdown)).to include('
')
end
end