Summary
A Cross-site scripting (XSS) vulnerability in the Security component of Kohana before 3.3.6 allows remote attackers to inject arbitrary web script or HTML by bypassing the strip_image_tags protection mechanism in system/classes/Kohana/Security.php.
Product
Kohana before 3.3.6
Impact
If exploited, a threat actor will be able to execute arbitrary Javascript in the browser of a victim who accesses the vulnerable application.
Steps to reproduce
The vulnerable function uses faulty regex to check to filter potentially malicious HTML and JavaScript inputs from <img> tags, as can be seen in the below snippet:
public static function strip_image_tags($str)
{
return preg_replace('#<imgs.*?(?:srcs*=s*["']?([^"'<>s]*)["']?[^>]*)?>#is', '$1', $str);
}
In order to exploit this issue, a threat actor may pass the following payload to the vulnerable function:
<img/src=x onerror=prompt(document.domain)>
As the regex is expecting a space character after the img tag, this payload will be accepted.
Expected result
The JavaScript will execute in the victim’s browser.
Remediation
Update Kohana dependency to 3.3.6 and above
Credit
This issue was discovered and reported by Checkmarx Security Researcher @dsopas (David Sopas).