laravel-xss-protection icon indicating copy to clipboard operation
laravel-xss-protection copied to clipboard

Missing option to allow inline "style" property

Open kwarcu opened this issue 4 months ago • 0 comments
trafficstars

Hi! I'm really missing an option / configuration to enable some of the properties or tags. In current case I really need to enable inline style properties. Underlying voku/anti-xss has proper configuration options. For now I'm forced to overwrite middleware like this to get what I need:

<?php

namespace App\Http\Middleware;

use GrahamCampbell\SecurityCore\Security;
use ProtoneMedia\LaravelXssProtection\Cleaners\BladeEchoes;
use voku\helper\AntiXSS;

class XssCleanInput extends \ProtoneMedia\LaravelXssProtection\Middleware\XssCleanInput
{
    public function __construct(BladeEchoes $bladeEchoCleaner)
    {
        $antiXss = new AntiXSS();

        $replacement = config('xss-protection.anti_xss.replacement');
        if ($replacement !== null) {
            $antiXss->setReplacement($replacement);
        }

        $evil = config('xss-protection.anti_xss.evil');
        if (isset($evil['attributes']) || isset($evil['tags'])) {
            $antiXss->addEvilAttributes($evil['attributes'] ?? []);
            $antiXss->addEvilHtmlTags($evil['tags'] ?? []);
        } else {
            $antiXss->addEvilAttributes($evil);
        }

        $antiXss->removeEvilAttributes(['style']); // All this to allow inline styles in input

        $security = new Security($antiXss);
        parent::__construct($security, $bladeEchoCleaner);
    }
}

I'm happy to prepare PR with appropriate changes in the library itself to handle config options. Or if you can prepare it I would really appreciate.

kwarcu avatar Jul 24 '25 20:07 kwarcu