emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix ob-latex.el command injection vulnerability.


From: lux
Subject: [PATCH] Fix ob-latex.el command injection vulnerability.
Date: Sat, 18 Feb 2023 18:08:44 +0800
User-agent: Evolution 3.46.3 (3.46.3-1.fc37)

Test environment:
- Emacs 29.0.60
- Orgmode 9.6.1
- TeX Live 2020

Preconditions:

(org-babel-do-load-languages
 'org-babel-load-languages
 '((latex . t)))

The vulnerability occurs in the file ob-latex.el, in the `org-babel-
execute:latex' function, if then file's extension is .svg, using
`shell-command' function to call the `mv' shell command:

  ((string= "svg" extension)
   ...
   (let ((tmp-pdf (org-babel-latex-tex-to-pdf tex-file)))
     (let* (...
            (img-out (org-compile-file
                      tmp-pdf
                      (list org-babel-latex-pdf-svg-process)
                      extension err-msg log-buf)))
       (shell-command (format "mv %s %s" img-out out-file)))))

But the parameter `img-out' and parameter `out-file' are not escape.
So, if file name or directory name contains shell characters and will
be executed.

Example for the vul_test.org file:

  #+name: vul_test
  #+header: :file test;uname -a;.svg
  #+begin_src latex
  \LaTeX
  #+end_src

Using Emacs open it, and press 'C-c C-e l p' export to a pdf file, or
point to begin_src block and press 'C-c C-c' to execute block.

In the '*Message*' buffer, you can see the 'uname -a' command output:

  Executing Latex code block (vul_test)...
  Processing LaTeX file /tmp/babel-UCtwdU/latex-zWDsHS.tex...
  PDF file produced.

  ,** (org.inkscape.Inkscape:145910): WARNING **: 17:27:24.285: Fonts
dir '/usr/share/inkscape/fonts' does not exist and will be ignored.
  Linux lx-debian 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21)
x86_64 GNU/Linux  <---- This is 'uname -a' output
  zsh:1: command not found: .svg
  Code block produced no output (took 1.1s).

This patch fixed it.

Attachment: 0001-lisp-ob-latex.el-org-babel-execute-latex-Fix-command.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]