ezyang / ezyang/htmlpurifier

Minor whitespace differences in PHP7.3

Open
#237 4 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

We're currently updating our app to PHP 7.3, and we're finding some unit test failures that don't occur on PHP 7.1. It's reproducible just using this script

<?php

require_once 'vendor/autoload.php';

$sHTML = '<p>Paragraph 1</p><textarea></textarea> <p>Paragraph 2</p>';

$oPurifier = new HTMLPurifier(); // version 4.11.0

echo $oPurifier->purify($sHTML);

On PHP 7.1, we get <p>Paragraph 1</p><p>Paragraph 2</p>. On PHP 7.3 we get <p>Paragraph 1</p> <p>Paragraph 2</p>.

There seems to be various cases where whitespace is added where it wasn't before:

'">><marquee><img src=x onerror=confirm(1)></marquee>"></plaintext\></|\><plaintext/onmouseover=prompt(1)>
<script>prompt(1)</script>@gmail.com<isindex formaction=javascript:alert(/XSS/) type=submit>'-->"></script>
<script>alert(document.cookie)</script>">
<img/id="confirm&lpar;1)"/alt="/"src="/"onerror=eval(id)>'">
<img src="http://www.shellypalmer.com/wp-content/images/2015/07/hacked-compressor.jpg">

On PHP7.3 that adds a newline before the @gmail which isn't there in PHP 7.1

<HEAD><META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-7"> </HEAD>+ADw-SCRIPT+AD4-alert(\'XSS\');+ADw-/SCRIPT+AD4- adds a space before the beginning of the output (though the HEAD etc is stripped)

I don't think this is an issue because whitespace doesn't normally mean anything, but I don't know whether it would signify some other weirdness that people need to be aware of elsewhere?

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 with the supplied PHP reproduction script and compare its HTMLPurifier output under PHP 7.1 and 7.3. Trace the sanitizer's whitespace handling for the textarea, malformed markup, and HEAD examples, then determine whether the differences are expected or regressions. Done means the compatibility behavior and any required correction are established with the affected unit tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.