v0.3.1: eliminate RCE via *read-eval* nil (Parser RCE Elimination)
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 3s
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 3s
Wrap read-from-string/read with (let ((*read-eval* nil)) ...) at three untrusted-input code paths: 1. think() in core-loop-reason — LLM output parsing. LLM output is untrusted by definition; #.(shell ...) in a response must not execute. 2. action-system-execute in core-loop-act — :system :eval path processes untrusted payload code from the signal pipeline. 3. load-memory-from-disk in core-memory — memory.snap file could be corrupted or planted in ~/, must not execute #. reader macros. Adds test-read-eval-rce-blocked to pipeline-reason-suite: mocks a backend returning malicious output containing #.(setf ...), verifies no side effects occur and safe fallback is returned. RED proof recorded: *read-eval* T + #.(setf ...) → :PWNED (RCE active) GREEN proof: *read-eval* NIL → reader-error caught (RCE blocked) Test: reason 12/0, full suite 88/0
This commit is contained in:
@@ -99,7 +99,7 @@
|
||||
(markdown-strip thought))))
|
||||
(if (and cleaned (stringp cleaned) (> (length cleaned) 0) (or (char= (char cleaned 0) #\() (char= (char cleaned 0) #\[)))
|
||||
(handler-case
|
||||
(let ((parsed (read-from-string cleaned)))
|
||||
(let ((parsed (let ((*read-eval* nil)) (read-from-string cleaned))))
|
||||
(if (listp parsed)
|
||||
(let ((normalized (plist-keywords-normalize parsed)))
|
||||
;; Ensure explanation is present in the payload for policy gate
|
||||
@@ -283,3 +283,19 @@ sorted by priority (highest first). Returns a rejection plist or the action."
|
||||
(list :status :success :content "mock-response")))
|
||||
(let ((result (backend-cascade-call "hello" :cascade '(:mock-backend))))
|
||||
(is (string= "mock-response" result)))))
|
||||
|
||||
(test test-read-eval-rce-blocked
|
||||
"Contract 1/v0.3.1: #. reader macro in LLM output must not execute arbitrary code."
|
||||
(let ((passepartout::*backend-registry* (make-hash-table :test 'equal))
|
||||
(passepartout::*provider-cascade* '(:mock-evil)))
|
||||
(setf (gethash :mock-evil passepartout::*backend-registry*)
|
||||
(lambda (prompt sp &key model)
|
||||
(declare (ignore prompt sp model))
|
||||
(list :status :success :content "(#.(setf passepartout::*v031-rce-test* :PWNED))")))
|
||||
(setf passepartout::*v031-rce-test* nil)
|
||||
(setf *read-eval* t)
|
||||
(let* ((ctx (list :type :EVENT :payload (list :sensor :user-input :text "test") :depth 0))
|
||||
(result (passepartout::think ctx)))
|
||||
(is (not (eq passepartout::*v031-rce-test* :PWNED)))
|
||||
(is (eq :REQUEST (getf result :TYPE)))
|
||||
(setf *read-eval* nil))))
|
||||
|
||||
Reference in New Issue
Block a user