Hot fix: now bad cookies do not ruin everything
This commit is contained in:
		
							parent
							
								
									799e156f88
								
							
						
					
					
						commit
						90f8289bcd
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -14,3 +14,5 @@ local.sh | |||||||
| 
 | 
 | ||||||
| iu9-ca-web-chat.db | iu9-ca-web-chat.db | ||||||
| log/ | log/ | ||||||
|  | core | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -149,8 +149,10 @@ struct CAWebChat { | |||||||
|                 "login_cookie.cpp", |                 "login_cookie.cpp", | ||||||
|                 "backend_logic/server_data_interact.cpp", |                 "backend_logic/server_data_interact.cpp", | ||||||
|                 "backend_logic/when_login.cpp", |                 "backend_logic/when_login.cpp", | ||||||
|  |                 "backend_logic/when_list_rooms.cpp", | ||||||
|                 "backend_logic/when_internalapi_pollevents.cpp", |                 "backend_logic/when_internalapi_pollevents.cpp", | ||||||
|                 "backend_logic/when_internalapi_getchatlist.cpp", |                 "backend_logic/when_internalapi_getchatlist.cpp", | ||||||
|  |                 "backend_logic/when_internalapi_getchatinfo.cpp", | ||||||
|             }; |             }; | ||||||
|             for (std::string& u: T.units) |             for (std::string& u: T.units) | ||||||
|                 u = "web_chat/iu9_ca_web_chat_lib/" + u; |                 u = "web_chat/iu9_ca_web_chat_lib/" + u; | ||||||
|  | |||||||
| @ -55,26 +55,31 @@ namespace een9 { | |||||||
|         }; |         }; | ||||||
|         skip_ows(); |         skip_ows(); | ||||||
|         while (pos < hv.size()) { |         while (pos < hv.size()) { | ||||||
|  |             if (!result.empty()) { | ||||||
|  |                 if (!isThis(';')) | ||||||
|  |                     THROW("Incorrect Cookie header line, missing ;"); | ||||||
|  |                 pos++; | ||||||
|  |                 skip_ows(); | ||||||
|  |             } | ||||||
|             std::string name_of_pechenye = read_to_space_or_eq(); |             std::string name_of_pechenye = read_to_space_or_eq(); | ||||||
|             ASSERT(isCookieName(name_of_pechenye), "Incorrect Cookie name"); |             // ASSERT(isCookieName(name_of_pechenye), "Incorrect Cookie name");
 | ||||||
|             skip_ows(); |             skip_ows(); | ||||||
|             ASSERT(isThis('='), "Incorrect Cookie header line, missing ="); |             if (!isThis('=')) | ||||||
|  |                 THROW("Incorrect Cookie header line, missing ="); | ||||||
|             pos++; |             pos++; | ||||||
|             skip_ows(); |             skip_ows(); | ||||||
|             std::string value_of_pechenye; |             std::string value_of_pechenye; | ||||||
|             if (isThis('"')) { |             if (isThis('"')) { | ||||||
|                 pos++; |                 pos++; | ||||||
|                 value_of_pechenye = read_to_space_or_dq_or_semc(); |                 value_of_pechenye = read_to_space_or_dq_or_semc(); | ||||||
|                 ASSERT(isThis('"'), "Incorrect Cookie header line, missing \""); |                 if (!isThis('"')) | ||||||
|  |                     THROW("Incorrect Cookie header line, missing \""); | ||||||
|                 pos++; |                 pos++; | ||||||
|             } else { |             } else { | ||||||
|                 value_of_pechenye = read_to_space_or_dq_or_semc(); |                 value_of_pechenye = read_to_space_or_dq_or_semc(); | ||||||
|             } |             } | ||||||
|             ASSERT(isCookieValue(value_of_pechenye), "Incorrect Cookie value"); |             // ASSERT(isCookieValue(value_of_pechenye), "Incorrect Cookie value");
 | ||||||
|             if (result.empty()) |             result.emplace_back(name_of_pechenye, value_of_pechenye); | ||||||
|                 result.emplace_back(); |  | ||||||
|             result.back().first = std::move(name_of_pechenye); |  | ||||||
|             result.back().second = std::move(value_of_pechenye); |  | ||||||
|             skip_ows(); |             skip_ows(); | ||||||
|         } |         } | ||||||
|         return result; |         return result; | ||||||
| @ -84,10 +89,14 @@ namespace een9 { | |||||||
|     findAllClientCookies(const std::vector<std::pair<std::string, std::string>>& header) { |     findAllClientCookies(const std::vector<std::pair<std::string, std::string>>& header) { | ||||||
|         std::vector<std::pair<std::string, std::string>> result; |         std::vector<std::pair<std::string, std::string>> result; | ||||||
|         for (const std::pair<std::string, std::string>& line: header) { |         for (const std::pair<std::string, std::string>& line: header) { | ||||||
|             if (line.first == "Cookie") { |             try { | ||||||
|                 std::vector<std::pair<std::string, std::string>> new_cookies = parseCookieHeader(line.second); |                 if (line.first == "Cookie") { | ||||||
|                 result.reserve(result.size() + new_cookies.size()); |                     std::vector<std::pair<std::string, std::string>> new_cookies = parseCookieHeader(line.second); | ||||||
|                 result.insert(result.end(), new_cookies.begin(), new_cookies.end()); |                     result.reserve(result.size() + new_cookies.size()); | ||||||
|  |                     result.insert(result.end(), new_cookies.begin(), new_cookies.end()); | ||||||
|  |                 } | ||||||
|  |             } catch (const std::exception& e) { | ||||||
|  |                 printf("!!!findAllClientCookies failure\n"); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return result; |         return result; | ||||||
|  | |||||||
| @ -63,6 +63,8 @@ namespace iu9cawebchat { | |||||||
|     std::string when_page_login(WorkerGuestData& wgd, const json::JSON& config_presentation, |     std::string when_page_login(WorkerGuestData& wgd, const json::JSON& config_presentation, | ||||||
|         const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo); |         const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo); | ||||||
| 
 | 
 | ||||||
|  |     std::string when_page_list_rooms(WorkerGuestData& wgd, const json::JSON& config_presentation, | ||||||
|  |             const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo); | ||||||
| 
 | 
 | ||||||
|     json::JSON internalapi_pollEvents(SqliteConnection& conn, int64_t uid, const json::JSON& Sent); |     json::JSON internalapi_pollEvents(SqliteConnection& conn, int64_t uid, const json::JSON& Sent); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -0,0 +1,5 @@ | |||||||
|  | #include "server_data_interact.h" | ||||||
|  | 
 | ||||||
|  | namespace iu9cawebchat { | ||||||
|  |     // todo
 | ||||||
|  | } | ||||||
| @ -0,0 +1,18 @@ | |||||||
|  | #include "server_data_interact.h" | ||||||
|  | 
 | ||||||
|  | namespace iu9cawebchat { | ||||||
|  |     std::string when_page_list_rooms(WorkerGuestData& wgd, const json::JSON& config_presentation, | ||||||
|  |             const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo) { | ||||||
|  |         if (userinfo.isNull()) { | ||||||
|  |             printf("Somebody entered /list-room with %s without being logged in\n", req.method.c_str()); | ||||||
|  |             if (!login_cookies.empty()) { | ||||||
|  |                 printf("Login cookies: \n"); | ||||||
|  |                 for (auto& c: login_cookies) { | ||||||
|  |                     printf("%s  as %s\n", c.nickname.c_str(), c.password.c_str()); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             return een9::form_http_server_response_307("/login"); | ||||||
|  |         } | ||||||
|  |         return RTEE("list-rooms", config_presentation, wgd, userinfo); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -82,20 +82,18 @@ namespace iu9cawebchat { | |||||||
|                 int64_t logged_in_user = -1; |                 int64_t logged_in_user = -1; | ||||||
|                 initial_extraction_of_all_the_useful_info_from_cookies(*wgd.db, req, cookies, login_cookies, userinfo, logged_in_user); |                 initial_extraction_of_all_the_useful_info_from_cookies(*wgd.db, req, cookies, login_cookies, userinfo, logged_in_user); | ||||||
| 
 | 
 | ||||||
|                 std::string result; |  | ||||||
| 
 |  | ||||||
|                 if (req.uri_path == "/" || req.uri_path == "/list-rooms") { |                 if (req.uri_path == "/" || req.uri_path == "/list-rooms") { | ||||||
|                     if (logged_in_user < 0) |                     return when_page_list_rooms(wgd, config_presentation, req, login_cookies, userinfo); | ||||||
|                         result = een9::form_http_server_response_307("/login"); |  | ||||||
|                     return RTEE("list-rooms", config_presentation, wgd, userinfo); |  | ||||||
|                 } |                 } | ||||||
|                 if (req.uri_path == "/login") { |                 if (req.uri_path == "/login") { | ||||||
|                     return when_page_login(wgd, config_presentation, req, login_cookies, userinfo); |                     return when_page_login(wgd, config_presentation, req, login_cookies, userinfo); | ||||||
|                 } |                 } | ||||||
|                 if (req.uri_path == "/chat") { |                 if (req.uri_path == "/chat") { | ||||||
|  |                     // todo: write it actually
 | ||||||
|                     return RTEE("chat", config_presentation, wgd, userinfo); |                     return RTEE("chat", config_presentation, wgd, userinfo); | ||||||
|                 } |                 } | ||||||
|                 if (req.uri_path == "/profile") { |                 if (req.uri_path == "/profile") { | ||||||
|  |                     // todo: write it actually
 | ||||||
|                     return RTEE("profile", config_presentation, wgd, userinfo); |                     return RTEE("profile", config_presentation, wgd, userinfo); | ||||||
|                 } |                 } | ||||||
|                 // if (req.uri_path == "/registration") {
 |                 // if (req.uri_path == "/registration") {
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user