We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

XSS Risk in textarea

I'm using Phalcon\Forms\Element\Textarea in my form, but it seems not be escaped.

https://github.com/phalcon/cphalcon/blob/5372ac7972218b10fd9f08027a7718ea10f191b5/phalcon/tag.zep#L963

So , if I input below in my textarea, XSS will be happned, I think.

test</textarea><script>alert(document.cookie)</script>


2.2k
edited Sep '16

update:

I treated this problem temporarily as below;

class myForm extends FormBase
{
    public function initialize($entity = null, $options = null)
    {
        $textarea = new Textarea('opinion');
        $this->add($textarea);
    }

    public function getOpinion()
    {
        return $this->escaper->escapeHtml($this->request->get('opinion'));
    }
}
edited Sep '16

I agree that such components need to offer basic filtering out of the box. But it does not, so for example I need to do apply sanitize on every route


 function getContent($num = null){
        $num = (int) $this->filter->sanitize($num, ['myCustomFilter', 'alphanum', 'int']);
        }