From 872b5e7b3d9bc3823264fd2f627586e90e179902 Mon Sep 17 00:00:00 2001 From: Vladislav Ostapov Date: Thu, 9 Jan 2025 17:43:02 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D0=B2=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=B2=20=D0=B1=D1=80=D0=B0=D1=83=D0=B7=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=20opera=20gx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/utils.cpp | 15 ++++++++++++++- src/main.cpp | 3 +++ static/login.html | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) 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) => {