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

FILTER_SANITIZE_STRING is deprecated #152

Open
SteelWagstaff opened this issue Jan 11, 2023 · 3 comments
Open

FILTER_SANITIZE_STRING is deprecated #152

SteelWagstaff opened this issue Jan 11, 2023 · 3 comments

Comments

@SteelWagstaff
Copy link

SteelWagstaff commented Jan 11, 2023

We run an automated CI/CD pipeline that runs a series of tests. When running the pipeline on a virtual machine running PHP8.1 we get this deprecation warning related to this plugin:

Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /app/web/app/plugins/h5p/admin/class-h5p-plugin-admin.php on line 547

Looks like

$page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
uses FILTER_SANITIZE_STRING which has been deprecated as of PHP 8.1.0. The PHP manual recommends replacement with htmlspecialchars().

See: https://www.php.net/manual/en/filter.filters.sanitize.php and https://www.php.net/manual/en/function.htmlspecialchars.php

@richard015ar
Copy link

I noticed eleven occurrences of FILTER_SANITIZE_STRING, included in https://github.com/h5p/h5p-editor-php-library/blob/65d11bc1f64965285455905e6ef227c927341e64/h5peditor-file.class.php#L14.

According to what I understand of the code, the idea is to strip the HTML tags from specific inputs. For example, the following method could replace the FILTER_SANITIZE_STRING flag. I would open a PR but need help finding a helper o common class that can be used across multiple classes to avoid the repetition of this method everywhere.

function filter_input_value(string $string): string {
    $str = preg_replace('/\x00|<[^>]*>?/', '', $string);
     return str_replace(["'", '"'], ["'", '"'], $str);
}

@SteelWagstaff
Copy link
Author

@icc are you willing/able to help us identify a helper method or common class? We'd be willing to open a PR for this, if so.

@icc
Copy link
Member

icc commented Jan 13, 2023

I quickly looked over the instances and it seems to me that it should be safe to just replace it with FILTER_UNSAFE_RAW as the input isn't printed anywhere. This should be simpler as well.

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

No branches or pull requests

3 participants