FIXED: kiwix-serve XSS attack vulnerability (#763)

This commit is contained in:
Kelson42 2015-01-08 12:51:42 +01:00
parent 191d37a105
commit 8287a64172
3 changed files with 10 additions and 1 deletions

View File

@ -180,7 +180,7 @@ namespace kiwix {
oData["pages"] = pagesCDT; oData["pages"] = pagesCDT;
oData["count"] = kiwix::beautifyInteger(this->estimatedResultCount); oData["count"] = kiwix::beautifyInteger(this->estimatedResultCount);
oData["searchPattern"] = this->searchPattern; oData["searchPattern"] = kiwix::encodeDiples(this->searchPattern);
oData["searchPatternEncoded"] = urlEncode(this->searchPattern); oData["searchPatternEncoded"] = urlEncode(this->searchPattern);
oData["resultStart"] = this->resultStart + 1; oData["resultStart"] = this->resultStart + 1;
oData["resultEnd"] = (this->resultEnd > this->estimatedResultCount ? this->estimatedResultCount : this->resultEnd); oData["resultEnd"] = (this->resultEnd > this->estimatedResultCount ? this->estimatedResultCount : this->resultEnd);

View File

@ -104,6 +104,14 @@ void kiwix::stringReplacement(std::string& str, const std::string& oldStr, const
} }
} }
/* Encode string to avoid XSS attacks */
std::string kiwix::encodeDiples(const std::string& str) {
std::string result = str;
kiwix::stringReplacement(result, "<", "&lt;");
kiwix::stringReplacement(result, ">", "&gt;");
return result;
}
// Urlencode // Urlencode
//based on javascript encodeURIComponent() //based on javascript encodeURIComponent()

View File

@ -48,6 +48,7 @@ namespace kiwix {
void printStringInHexadecimal(const char *s); void printStringInHexadecimal(const char *s);
void printStringInHexadecimal(UnicodeString s); void printStringInHexadecimal(UnicodeString s);
void stringReplacement(std::string& str, const std::string& oldStr, const std::string& newStr); void stringReplacement(std::string& str, const std::string& oldStr, const std::string& newStr);
std::string encodeDiples(const std::string& str);
#endif #endif