Re: Security concerns in Common Lisp
Daniel Weinreb writes:
>
>
>
> Jeff Massung wrote:
> >
> > Let's say I created a simple web server with LispWorks that had a
> > simple edit box that allowed a visitor to play with Lisp, enter an
> > expression, click submit, and see the results. What prevents the user
> > from entering something akin to (run-shell-command "format c:")?
>
> Nothing, really. Such a server is inherently highly unsafe. I know
> of no Common Lisp implementation that attempts to implement a
> "sandbox" of the sort that Java attempts to implement. You have to
> limit its privileges using the underlying operating system's
> facilities.
Well indeed, one good way would be to move the border further out. Use
a virtual unix machine, such as a user-mode-linux VM or a xen VM,
configured to avoid leaking network priviledges, and run the lisp
inside it. Configure it to allocate it a bound CPU time percentage.
When a remote user connects, make a copy (or CoW) of the image, and
then the remote user may do whatever evil it wants, it'll stay inside
the VM. When he's done, delete the image.
> > But, what if it was just an end application reading a configuration
> > file with Lisp data for ease or (as in my case) a server/client
> > sending Lisp data back and forth across the internet, where both users
> > are most likely running as superusers (yay for Windows)?
>
> Ah. First, it's really not a great idea to design your system so that your
> configuration files are Lisp forms to be evaluated. First, it's just too
> easy for mistakes to have arbitrary, bad effects. Second, full Lisp
> is usually "too powerful", in the sense that a simple declarative
> format can be parsed easily by a program, whereas a Lisp file
> might have arbitrarily complex Lisp forms that are hard for
> a program to understand.
I don't agree. '.bashrc' and '.emacs' are two examples showing that
it's good to have executable configuration, (not to mention ~/.sbclrc
and such).
> Yes, there are good reasons for
> programs that can read and understand config files. You may not
> have one now, but you should design your architecture to allow
> for them in the future, IMHO based on years of experience.
>
> If you really are going to use Lisp, but not Lisp forms,
> then you'll find yourself using the Lisp "read" but not
> the Lisp "eval". That's a lot safer, but there is one
> hazard that you need to know about: there is a reader
> macro, #., that means "read one form and evaluate it".
Of course, if the application itself is not "an emacs", that is, if is
not mainly a programming environment in which the application happens
to _be_ developed, there's little need for executable configuration
files. But your application should probably be develoed as "an
emacs"!
Configuration files are (or should be) entirely controled by the user,
the same user who can delete his own files himself already, so you're
gaining nothing preventing him to delete his files from a
configuration file.
--
__Pascal Bourguignon__ http://www.informatimago.com/
HANDLE WITH EXTREME CARE: This product contains minute electrically
charged particles moving at velocities in excess of five hundred
million miles per hour.