---
layout: post
title: "XSS in Kayako helpdesk software"
thumbnail: broken-phone-box-240.jpg
date: 2016-08-29
---
In the Kayako helpdesk software, customers can submit tickets which staff can then view and answer. In this feature there is a XSS vulnerability in the ticket title. This post describes how I found that vulnerability.
## Checking escape functionality
First, I created a new ticket with some HTML tags in each field:

I use a easily recognizable word in each field ("foobar") so that I can later on search in the page source and easily find how strings are escaped. I use `` instead of `` in the title. However, when we try that the whole tag gets removed.
## Looking at the code
Time to look at the code to see what escaping is exactly performed:
$_documentTitle = addslashes(StripScriptTags($this->_documentTitle));
echo 'SetHeaderTitle("' . $_documentTitle . '");';
The call to [`addslashes`](https://www.php.net/manual/en/function.addslashes.php) is the reason why our quotes are escaped, and the function `StripScriptTags` removes our `` tag:
function StripScriptTags($_htmlCode)
{
// Strips "empty" script tags (e.g. )
$_htmlCode = preg_replace('@@si', '', $_htmlCode);
// Strips "full" script tags (e.g. )
$_htmlCode = preg_replace('@@si', '', $_htmlCode);
// Strips just closing tags
$_htmlCode = preg_replace('@@si', '', $_htmlCode);
return $_htmlCode;
}
The last `preg_replace` call removes our script tag. Let's look at what this regex means exactly:
* The `@` is a delimeter. The real regex is in between the two `@`.
* The literal ``.
So `` is removed.
## Performing the attack
As we have seen `` tags are removed, as long as they contain nothing else but whitespace. This means that we can bypass this sanitization code by putting something that is not whitespace in the tag:
Note that we have added an `a` to the closing script tag, which prevents `StripScriptTags` from deleting it. We also use backticks instead of quotes in our JavaScript, because quotes would be escaped by `addslashes`. Success at last:

## Conclusion
This vulnerability makes it possible for an anonymous user to inject scripts that are executed by staff. It was easily found using a combination of hands-on testing and code review: first test to find an interesting location where input is not correctly escaped, then read the code to learn what escaping is done exactly.
## Timeline
* 28 Feb 2016, Sjoerd → Kayako: there is XSS in SetHeaderTitle.
* 29 Feb 2016, Kayako → Sjoerd: bug has been filed: SWIFT-4917.
* 6 Mar 2016, Sjoerd → Kayako: the bug is public but should be private.
* 7 Mar 2016, Kayako → Sjoerd: bug marked as private.
* 10 Jun 2016, Sjoerd → Kayako: could you look at this bug?
* 23 Jun 2016, Sjoerd → Kayako: any update? would like to publish in July.
* 23 Jun 2016, Kayako → Sjoerd: please wait until issue is fixed in next release.
## Version
For this article I used Kayako 4.71.0. The newest version at the time of writing is 4.74.2.