forked from chookspace/chookchat
Fix username html injection
This commit is contained in:
@@ -9,13 +9,18 @@
|
|||||||
|
|
||||||
#include "post.h"
|
#include "post.h"
|
||||||
|
|
||||||
|
void sanitize(std::string& str);
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
uint64_t id = 0;
|
uint64_t id = 0;
|
||||||
std::string name = "";
|
std::string name = "";
|
||||||
std::string passwordHash = "";
|
std::string passwordHash = "";
|
||||||
|
|
||||||
User(uint64_t id, const std::string& name, const std::string& passwordHash) :
|
User(uint64_t id, std::string namein, const std::string& passwordHash) :
|
||||||
id(id), name(name), passwordHash(passwordHash) {}
|
id(id), passwordHash(passwordHash) {
|
||||||
|
sanitize(namein);
|
||||||
|
name = namein;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
|
|||||||
@@ -13,25 +13,25 @@ void replaceAll(std::string& str, const std::string& from, const std::string& to
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sanitize(std::string& str) {
|
||||||
|
replaceAll(str, "&", "&");
|
||||||
|
replaceAll(str, "<", "<");
|
||||||
|
replaceAll(str, ">", ">");
|
||||||
|
replaceAll(str, "\"", """);
|
||||||
|
replaceAll(str, "'", "'");
|
||||||
|
}
|
||||||
|
|
||||||
Post::Post(std::string contentin, const std::string& user) : user(user), time(std::time(nullptr)) {
|
Post::Post(std::string contentin, const std::string& user) : user(user), time(std::time(nullptr)) {
|
||||||
replaceAll(contentin, "&", "&");
|
|
||||||
replaceAll(contentin, "<", "<");
|
|
||||||
replaceAll(contentin, ">", ">");
|
|
||||||
replaceAll(contentin, "\"", """);
|
|
||||||
replaceAll(contentin, "'", "'");
|
|
||||||
// parse the post content markdown
|
// parse the post content markdown
|
||||||
|
sanitize(contentin);
|
||||||
std::stringstream input(contentin);
|
std::stringstream input(contentin);
|
||||||
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
||||||
content = parser->Parse(input);
|
content = parser->Parse(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
Post::Post(std::string contentin, uint64_t user) : userId(user), time(std::time(nullptr)) {
|
Post::Post(std::string contentin, uint64_t user) : userId(user), time(std::time(nullptr)) {
|
||||||
replaceAll(contentin, "&", "&");
|
|
||||||
replaceAll(contentin, "<", "<");
|
|
||||||
replaceAll(contentin, ">", ">");
|
|
||||||
replaceAll(contentin, "\"", """);
|
|
||||||
replaceAll(contentin, "'", "'");
|
|
||||||
// parse the post content markdown
|
// parse the post content markdown
|
||||||
|
sanitize(contentin);
|
||||||
std::stringstream input(contentin);
|
std::stringstream input(contentin);
|
||||||
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
||||||
content = parser->Parse(input);
|
content = parser->Parse(input);
|
||||||
|
|||||||
Reference in New Issue
Block a user