diff --git a/src/auth/utils.cpp b/src/auth/utils.cpp index 8450d3a..5748c43 100644 --- a/src/auth/utils.cpp +++ b/src/auth/utils.cpp @@ -113,7 +113,20 @@ std::map http::utils::parseCookies(const std::string& if (equalPos == std::string::npos) { continue; // Неверный формат Cookie } - std::string name = cookie.substr(0, equalPos); + size_t startIndex = 0; + while (startIndex < cookie.size()) { + if (cookie[startIndex] == '=') { + // некорректная кука, состоит только из пробелов, так что на этом обработку и закончим + return cookies; + } + + if (cookie[startIndex] == ' ') { + startIndex++; + } else { + break; + } + } + std::string name = cookie.substr(startIndex, equalPos - startIndex); std::string value = cookie.substr(equalPos + 1); // Удаляем пробелы с начала и конца значения Cookie diff --git a/src/main.cpp b/src/main.cpp index d7617a9..f789d28 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -114,6 +114,7 @@ public: #error "Modem type not defined!" #endif static constexpr const char* LOGIN_HTML = "/login.html"; + static constexpr const char* DEV_HTML = "/dev.html"; // картинки, их даже можно кешировать static constexpr const char* FAVICON_ICO = "/favicon.ico"; @@ -135,6 +136,7 @@ public: sf->registerFile(staticFilesPath + STYLE_CSS, STYLE_CSS, mime_types::text_css, true); sf->registerFile(staticFilesPath + FIELDS_CSS, FIELDS_CSS, mime_types::text_css, true); sf->registerFile(staticFilesPath + INDEX_HTML, INDEX_HTML, mime_types::text_html, false); + sf->registerFile(staticFilesPath + DEV_HTML, DEV_HTML, mime_types::text_html, false); sf->registerFile(staticFilesPath + LOGIN_HTML, LOGIN_HTML, mime_types::text_html, true); sf->registerFile(staticFilesPath + INTERNET_JPG, INTERNET_JPG, mime_types::image_jpeg, true); } @@ -195,6 +197,7 @@ public: s.resources.emplace_back(std::make_unique(FIELDS_CSS, [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(FIELDS_CSS, rep); })); s.resources.emplace_back(std::make_unique(VUE_JS, [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(VUE_JS, rep); })); s.resources.emplace_back(std::make_unique(INTERNET_JPG, [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(INTERNET_JPG, rep); })); + s.resources.emplace_back(std::make_unique("/dev", [this](const auto& req, auto& rep) { boost::ignore_unused(req); sf->serve(DEV_HTML, rep); })); s.resources.emplace_back(std::make_unique("/api/get/statistics", this->auth, http::auth::User::WATCH_STATISTICS, [this](const auto& req, auto& rep) { if (req.method != "GET") { diff --git a/static/login.html b/static/login.html index 4fd1973..2f904cb 100644 --- a/static/login.html +++ b/static/login.html @@ -111,7 +111,8 @@ headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(requestData) + body: JSON.stringify(requestData), + credentials: 'same-origin' }).then(response => { // Обработка ответа сервера response.json().then((value) => {