Repository navigation
fix(html): prevent extraction of CSS from hidden conditional comments - #14248
Draft
PsyCrow-code wants to merge 1 commit into
Draft
PsyCrow-code wants to merge 1 commit into
PsyCrow-code wants to merge 1 commit into
Conversation
Remove hidden conditional comments before HTMLPurifier extracts style blocks to prevent Outlook-specific CSS from affecting visible message content. Preserve downlevel-revealed content and add regression tests. Assisted-by: ChatGPT:gpt-6 Signed-off-by: PsyCrow <ing.josegonzalez@gmail.com>
PsyCrow-code
marked this pull request as ready for review
November 20, 2026 01:43
PsyCrow-code
requested review from
ChristophWurst,
GretaD and
kesselb
as code owners
November 20, 2026 01:43
ChristophWurst
requested changes
Nov 20, 2026
Contributor
Author
|
@ChristophWurst Thanks for the review. I've rewritten the description using the repository's Context / Approach / Screenshots / Testing / AI assistance template. I also added the concrete bank-notification rendering context and an importable, anonymized The original message contains private account information, so the fixture is synthetic. I have explicitly marked the real before/after Nextcloud Mail UI screenshots as outstanding; this PR remains in draft rather than suggesting that the requested visual evidence is complete. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This fixes a rendering problem observed in a real bank-notification email in a private Nextcloud Mail installation (Nextcloud 35, Mail 5.12.x). The text in table cells appeared compressed/overlapping in the browser, rather than having normal line spacing.
The message has Microsoft Outlook-only, downlevel-hidden conditional markup. HTMLPurifier's
ExtractStyleBlocksfilter runs before comments are removed, so a<style>element meant only for Outlook can escape the comment and affect the regular HTML seen in Mail.The following minimal, anonymized reproduction uses illustrative values rather than any private email content:
Steps to reproduce on unpatched Mail: open an HTML message containing this hidden MSO style and a normal table, or pass the snippet through
Html::sanitizeHtmlMailBody()and render the returned HTML. The MSO-only rule is extracted, and itsline-height: 1pxis applied to regular table cells. With this patch, the hidden MSO rule and content are discarded before extraction; normal styles and message content remain.Related upstream behavior: ezyang/htmlpurifier#146.
Download the synthetic example email or view its source. This is a directly importable
.emlfixture with no private sender, account or transaction data.Approach
Remove only downlevel-hidden conditional comments before constructing the sanitized HTML via HTMLPurifier. The regex executes directly before the existing downlevel-revealed marker handling.
<!--[if !mso]><!-->content and its styles, along with<![if !mso]>markers.Why here? Filtering after
ExtractStyleBlocksis too late: the unwanted CSS has already been collected. Changing HTMLPurifier itself would affect other consumers, while this is a narrowly scoped Mail workaround.Screenshots
These are genuine screenshots of the same email rendered in Nextcloud Mail before and after applying this change. Private information is redacted.
The source message contains confidential information; the independent, synthetic
.emlfixture linked above is provided for reproducible testing.Testing
git diff --checkpassed.This PR remains draft pending maintainer review and any further verification requested.
AI assistance
Assisted by ChatGPT (GPT-6) for analysis, tests and PR documentation; code and local observations manually reviewed.