Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new option "allowedRemoteHosts" to restrict which remote hosts can be requested #3377

Merged
merged 3 commits into from
Feb 25, 2024

Conversation

bohwaz
Copy link
Contributor

@bohwaz bohwaz commented Jan 13, 2024

This is a simple patch to add some kind of security when allowing remote requests.

@bsweeney
Copy link
Member

A user could already perform this validation using the existing allowedProtocols option. For example:

$options = new Dompdf\Options($dompdf_options);
$options->addAllowedProtocol("https://", function (string $uri) use (&$options) {
    $ret = $options->validateRemoteUri($uri);
    if ($ret[0] === false) {
        return $ret;
    }

    $parsed_url = parse_url($uri);
    if (strtolower($parsed_url["host"]) != "example.com") {
        return [false, "The remote file domain is not allowed."];
    }

    return [true, null];
});
$dompdf = new Dompdf\Dompdf($options);

@bohwaz
Copy link
Contributor Author

bohwaz commented Jan 17, 2024

Yes but the callback approach is not documented, and this is much easier to use, and also promotes good practices :)

@bsweeney bsweeney added this to the 3.0.0 milestone Jan 17, 2024
src/Options.php Show resolved Hide resolved
src/Options.php Outdated Show resolved Hide resolved
bohwaz and others added 2 commits February 17, 2024 21:32
Co-authored-by: Brian Sweeney <brian@eclecticgeek.com>
@bsweeney bsweeney merged commit 8608964 into dompdf:master Feb 25, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants