Anecdotal evidence: I wrote a sort of "miniperl" interpreter that I believed (or lets say hoped) to be secure by transforming and filtering the miniperl into executable perl and using eval to execute it. It operated upon a hierarchical set of hashes and was crippled down to essentially mathematical operations, strings, control structures and calling of functions I allowed or provided.

It was for a local management program for a play-by-mail space opera game, so security was not really necessary, just a bonus so that config files could be exchanged between player and game master without worries

A typical example of what it did:

#bi is population index planet 'Taurus I' : bi+= 200+10*3 : system.scoutdata='Heavily armed' system taurus : code { if ( scoutdata eq '' ) { owned=1 } } translated to: $planet{'taurus i'}{'bi'}+= 200+10*3; $planet{'system'}{'scoutdata'}= 'Heavily armed'; if ($system{'taurus'}{'scoutdata'} eq '') { $system{'taurus'}{'owned'} +=1; }

All the hashes were tied so that the %system-hash of a planet could be reached by simply saying system.something= .... This made it possible to do consitency checks or further actions when a variable was changed. Also if a variable like 'owned' was configured as hierarchical, not only was taurus.owned set to 1 in the example above but also the 'owned' of every planet in this system, i.e. 'taurus i'.owned would have been set too

As you can see I had to exclude most of the special characters from my language, especially all the sigils. Since arrays or hashes couldn't be specified directly, looping was only possible through function calls. No regex was possible

It was fun programming it, but you really have to cripple the language to put perl into a sandbox (and I still can't be completely sure I plugged all holes). While it fitted my needs in this case perfectly, I wouldn't really trust it on a public interface in the web for example

By the way, I used Parse::RecDescent for the parsing of the language (actually it was really two languages that were parsed)


In reply to Re: A minilanguage with the least effort? by jethro
in thread A minilanguage with the least effort? by esk555

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.