From 5007c740a265d2b89217fc36488af223a96e8529 Mon Sep 17 00:00:00 2001 From: "denis.sumin" <denis.sumin@demlabs.net> Date: Wed, 3 Aug 2022 16:19:04 +0300 Subject: [PATCH 1/4] [*] update node and filtering preflight requests from web --- .../DapWeb3Api/DapWebControll.cpp | 19 +++++++++++++++++++ cellframe-node | 2 +- config.pri | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp b/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp index 04fba3a4d..58a177528 100644 --- a/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp +++ b/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp @@ -132,6 +132,25 @@ void DapWebControll::onClientSocketReadyRead() QByteArray encodedString = s_tcpSocketList[idUser]->readAll(); QString req = QUrl::fromPercentEncoding(encodedString); + + if(req.contains("Access-Control-Request-Method") && req.contains("Access-Control-Request-Private-Network")) + { + qDebug()<<"Preflight web request"; + + QTextStream answer(s_tcpSocketList[idUser]); + answer.setAutoDetectUnicode(true); + answer + <<"HTTP/1.1 204 No Content\r\n" + <<"Connection: keep-alive\r\n" + <<"Access-Control-Allow-Origin: *\r\n" + <<"Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE\r\n" + <<"\r\n"; + s_tcpSocketList[idUser]->flush(); + s_tcpSocketList[idUser]->close(); + s_tcpSocketList.remove(s_tcpSocketList[idUser]->socketDescriptor()); + return; + } + QStringList list = req.split("\n", QString::SkipEmptyParts); QRegularExpression regex(R"(method=([a-zA-Z]+))"); QRegularExpressionMatch match = regex.match(list.at(0)); diff --git a/cellframe-node b/cellframe-node index 1fbf651e9..ebd9e08af 160000 --- a/cellframe-node +++ b/cellframe-node @@ -1 +1 @@ -Subproject commit 1fbf651e9f1f4887294ac3c4ec15ecfe320add2b +Subproject commit ebd9e08af3f8fcd8124b5e1facd487f416f45c4b diff --git a/config.pri b/config.pri index 6f9beee00..9f1cece6e 100644 --- a/config.pri +++ b/config.pri @@ -8,7 +8,7 @@ VER_MAJ = 2 VER_MIN = 8 -VER_PAT = 15 +VER_PAT = 16 DEFINES += DAP_BRAND=\\\"$$BRAND\\\" -- GitLab From ea5e9904cfbd7eb071bb12e973f75269fa07fefd Mon Sep 17 00:00:00 2001 From: Denis Sumin <denis.smolov@demlabs.net> Date: Wed, 3 Aug 2022 14:21:16 +0000 Subject: [PATCH 2/4] Update DapWebControll.cpp --- CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp b/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp index 58a177528..01e7af2af 100644 --- a/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp +++ b/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp @@ -133,7 +133,7 @@ void DapWebControll::onClientSocketReadyRead() QByteArray encodedString = s_tcpSocketList[idUser]->readAll(); QString req = QUrl::fromPercentEncoding(encodedString); - if(req.contains("Access-Control-Request-Method") && req.contains("Access-Control-Request-Private-Network")) + if(req.contains("Access-Control-Request-Method") || req.contains("Access-Control-Request-Private-Network")) { qDebug()<<"Preflight web request"; -- GitLab From 7f75dc14cbacc5244a7b9ff84a17a1e27fbd8e3a Mon Sep 17 00:00:00 2001 From: "denis.sumin" <denis.smolov@demlabs.net> Date: Thu, 4 Aug 2022 11:15:12 +0300 Subject: [PATCH 3/4] [*] fix filterung preflight and checked web id --- .../DapWeb3Api/DapProcessingNodeFunc.cpp | 2 ++ CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CellFrameDashboardService/DapWeb3Api/DapProcessingNodeFunc.cpp b/CellFrameDashboardService/DapWeb3Api/DapProcessingNodeFunc.cpp index 1782ad131..84212690f 100644 --- a/CellFrameDashboardService/DapWeb3Api/DapProcessingNodeFunc.cpp +++ b/CellFrameDashboardService/DapWeb3Api/DapProcessingNodeFunc.cpp @@ -363,6 +363,8 @@ QJsonDocument DapWebControll::sendJsonTransaction(QJsonDocument jsonCommand) QJsonDocument docResult; if(result.isEmpty()) docResult = processingResult("bad", QString("Node is offline")); + else if(result.contains("No valid items")) + docResult = processingResult("bad", result); else docResult = processingResult("ok", "", result); diff --git a/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp b/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp index 01e7af2af..323cc5b76 100644 --- a/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp +++ b/CellFrameDashboardService/DapWeb3Api/DapWebControll.cpp @@ -133,7 +133,7 @@ void DapWebControll::onClientSocketReadyRead() QByteArray encodedString = s_tcpSocketList[idUser]->readAll(); QString req = QUrl::fromPercentEncoding(encodedString); - if(req.contains("Access-Control-Request-Method") || req.contains("Access-Control-Request-Private-Network")) + if(req.contains("OPTIONS") || req.contains("Access-Control-Request-Method") || req.contains("Access-Control-Request-Private-Network")) { qDebug()<<"Preflight web request"; @@ -198,7 +198,7 @@ void DapWebControll::onClientSocketReadyRead() else if(match.captured(1) == "hashTx") hashTx = match.captured(2); } - if(s_id.filter(id).length()){ + if(!s_id.isEmpty() && s_id.filter(id).length()){ if(cmd == "GetWallets") doc = getWallets(); else if(cmd == "GetNetworks") -- GitLab From 61104004a1b6ecdea53a4b0c5b2f4ce2cc06a664 Mon Sep 17 00:00:00 2001 From: "denis.sumin" <denis.smolov@demlabs.net> Date: Thu, 4 Aug 2022 11:15:52 +0300 Subject: [PATCH 4/4] [*] update node --- cellframe-node | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cellframe-node b/cellframe-node index ebd9e08af..2c916eff4 160000 --- a/cellframe-node +++ b/cellframe-node @@ -1 +1 @@ -Subproject commit ebd9e08af3f8fcd8124b5e1facd487f416f45c4b +Subproject commit 2c916eff4ac694bc4d2a4aa4173a6571b1954f1f -- GitLab