Skip to content

Possible E_DEPRECATED in HostBlacklist under PHP 8.1 #322

@Firehed

Description

@Firehed

When purifying HTML containing an anchor tag containing only the fragment component, an E_DEPRECATED error is emitted from the host blacklist if it's configured. Depending on the application config, this may get upgraded to an ErrorException and cause a crash, but that's not relevant to the underlying issue.

HTMLPurifier version: v4.14.0 (found on an earlier version but updated to latest release to be sure)

Uncaught exception: ErrorException: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/html/vendor/ezyang/htmlpurifier/library/HTMLPurifier/URIFilter/HostBlacklist.php:38

Simple reproduce case:

<?php
require 'vendor/autoload.php';

$pc = HTMLPurifier_Config::create([
    'HTML.Allowed' => 'a[href]',
    'URI.HostBlacklist' => [
        'example.com',
    ],
]);
$p = new HTMLPurifier($pc);

var_dump($p->purify(<<<HTML
<a href="#fn-1">Footnote </a>
HTML));

Possible fix: cast $uri->host to string on the mentioned line.

Update - related to #310 I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions