ezyang / ezyang/htmlpurifier

Selector for element with attribute is lost

Open
#299 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
3.4k
Forks
361
Avg merge
3d 41m
Merged PRs (30d)
2

Description

Hi 👋

We are using htmlpurifier for nextcloud/mail to sanitize the body of html messages and have a bug report that a mail is not rendered correctly (https://github.com/nextcloud/mail/issues/5279).

I debugged the mail body and found that

* img[tabindex="0"] + div { text-align:center }

is rewritten to

* + div { text-align:center }

https://github.com/ezyang/htmlpurifier/blob/c97bb9322386385a2cbfdd7aab705e3a47050581/library/HTMLPurifier/Filter/ExtractStyleBlocks.php#L243

image

A test case for ExtractStyleBlocksTest:

	public function test_cleanCSS_elementWithAttribute()
	{
		$this->assertCleanCSS(
			"* img[tabindex=\"0\"] + div {\ntext-align:center\n}",
			"* img + div {\ntext-align:center\n}"
		);
	}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in library/HTMLPurifier/Filter/ExtractStyleBlocks.php around the referenced selector handling, then run or inspect ExtractStyleBlocksTest. Add the provided test case and ensure the cleaned CSS retains the attribute selector in the output. Done means the regression test passes without breaking the existing cleaning behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.