June 23rd, 2024

Arbitrary shell command evaluation in Org Mode (GNU Emacs)

A vulnerability in Emacs Org mode allowed arbitrary shell command execution. A fix in Emacs 29.4 and Org 9.7.5 prevents unsafe code evaluation in link abbreviations, advising users to apply the patch.

Read original articleLink Icon
Arbitrary shell command evaluation in Org Mode (GNU Emacs)

A vulnerability in Emacs Org mode was reported by Ihor Radchenko, allowing arbitrary shell command evaluation when opening a specific .org file. The issue could execute commands without user prompts. A fix has been provided and integrated into Emacs 29.4 and Org 9.7.5. The fix prevents the evaluation of unsafe Elisp code in link abbreviations, displaying warnings instead. The patch includes changes to the 'org-link-expand-abbrev' function in 'ol.el' to mitigate potential vulnerabilities. Users are advised to apply the fix from the Org mode git repository. The vulnerability was disclosed on the oss-sec mailing list. Nmap.org, Npcap.com, Seclists.org, Sectools.org, and Insecure.org are related websites mentioned in the context of security tools and resources.

Link Icon 5 comments
By @metroholografix - 4 months
What's of greater importance here is not this specific security issue, but the default configuration of MIME handling in Emacs which can turn any unexpected evaluation bug -which we are likely to see more of- into remote code execution. We've had a previous Org security issue in exactly the same vein [1] and the Emacs MIME defaults are still unsafe. Of course, one can change them (non-trivial and related documentation is extremely confusing, see [2] for a possible solution) but really Emacs should not come with these defaults.

The loss of on-by-default functionality such as Org fontification in email message buffers is in no way as important as being wide open to trivial remote code execution.

[1] https://github.com/emacs-mirror/emacs/commit/befa9fcaae29a6c...

[2] https://xristos.sdf.org/fix-gnus-mime.el.txt

By @bloopernova - 4 months
The vulnerability is that Emacs evaluates this automatically:

#+LINK: shell %(shell-command-to-string) [[shell:touch ~/hacked.txt]]

By @ww520 - 4 months
I thought it’s feature. Org mode file can be used as a runable document. You have paragraphs of text and then a section containing executable code.
By @SEJeff - 4 months
Clearly, if you care about security here, the best thing is to just use vim.
By @ungamedplayer - 4 months
https://orgmode.org/manual/Code-Evaluation-Security.html

Following ‘shell’ and ‘elisp’ links Org has two link types that can directly evaluate code (see External Links). Because such code is not visible, these links have a potential risk. Org therefore prompts the user when it encounters such links. The customization variables are:

User Option: org-link-shell-confirm-function Function that prompts the user before executing a shell link.

User Option: org-link-elisp-confirm-function Function that prompts the user before executing an Emacs Lisp link.

Non issue. Rtfm.