From: lux <lx@shellcodes.org>
To: Max Nikulin <manikulin@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] Fix ob-latex.el command injection vulnerability.
Date: Wed, 08 Mar 2023 23:42:58 +0800 [thread overview]
Message-ID: <tencent_2A4B339A354335947724F292E1F9C1A69C08@qq.com> (raw)
In-Reply-To: <047b7367-c98f-e531-b3e9-bc50b6b098e5@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 873 bytes --]
On Tue, 2023-03-07 at 22:31 +0700, Max Nikulin wrote:
> On 06/03/2023 10:17, lux wrote:
> > On Sat, 2023-02-18 at 11:43 +0000, Ihor Radchenko wrote:
> > >
> > > I think should be (rename-file img-out out-file t)
> >
> > Fixed, thank you.
>
> There are a couple more mv shell commands in ob-latex.el. It would be
> nice to fix them as well. Sorry, I have not checked it earlier. Are
> you
> still interested in this topic? I hope, you already have examples
> that
> can be used to quickly test if modified code works as expected.
Hi, this is a new patch, let me briefly explain this patch:
1. Replaced the `(shell-command "mv BAR NEWBAR")' with `rename-file'.
2. `org-babel-latex-convert-pdf' is not safe, simple test:
(org-babel-latex-convert-pdf ";id;.tex" ";uname;.pdf" "" "")
So, add `shell-quote-argument' to each external parameter.
[-- Attachment #2: 0001-lisp-ob-latex.el-Fix-command-injection-vulnerability.patch --]
[-- Type: text/x-patch, Size: 2298 bytes --]
From 62f9d32decdd078633e51ea9fa30fdb000b6de51 Mon Sep 17 00:00:00 2001
From: Xi Lu <lx@shellcodes.org>
Date: Wed, 8 Mar 2023 23:28:32 +0800
Subject: [PATCH] * lisp/ob-latex.el: Fix command injection vulnerability
(org-babel-execute:latex): Fix command injection vulnerability
(org-babel-latex-convert-pdf): Add `shell-quote-argument'
---
lisp/ob-latex.el | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index a2c24b3d9..2315a8b7c 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -218,17 +218,14 @@ This function is called by `org-babel-execute-src-block'."
(if (string-suffix-p ".svg" out-file)
(progn
(shell-command "pwd")
- (shell-command (format "mv %s %s"
- (concat (file-name-sans-extension tex-file) "-1.svg")
- out-file)))
+ (rename-file (concat (file-name-sans-extension tex-file) "-1.svg")
+ out-file t))
(error "SVG file produced but HTML file requested")))
((file-exists-p (concat (file-name-sans-extension tex-file) ".html"))
(if (string-suffix-p ".html" out-file)
- (shell-command "mv %s %s"
- (concat (file-name-sans-extension tex-file)
- ".html")
- out-file)
- (error "HTML file produced but SVG file requested")))))
+ (rename-file (concat (file-name-sans-extension tex-file) ".html")
+ out-file t)
+ (error "HTML file produced but SVG file requested")))))
((or (string= "pdf" extension) imagemagick)
(with-temp-file tex-file
(require 'ox-latex)
@@ -277,8 +274,10 @@ This function is called by `org-babel-execute-src-block'."
(defun org-babel-latex-convert-pdf (pdffile out-file im-in-options im-out-options)
"Generate a file from a pdf file using imagemagick."
- (let ((cmd (concat "convert " im-in-options " " pdffile " "
- im-out-options " " out-file)))
+ (let ((cmd (concat "convert " (shell-quote-argument im-in-options) " "
+ (shell-quote-argument pdffile) " "
+ (shell-quote-argument im-out-options) " "
+ (shell-quote-argument out-file))))
(message "Converting pdffile file %s..." cmd)
(shell-command cmd)))
--
2.39.2
next prev parent reply other threads:[~2023-03-08 15:45 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-18 10:08 [PATCH] Fix ob-latex.el command injection vulnerability lux
2023-02-18 11:15 ` Max Nikulin
2023-02-18 11:28 ` lux
2023-02-18 11:43 ` Ihor Radchenko
2023-02-19 2:31 ` lux
2023-03-06 3:17 ` lux
2023-03-07 12:35 ` Ihor Radchenko
2023-03-07 13:20 ` lux
2023-03-07 13:52 ` Ihor Radchenko
2023-03-07 15:06 ` Bastien Guerry
2023-03-07 15:10 ` Ihor Radchenko
2023-03-07 15:31 ` Max Nikulin
2023-03-08 2:28 ` lux
2023-03-08 15:42 ` lux [this message]
2023-03-09 12:22 ` Ihor Radchenko
2023-03-09 16:29 ` Max Nikulin
2023-03-11 5:12 ` lux
2023-03-11 10:47 ` Ihor Radchenko
2023-03-11 10:57 ` lux
2023-03-12 11:28 ` Ihor Radchenko
2023-05-01 10:56 ` Max Nikulin
2023-05-01 11:18 ` Ihor Radchenko
2023-05-02 11:02 ` CVE-2023-28617 (was Re: [PATCH] Fix ob-latex.el command injection vulnerability.) Max Nikulin
2023-05-02 11:21 ` Ihor Radchenko
2023-05-11 15:56 ` Max Nikulin
2023-05-12 13:42 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_2A4B339A354335947724F292E1F9C1A69C08@qq.com \
--to=lx@shellcodes.org \
--cc=emacs-orgmode@gnu.org \
--cc=manikulin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).