From patchwork Mon Sep 14 16:31:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1363800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=w+/2NlcT; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rASD4Twl; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BqsNn5Bq3z9sTM for ; Tue, 15 Sep 2020 02:33:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=VeMopRJmh5yjGygcagFI0NA6+h9lkF+iZHr+gujTS+Q=; b=w+/2NlcTooDnnc9WWf4PmNMA1H pX9rIx7cDy2bZfECEKikqOFNbVbu1rqLPMrMmGa4vrhiFzdy+pyQVqHRZbgwEz0A7CzlhRA50I7sm 06uJ+SFf4uFTeRw4PcvLVr0BlYbDvaGEnYHaQ0v8KT7sa0tlW/2cHFeqpJwKuh7phgzlPkzfidP9I wNIWUyFdVaRaoqO0fed1XCCVyuiT8n4W/Xqz4cHAIxHGjdi60M5TVzXrbwZa5T4WeCJHzQofXnHFJ wmFRDFe/g9CZJcS6xzVsUgvnz/xguZZdZL/ys7L/Tk+QJj07MBGebmQJ2swDizPlUfw88FNVmiIp5 X8WCrL2w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kHrO8-0004b5-9Z; Mon, 14 Sep 2020 16:31:32 +0000 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kHrO6-0004af-54 for openwrt-devel@lists.openwrt.org; Mon, 14 Sep 2020 16:31:30 +0000 Received: by mail-lj1-x236.google.com with SMTP id k25so258622ljk.0 for ; Mon, 14 Sep 2020 09:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x8/YG+TgNcU10KPsE+otKw7r5PSXAlY8r+kHdavVF9Q=; b=rASD4TwlFsemoMFqcsCTxpSqwHH4DUJrogWs2cq6TJyPZuPBAnFnCq9c6nMozUcIbi +WuMS5yknV2Tmdd7eibUBe54CZlpFyWz4LmUZtG7smAATT1umhElsDUu2GkR3m4LHQo9 fAeLPfc9JtieGZR+cL7U/Sv7915UBhAUoxpVuBCXC+qJoyzVsqk4D3DL3wz+V4TA/GuX CTvEYsoUAIhsdDakS2rVD1iqaMjnRX/8EjFl+CV0Acip9tssYqyxB5SJxoizZEXNml9K 69zvsgFPGKtV/9YnDFYSzfn2i1RaBJ40jba/QE70fiHKkBj0zeErmw2iQwU2A+lxG4ps Yhig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x8/YG+TgNcU10KPsE+otKw7r5PSXAlY8r+kHdavVF9Q=; b=h5zE7trOptQR8g0aijlA90x7JuBVmbGS3JUFimevCeKqFNM7N4mTzqOAH5l9cgMsx1 YUqu0ZgkSX5Yzaua94mVRuT1x7LwYlwNiUS0/eDxfMH8g+BacrWztsJF+E6SltnNUDQZ ymzs15gHLny3tG+PDdJtTUA1QJILQ/LNzq59Xpw3vb5he/a7j108+3KgXqP+L5VGw0fl dZ8oq1cuQKQW6H/Y/4fdHWbgZSdl3s3f3a7QTNSppsItH5wYtSDY5kGarpALgbcsXoXY ynQ9ay1wY5vMWnV9tCuiLoEYQu74cguAqYoFcp2tBDgvi1+vZ5S33V6RNVPCq/Ducqnu NBbQ== X-Gm-Message-State: AOAM531YPDT9XOJKxY0hSOUU7+C4geCcMXThSGkaAfLdklEOucJR6p1w Uo2UYJ4QZih2YxPp70B15WxfAgCeNJM= X-Google-Smtp-Source: ABdhPJxp9mWoGxZgfjSYguh+XWw8zTv+kYY8bGafPi1Z7e+8WcgjnNtFB/m1hMO3YvmQzetKP7IXZQ== X-Received: by 2002:a2e:7c14:: with SMTP id x20mr5819474ljc.220.1600101088101; Mon, 14 Sep 2020 09:31:28 -0700 (PDT) Received: from localhost.localdomain (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id y25sm4126113ljd.79.2020.09.14.09.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 09:31:27 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH luci] luci-base: use actual JSON-RPC for verifying ubus RPC URL Date: Mon, 14 Sep 2020 18:31:07 +0200 Message-Id: <20200914163107.27739-1-zajec5@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200914_123130_209151_DD844A66 X-CRM114-Status: GOOD ( 12.41 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zajec5[at]gmail.com] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:236 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zajec5[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Jo-Philipp Wich Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki Sending GET request to the main RPC base URL and expecting HTTP response code 400 had two flaws: 1. It was not verifying actual JSON-RPC interface availability 2. It did not allow implementing support for new requests Signed-off-by: Rafał Miłecki --- .../luci-base/htdocs/luci-static/resources/luci.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 83c2807d7..e285f999e 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -2553,10 +2553,19 @@ rpcBaseURL = Session.getLocalData('rpcBaseURL'); if (rpcBaseURL == null) { + var msg = { + jsonrpc: '2.0', + id: 'init', + method: 'list', + params: undefined + }; + var options = { + nobatch: true + }; var rpcFallbackURL = this.url('admin/ubus'); - rpcBaseURL = Request.get(env.ubuspath).then(function(res) { - return (rpcBaseURL = (res.status == 400) ? env.ubuspath : rpcFallbackURL); + rpcBaseURL = Request.post(env.ubuspath, msg, options).then(function(res) { + return (rpcBaseURL = res.status == 200 ? env.ubuspath : rpcFallbackURL); }, function() { return (rpcBaseURL = rpcFallbackURL); }).then(function(url) {