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

[TODO: merge conflicts] Recursive XSS Filter #794

Closed
wants to merge 2 commits into from
Closed

[TODO: merge conflicts] Recursive XSS Filter #794

wants to merge 2 commits into from

Conversation

videsignz
Copy link

I edited the XSS Filter to not only allow individual values but to also allow arrays and objects.

    public static function XSSFilter(&$value)
    {
        if (is_string($value)) {

            $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');

        }elseif(is_array($value) || is_object($value)) {

            foreach ($value as $key => &$array_value) {

                self::XSSFilter($array_value);

            }           
        }
        return $value;
    }

This is extremely useful if you want to filter array results directly after a database call within a model.

Single Row Example:

    // If successful, clean & return data
    if ($query->rowCount() == 1) {
        $query = $query->fetch();
        return Filter::XSSFilter($query);
    }

Multiple Row Example:

    // If successful, clean & return data as array
    if ($query->rowCount() > 0) {
        $query = $query->fetchAll();
        return Filter::XSSFilter($query);
    }

Edited the XXS Filter to not only accept individual values but also
arrays and objects. This is useful to use directly after a database
call.
@panique panique changed the title Recursive XSS Filter [TODO: merge conflicts] Recursive XSS Filter Aug 1, 2016
@panique panique closed this Apr 26, 2017
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.

2 participants