I would like to allow my web users to execute little perl calculator programs: they could enter into my webform textarea field something like:

sub cubed { return $_[0]**3; } $a=3 ; 25+$a**2 + cubed($a)

when the user hits submit, my server-side cgi script executes this snippet to learn that the user wanted '61'. later, the server will (eventually) return an html page that says "the result of your program {spit back what the user entered above} is 61." I want to predefine a few functions for the user myself, too, such as squared, cubed, etc., but still allow my own users to define their functions, too.

obviously, I do not want my users to inject nasty code, either into the html [I spit back what they entered); or worse, locally escape into my system (via system, backquote, or other nastily crafted entries.

so, I need a safe, sanitized subset version of perl that I can execute. I am probably not the first one in need of this, but I was hoping that someone could point me to where this has been put together already.

I could live with a non-perl syntax for my users, too, as long as it allows them to define their own functions and is reasonably safe. since my cgi server script is in perl, perl-like syntax may be advantageous.

pointers appreciated.


In reply to embedding a safe unescapable mini perl interpreter? by iaw4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.