From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id cFEYK5F942Q7eAEASxT56A (envelope-from ) for ; Mon, 21 Aug 2023 17:06:57 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 4B3mKpF942STDQEAauVa8A (envelope-from ) for ; Mon, 21 Aug 2023 17:06:57 +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 5B9E04E16F for ; Mon, 21 Aug 2023 17:06:57 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=none; 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"; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1692630417; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wlGX3hyWxB5nswuB6tJPA7iy3jeu1olmcSd85iX0FyU=; b=NsAAR7r0jot/DIHY/GarNola1CPk+fwpBN1AMKcupIidxOl+q2H4wE2ibmh7KIpX9bn4OH IhNg4y/dNDwsApxASTXS6QBBe3j/Zbu7ha7joj8334ti320EbjaP/EYstOkjgBVMqsudyu rzHdlfQOh+dnqKbYFskaVsiCqjlllaj9AdIawybu6aK66QelNIst1yWjBFnCYtCWyBl4tx 6e+ePXX+UNx0sv3+CogFU8WDLdXcrXY+kvMfGZBSJySrfmPBmi/yyNdf6jdxr+02zk/oKs kfuCbkNwCnsf6Sz6jb05FiS/0LK7SRK5mGs1UM8fYalscOm8p0VECMxDsMJiEg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1692630417; a=rsa-sha256; cv=none; b=T3HmVee5eRjJmNWTHpdMEA5Z4bo93W7NYHWYQL5VTQEv7dWFRjTVxNVv88SJJhycBjOPzk 76eKaIb+YT+KPUrXqYnIz42r8VHFrLerm2+ZnCxc0l3xcgTKPN5sdY5KVfAmgR7kv5w5AM EAf/fcLUcIn0fm1yQnedTOafh5Jpob4Pv4VmLKBQEyewEX9rqqMETmS2s+3/AlEMwQ2Uh6 SCZd7sOGvONJAYeBN6z2CHZ+C03tGV6A7CYk4DHOsNRUhZu723zBv/Kprz06OsT31hI78Y A75/Uu20ZDyab9gihTWm9SVCKNxOrnKKLeGo0f3upaL3ujOU77XsMjOb3X+ilA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; 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"; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qY6To-0001l1-Mf; Mon, 21 Aug 2023 11:06:08 -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 1qY6Tm-0001kq-Gt for emacs-orgmode@gnu.org; Mon, 21 Aug 2023 11:06:06 -0400 Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qY6Tk-00055o-06 for emacs-orgmode@gnu.org; Mon, 21 Aug 2023 11:06:06 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1qY6Th-0000Fj-EE for emacs-orgmode@gnu.org; Mon, 21 Aug 2023 17:06:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Re: [BUG][SECURITY] ob-sqlite header args allows execution of arbitrary shell commands Date: Mon, 21 Aug 2023 22:05:54 +0700 Message-ID: References: <87zg2vl6qc.fsf@localhost> <87cyzkpwp4.fsf@localhost> <87o7j43921.fsf@localhost> <87h6os6fm6.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Content-Language: en-US, ru-RU In-Reply-To: <87h6os6fm6.fsf@localhost> Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NICE_REPLY_A=-3.374, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -5.04 X-Spam-Score: -5.04 X-Migadu-Queue-Id: 5B9E04E16F X-Migadu-Scanner: mx1.migadu.com X-TUID: hrt+nr6hDxvR On 21/08/2023 14:04, Ihor Radchenko wrote: > +(defconst org-shell-arg-literal (gensym "literal") (opinion) Perhaps a better name exists. Maybe org-shell-arg-tag-unescaped (or unquoted) > + "Symbol to be used to mark shell arguments that should not be escaped. > +See `org-make-shell-command'.") > +(defun org-make-shell-command (command &rest args) > + "Build safe shell command string to run COMMAND with ARGS. > + > +The resulting shell command is safe against malicious shell expansion. > + > +ARGS can be nil, strings, (LITERAL STRING), or a list of (opinion) I would give an example `(,ob-shell-arg-literal STRING) to avoid "LITERAL" that is confusing from my point of view. Perhaps it is better to describe its purpose more clearly: prevent raw shell constructs in ob header arguments in Org documents unless they appear in evaluated expressions. > +such elements. LITERAL must be the value of `org-shell-arg-literal'. > + > +Strings will be quoted with `shell-quote-argument' while \(literal > +STRING) will be used without quoting. nil values will be ignored." > + (concat > + command (when command " ") > + (mapconcat > + #'identity > + (delq > + nil > + (mapcar > + (lambda (str-def) > + (pcase str-def > + (`(or nil "") nil) An empty string may be an important argument. E.g. read -r -d "" var allows to read values separated by null character (\0), e.g. from output of find -print0. That is why I would leave just nil. > + (when separator (format "-separator %s" separator)) Sorry, I made a typo previous time. It would not work. -separator and the separator character must *not* be combined into single argument. Sqlite does not support it. (and separator `("-separator" ,separator)) or (format "%s" separator) if it may have a type other than string. I hope, this approach does not have unnoticed flaws.