From patchwork Mon Sep 21 14:16:23 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: 1368418 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=KanZrakB; 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=kLkw5tEJ; 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 4Bw63r4B5pz9sSC for ; Tue, 22 Sep 2020 00:18:16 +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=hhQTz6HboV9au9LaFDGbGaQftTbA9Xa/cmzBxoG6xUI=; b=KanZrakBhSPdxmqqc4JVJInbis 8SgXY3DB532LXfP40dmEtnb/k7DUU/oSS1m/NtxQyBLQcZAr6bGPRwSxLkLf9GaXBN5TmzSGCkOai bWQ3ZRSkiEGeRMOa/g1JT524fZiSpLw0koLoPath+WUz1AQ+03Y8KRlhVO7GIIZypsr9FBLzV+F+R KXRJI6T9hsyCAZBTo3hKCuhhhmUi+hCOI651WW8BAzGrzYoFpTEP29mxyOp9nnPyvMwcDruELLnz+ KsRnMsNgAl3HT+ZUa/Emnmoo6VMC9pcCZvsG3Poz/x7Uyb/8qCQJo4xM8LEKGmrlAv85zRiX/SJ91 f6uwhfeA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKMcT-0000Lh-VD; Mon, 21 Sep 2020 14:16:41 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKMcR-0000L1-Ie for openwrt-devel@lists.openwrt.org; Mon, 21 Sep 2020 14:16:40 +0000 Received: by mail-lf1-x144.google.com with SMTP id 77so6877840lfj.0 for ; Mon, 21 Sep 2020 07:16:37 -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=Ldc43i25pxcIaYZ1RFwkV1jm0fSVYLHdUDNLJs+eps8=; b=kLkw5tEJQ0rHsMszquGqfkPFy1hieu4r5DNoCpOAFKuICdDDBtH5g3VeFIq3zlwj97 DYiw/+0jFmlLXcnymHbQsL+22vWYPLG9m7UKzgKAsKqXO8j95zxDzQYmbhXzeX6pwfhk Q5A/Nmtrz/iiIqnpyouzVJykTNjNHyhN+dJ3doq59QP0TFbfXFdz6w5TEstzat6RVx0e xuMV2xtPIGedBGslaKP6rieNTnWPl4c+Wy/e7ZGNENgIrcEjKhoFQCEYt7K15Qu+CoHg 0jxbNhHeM5NYuRdkitrAZlIv6irVQeTdgXjgJ6SnyPZxLMQ63Z41s3Bpay+AMAnIi+KE VHCQ== 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=Ldc43i25pxcIaYZ1RFwkV1jm0fSVYLHdUDNLJs+eps8=; b=F7kYTXU8M77qRPgH7Wlm4kZnCHIkI8SADYRti3ZpSIEbFyKfAhckeYEPHiLLxpNnn8 lS5oFuFPqRwly6YjZNv+eA3/0QYlozVoDkEMwH5EJoyhh0+vczV0IUiifPW9KO4e954b LApoPNevUApVNualV5HWIzHIwsKbSfQFT5PhBCb0DKioDeUEsb+Sd2+9ixiXxWxZ4tyw koNVpWLWW0QRevXedX7btdXAv0LRwY1FZck8RbwGPA03nzWARgzVv6JcJpcE1sbla5Dm sJlJJIseLrII2ek62SGsJJD6c12xIEgeGTyRgtkpStLn4Ehm2nUd44IJwDOActt6vDsc 2nUw== X-Gm-Message-State: AOAM531uStHsXwm00BUO2RBohvHJTdFmPWQdXcEkDZkWvkxgABSZ3fND 26vjERZJ7o7GSs+3t4eW5JnxbLCdM0w= X-Google-Smtp-Source: ABdhPJxOoV1zdEj5g/1pfHea92LbvlsQ7VcTbU2OJTIOH/Ta4qAvb1Q2kice2nsZAfdxCHcsajw4gA== X-Received: by 2002:a19:8c46:: with SMTP id i6mr59144lfj.55.1600697796183; Mon, 21 Sep 2020 07:16:36 -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 n14sm2605102lfi.50.2020.09.21.07.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 07:16:35 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH uhttpd] ubus: support GET method with CORS requests Date: Mon, 21 Sep 2020 16:16:23 +0200 Message-Id: <20200921141623.23608-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-20200921_101639_632415_AB49948F X-CRM114-Status: GOOD ( 14.65 ) 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.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:144 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zajec5[at]gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zajec5[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 Complex GET requests (e.g. those with custom headers) require browsers to send preflight OPTIONS request with: Access-Control-Request-Method: GET It's important to reply to such requests with all relevant Access-Control-Allow-* headers to allow CORS requests. Adding GET to the Access-Control-Allow-Methods is cosmetical as according to the Fetch standard: > If request’s method is not in methods, request’s method is not a > CORS-safelisted method, and request’s credentials mode is "include" or > methods does not contain `*`, then return a network error. It basically means that Access-Control-Allow-Methods value is ignored for GET, HEAD and POST methods. Signed-off-by: Rafał Miłecki --- ubus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ubus.c b/ubus.c index 1cf5c5f..39b38b2 100644 --- a/ubus.c +++ b/ubus.c @@ -164,7 +164,7 @@ static void uh_ubus_add_cors_headers(struct client *cl) { char *hdr = (char *) blobmsg_data(tb[HDR_ACCESS_CONTROL_REQUEST_METHOD]); - if (strcmp(hdr, "POST") && strcmp(hdr, "OPTIONS")) + if (strcmp(hdr, "GET") && strcmp(hdr, "POST") && strcmp(hdr, "OPTIONS")) return; } @@ -175,7 +175,7 @@ static void uh_ubus_add_cors_headers(struct client *cl) ustream_printf(cl->us, "Access-Control-Allow-Headers: %s\r\n", blobmsg_get_string(tb[HDR_ACCESS_CONTROL_REQUEST_HEADERS])); - ustream_printf(cl->us, "Access-Control-Allow-Methods: POST, OPTIONS\r\n"); + ustream_printf(cl->us, "Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n"); ustream_printf(cl->us, "Access-Control-Allow-Credentials: true\r\n"); }