Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict what Java functions can be called from Lisp #693

Open
Burkino opened this issue Jan 3, 2025 · 2 comments
Open

Restrict what Java functions can be called from Lisp #693

Burkino opened this issue Jan 3, 2025 · 2 comments

Comments

@Burkino
Copy link

Burkino commented Jan 3, 2025

So I'm thinking of using ABCL as a simple scripting language inside of a Minecraft mod. Since all the text is user controlled (and possibly running on a public server) I'm sure you can see why allowing jcall and jstatic would be a bad idea.

My questions are:

  1. How do I give ABCL the least amount of privilege? It shouldn't be able to do whatever it wants with Java, it shouldn't be able to get any information about the system.
  2. How do I add my own symbol to ABCL, the docs talk about converting Java objects to Lisp values which sounds right, but I might be misunderstanding.
@easye
Copy link
Collaborator

easye commented Jan 3, 2025

In general there is no way to "lock down" a given instance of ABCL (or any Common Lisp implementation) so that the eval of arbitrary expressions can be restricted in a meaningful way. One usually defines a "smaller" language for ones needs which is carefully restricted to the capabilities one wishes to expose from the host, and implements an carefully restricted interpreter for that domain specific language. Unfortunately, this is usually a lot more work than one wants to do when one just wants to use ABCL as a scripting language.

Just adding a symbol is trivially easy:

(intern 'my-own-symbol)

But I guess that you are probably after adding a symbol bound to callable Lisp function interfacing to something coded in Java? The easiest way to do this is ensure that the required Java classes are present in the ABCL's runtime classpath, then write a little bit of Lisp code from either the java or jss packaging to glue calling that function. When ABCL starts up, arrange that this Lisp glue code defining the function interface is run via specifying code to run via --load command line arguments or by modifying the contents of the system.lisp file, and voila!

To do the equivalent entirely in Java is also possible, but is rather more difficult as one is essentially extending ABCL. To go this route, you should study the implementation a bit, perhaps by studying how primitives are defined.

@yitzchak
Copy link
Contributor

yitzchak commented Jan 3, 2025

@Burkino One proposed way to do "sandboxing" in Common Lisp is via First-class Global Environments. This hasn't been implemented in any CL implementation yet, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants