From patchwork Tue Nov 10 08:02:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wojciech Jowsa X-Patchwork-Id: 1397415 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=O+E3S99a; 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=mF3Evrqg; 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 4CVgPJ4LySz9sTK for ; Tue, 10 Nov 2020 19:04:20 +1100 (AEDT) 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=ERCX2xgEI5aQ3JmmYEnjileuHXAcGgH1Vm20RgsQ2bY=; b=O+E3S99azn8XOVTB6OZl8je/Qp SC08DKNExqzLL6UTiNHcyEqNNVVDzNttbHDJO0L9Qa32zSh0EfHw8WbpI5gPGf27XMiXIECCHNc6t 3KikC1oImqc4TO7unJoLyZCZ2V7D29HpS+fQ0kjCG3Ezxh7rHYXiTDQ132KkKxewWY/lZdTcX0kGI uFOfY3fijlhxIp2o1Rmk3mwOtF6ZKSsnS+NZQZDRKMPqAw3CjUsxnIZX0hE8b8kz9crzb+puybLsk jA02cgq+aPUlF5QneTngyuUMT7YwYdnsFcWozYdy+6qf0PNv4Xgt0ORPDRJkAtaUSjF8PONHhvhy7 Cyk4VG4g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcOby-0001Mg-4r; Tue, 10 Nov 2020 08:02:42 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcObv-0001M3-Qv for openwrt-devel@lists.openwrt.org; Tue, 10 Nov 2020 08:02:40 +0000 Received: by mail-lj1-x244.google.com with SMTP id s9so11879045ljo.11 for ; Tue, 10 Nov 2020 00:02:37 -0800 (PST) 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=t19jXZmE3IjCz+mRk0VmLhlAVb+HOalId0v/HeH7A/8=; b=mF3EvrqgwQ41M0cv/j8rDhXLobyaJO4+21FfwOIkja9yIu3RB/Oq/N4hdp24y4/gdS VdGWo72mpAyv6DQru0bIwyDO+TlHK//gH6EZ36A8bgM7l+JratexXi/9vsrmXj0tGEOz 8da7gWTTsfC4WO7jLtRyNvHbYWKN976vBQx/F22xqQJCedG+2fp0rRLqtiUKOyE3uwWI Atm4MhQpfjgLhM9frn+hhi+hzKP+P7XdqCa4/jFg6yp+7RAON5e9yHCge1RBs1BkQwe0 o7vwleLBi2h/FyZtg3IGpi2z7HrXxHQJRxI5q0E1bK35Oi4jyPCPlY1+voxSKpO14Tji /g4Q== 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=t19jXZmE3IjCz+mRk0VmLhlAVb+HOalId0v/HeH7A/8=; b=drTUYVsWRHHVgkUkQqeMqeG/cH9s79L0Flv/ip/bTUeQ08IlZBgiHgwrqeCL4xeQ7Z McDax74NhvdiaB30T5DqClbE8IHBtZOSJHSaygWcEYMkfxE7QvijAje0qq1lmoGhVfkI bWW3rk8nKc+HpKB5lyBQptePXb600Lgdv4/o993sRJO+dmKw/KpKkkni8i6FMjF/vJ5I +6lKj6AllkxVxQi0MEM0m4HRDI4o86ztx9VAtW0J7QJnP75V8ASlPkB63OPiSKSV11wI iSx3mu592n/5ceV6GaNcUToVS2hMwHcFoRPY73WUj1gQtWEhfmv3fiQeG1h0F1gt5Gzv c7QA== X-Gm-Message-State: AOAM532ega0DDZW00kI4kSwUU+AvfoXcB/rnwJZwKsyYvBv/TtGTqU0G 6krqNPRmZkFJbf61HARWIEMPvXtc9mebBg== X-Google-Smtp-Source: ABdhPJz9ePlyQY71otdcMu6tBjq1gdNNr4FunY/HYSTCkQMGu6IqnfkPUJoIfMj/UnbMewuyCs1eMw== X-Received: by 2002:a05:651c:22e:: with SMTP id z14mr6036548ljn.321.1604995356554; Tue, 10 Nov 2020 00:02:36 -0800 (PST) Received: from wjow-XPS-15-9570.lan (host-188-122-2-56.finemedia.pl. [188.122.2.56]) by smtp.gmail.com with ESMTPSA id p24sm464632lfh.241.2020.11.10.00.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 00:02:35 -0800 (PST) From: Wojciech Jowsa To: openwrt-devel@lists.openwrt.org Subject: [PATCH] ubus: allow passing sid with url Date: Tue, 10 Nov 2020 09:02:09 +0100 Message-Id: <20201110080209.6368-1-wojciech.jowsa@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_030239_938380_A138AAB6 X-CRM114-Status: GOOD ( 13.61 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:244 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wojciech.jowsa[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_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_EF Message has a valid DKIM or DK signature from envelope-from 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: Wojciech Jowsa Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org In order to use EventSource web content's interface to server-sent events when ubus authentication is enabled, a session id has to be passed. Evensource interface does not allow to use bearer authentication header field. One of the possible solutions is to pass sid in url. Signed-off-by: Wojciech Jowsa --- ubus.c | 8 +++++++- uhttpd.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ubus.c b/ubus.c index cc7447e..06f5128 100644 --- a/ubus.c +++ b/ubus.c @@ -369,6 +369,10 @@ static void uh_ubus_handle_get_subscribe(struct client *cl, const char *path) sid = uh_ubus_get_auth(cl->hdr.head); + if(!strcmp(sid, UH_UBUS_DEFAULT_SID) && du->sid != NULL) { + sid = du->sid; + } + if (!conf.ubus_noauth && !uh_ubus_allowed(sid, path, ":subscribe")) { uh_ubus_send_header(cl, 200, "OK", "application/json"); uh_ubus_posix_error(cl, EACCES); @@ -940,8 +944,10 @@ static void uh_ubus_handle_request(struct client *cl, char *url, struct path_inf return; } chr = strchr(du->url_path, '?'); - if (chr) + if (chr) { + du->sid = chr + 1; chr[0] = '\0'; + } du->legacy = false; diff --git a/uhttpd.h b/uhttpd.h index e61e176..99372be 100644 --- a/uhttpd.h +++ b/uhttpd.h @@ -211,6 +211,7 @@ struct dispatch_ubus { struct json_object *jsobj; struct json_object *jsobj_cur; char *url_path; + char *sid; int post_len; uint32_t obj;