From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 0L/5ApxJW2NSdwEAbAwnHQ (envelope-from ) for ; Fri, 28 Oct 2022 05:16:44 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 0J3VApxJW2Oo2gAAauVa8A (envelope-from ) for ; Fri, 28 Oct 2022 05:16:44 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B7A1E2AB28 for ; Fri, 28 Oct 2022 05:16:43 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooFpY-0000Bx-Qh; Thu, 27 Oct 2022 23:14:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooFpX-0000Bn-Fm for emacs-orgmode@gnu.org; Thu, 27 Oct 2022 23:14:47 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooFpS-0004RK-9M for emacs-orgmode@gnu.org; Thu, 27 Oct 2022 23:14:47 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id DDCAA240026 for ; Fri, 28 Oct 2022 05:14:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1666926878; bh=8dIgV9Q18AOS0tALoOBbFDuXNFkpzmfkQgIsrFiZxag=; h=From:To:Cc:Subject:Date:From; b=YBuBOBFIeJf+p43J0ZIFDMvqCbQa1/P9ggU2A33cvUB5kmoBFIOC3srDpB1SS7PEa uwETbbjiybGmTQjYuZKEfEVDM4qmuz/dMte7d4Eq4AHFPrLQhTiXYK9Gew1y3AcF33 3b8769MItu4EwePHIJ+7QTN57BegQ9yWOyOUcwXlH+M/dXG+Boa02mQZJ7VEZGquW/ MUiklqGtgZvMxHkshHhvZwdiywrtfmbZrKtvkzJS8C9WX9nJUStGbVpgjz2cR9Rk4V 6GX4rVxINBSDWpzBUW6dndOIDvKpRMB01kwyXA+zavPCvR5ql010BFILRRXfMBUzvs 3SonzEQ5xt6jg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Mz72532Hfz6tr9; Fri, 28 Oct 2022 05:14:37 +0200 (CEST) From: Ihor Radchenko To: Max Nikulin Cc: emacs-orgmode@gnu.org Subject: [PATCH] Re: [BUG][Security] begin_src :var evaluated before the prompt to confirm execution In-Reply-To: References: Date: Fri, 28 Oct 2022 03:15:20 +0000 Message-ID: <87ilk4myev.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Emacs-orgmode" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1666927003; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=qN+CD9bLwgiCGlqZOWqDV1dWMw1aT6/GH1rX40SPV/U=; b=EotCS6G6rYwUFfJlRMuRBu1kqarqIA8q/TSXfnLjjTjJYLhD2sGPNkUQIMW886NIF4obt9 Og3T2YNVQVyzOA6Q3KWFd8dcOMPv1dJ6aXLEqaA/KNAYVeiE6dGHi+GoSNW2qmhVcuFUZJ kpcYsfSGKR2E+cNHv8xyGIJuodSr1Bb5WT8DxUbQw+Rx71YHWW9luwZd7hubR26WFkyuMJ rvFoAdHJD451ubld1aWUEWI+6nHsPdVcEFatG+vjrQMZCUBivMQXoSGTN2HZmN0MRH5pWM vbPG9OnqohLDZw7upgpOkyzrM4DfAdp+JmN64AJcvQARrqYEJd0Nw2mkQwKhIA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1666927003; a=rsa-sha256; cv=none; b=Z7HbZF9SxXktQDRYAeoTmuvu6xMJUrdVhKuLsm5Hewa7ozeS3yeLRLffOMzMoAf0NzfCTn Le6A7iLFyUBdueGuTkqyydU/4mb+bDWUQyDXCAysVZbr2TmoBQ6AxOFqRMB3oAQD2WZyvO DsbdTfHhvST1ngz/QC4Q7e/mI/dT1duBLNzECXe+zoR1IILZKEOjQdjnRSxastDums77nv zRcR6cH+iI/tmkl4olD4igsDaDxwgxo3Emmh/5Q63leIrihK5/dwDnEzkZpTcwSivsgDRe 9u20slF5TP8x2NgKpczAT94MvA5P01aecO5d8H/DP9f3OaYV82fWnTI7+woxiQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=YBuBOBFI; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.11 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=YBuBOBFI; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: B7A1E2AB28 X-Spam-Score: -2.11 X-Migadu-Scanner: scn1.migadu.com X-TUID: XRIm2FR+Eo9C --=-=-= Content-Type: text/plain Max Nikulin writes: > Consider the following source block > > ---- >8 ---- > #+begin_src elisp :var a=(message "%s" "pwnd") > a > #+end_src > ---- 8< ---- > > Open the "*Messages*" buffer (C-h e) and try to evaluate the source > block (C-c C-c). > > Actual result: > "pwnd" message appears in "*Messages*" simultaneously with user prompt > whether the code should be executed. > > Expected result: > No code from the Org buffer and linked files is executed prior to > confirmation from the user. Confirmed. See the attached tentative patch. I tried to balance between annoying users with query and not evaluating unsafe code: '-quoted lists and symbols are still evaluated without prompt. Let me know if you see any potential issues. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-babel-read-Obey-org-confirm-babel-evaluate.patch >From 961a3ee38a2b9521427fddea5102d003f39b88d6 Mon Sep 17 00:00:00 2001 Message-Id: <961a3ee38a2b9521427fddea5102d003f39b88d6.1666926796.git.yantar92@posteo.net> From: Ihor Radchenko Date: Fri, 28 Oct 2022 11:09:50 +0800 Subject: [PATCH] org-babel-read: Obey `org-confirm-babel-evaluate' * lisp/ob-core.el (org-babel-read): Do not execute arbitrary Elisp without prompt, according to `org-confirm-babel-evaluate'. Reported-by: Max Nikulin Link: https://orgmode.org/list/tjct9e$179u$1@ciao.gmane.io --- lisp/ob-core.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 518831ec6..e10ab401c 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -3165,7 +3165,16 @@ (defun org-babel-read (cell &optional inhibit-lisp-eval) ((and (not inhibit-lisp-eval) (or (memq (string-to-char cell) '(?\( ?' ?` ?\[)) (string= cell "*this*"))) - (eval (read cell) t)) + ;; Prevent arbitrary function calls. + (if (and (memq (string-to-char cell) '(?\( ?`)) + (not (org-babel-confirm-evaluate + ;; See `org-babel-get-src-block-info'. + (list "emacs-lisp" (format "%S" cell) + '((:eval . yes)) nil (format "%S" cell) + nil nil)))) + ;; Not allowed. + (user-error "Evaluation of elisp code %S aborted." cell) + (eval (read cell) t))) ((save-match-data (and (string-match "^[[:space:]]*\"\\(.*\\)\"[[:space:]]*$" cell) (not (string-match "[^\\]\"" (match-string 1 cell))))) -- 2.35.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--