Reflected Cross-Site Scripting in Serendipity (serendipity.SetCookie)
The administration interface's entry sorting feature reflects user-supplied input into a JavaScript context without proper escaping, allowing an attacker to inject script. An authenticated victim who clicks a crafted link could have arbitrary JavaScript executed in their browser on the affected domain.
bb9866f3f743d6bf69b6836 Follow
Originally disclosed on HackerOne
- Triaged in 42 hours
- Fixed in 48 days
- Disclosed after 4 months
## Summary
The Smarty template responsible of creating JavaScript snippets assigning cookies to users is during sorting of entries in the administration interface is affected by a reflected cross-site scripting.
Description
In templates/2k11/admin/entries.inc.tpl, the following code is dynamically creating a JavaScript snippet consisting of calls to serendipity.SetCookie():
<script>
$(document).ready(function() {
{foreach $filter_import AS $f_import}
serendipity.SetCookie("entrylist_filter_{$f_import}", "{$get_filter_{$f_import}}" )
{/foreach}
{foreach $sort_import AS $s_import}
serendipity.SetCookie("entrylist_sort_{$s_import}", "{$get_sort_{$s_import}}" )
{/foreach}
});
</script>
However, Smarty is not aware of the context is is not told to escape it as javascript (https://www.smarty.net/docsv2/en/language.modifier.escape) and no prior encoding is performed on data injected in the template (see include/admin/entries.inc.php:216):
<?php
// [...]
case 'editSelect':
$data['switched_output'] = false;
$filter_import = array('author', 'category', 'isdraft');
$sort_import = array('perPage', 'ordermode', 'order');
foreach($filter_import AS $f_import) {
serendipity_restoreVar($serendipity['COOKIE']['entrylist_filter_' . $f_import], $serendipity['GET']['filter'][$f_import]);
$data["get_filter_$f_import"] = $serendipity['GET']['filter'][$f_import];
}
foreach($sort_import AS $s_import) {
serendipity_restoreVar($serendipity['COOKIE']['entrylist_sort_' . $s_import], $serendipity['GET']['sort'][$s_import]);
$data["get_sort_$s_import"] = $serendipity['GET']['sort'][$s_import];
}
For the record, the function serendipity_JSsetCookie is also vulnerable, but it's not in use in this version:
<?php
// [...]
function serendipity_JSsetCookie($name, $value) {
$name = serendipity_entities($name);
$value = urlencode($value);
echo '<script type="text/javascript">serendipity.SetCookie("' . $name . '", unescape("' . $value . '"))</script>' . "\n";
}
Steps To Reproduce
- Access https://blog.fuzzing-project.org/serendipity_admin.php?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=editSelect&serendipity[filter][author]=1xx");alert(document.domain);// while being authenticated;
- Notice the execution of
alert(document.domain)within the context ofblog.fuzzing-project.org.
Impact
By accessing a link specially crafted by an attacker and exploiting this vulnerability, an authenticated victim could be forced to perform actions on its behalf on the domain blog.fuzzing-project.org. If the victim is authenticated as administrator, it could be used to compromise the website or the underlying server (through the installation of serendipity_plugin_externalphp).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the template engine was not instructed to escape output for the JavaScript context, and the application did not encode the GET parameters before inserting them into the script.
Impact
An authenticated victim could be forced to perform actions on their behalf on the affected domain, and if the victim is an administrator, the attacker could potentially compromise the website or server.
What the attacker needed
Victim is authenticated; victim clicks a crafted link
How it was found
- While authenticated, visit the admin entries page with a crafted filter author parameter containing a script payload.
- Observe that the script executes in the context of the blog domain.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a website takes input from a URL and puts it directly into a page without cleaning it, an attacker can sneak in their own code. Here, the admin page for sorting blog entries inserted a value from the URL into a script block, so a malicious link could run JavaScript in the admin's browser. This is called reflected cross-site scripting because the bad input is echoed back immediately.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.