Note that there are some explanatory texts on larger screens.

plurals
  1. POGroovy/Grails: is there a way to make .evaluate() at all safe?
    primarykey
    data
    text
    <p>I have a situation where I need to determine eligiblity for for one object to "ride" another. The rules for the vehicles are wildly confusing, and I would like to be able to change them without restarting or recompiling my project.</p> <p>This works but basically makes my security friends convulse and speak in tongues:</p> <pre><code>class SweetRider{ String stuff BigDecimal someNumber BigDecimal anotherNumber } class SweetVehicle{ static hasMany=[constraintLinkers:VehicleConstraintLinker] String vehicleName Boolean canIRideIt(SweetRider checkRider){ def checkList = VehicleConstraintLinker.findAllByVehicle(this) checkList.each{ def theClosureObject = it.closureConstraint def iThinkINeedAShell = new GroovyShell() def checkerThing = iThinkINeedAShell.evaluate(theClosureObject.closureText) def result = checkerThing(checkRider) return result } } } class VehicleConstraintLinker{ static belongsTo = [closureConstraint:ConstraintByClosure, vehicle:SweetVehicle] } class ConstraintByClosure{ String humanReadable String closureText static hasMany = [vehicleLinkers:VehicleConstraintLinker] } </code></pre> <p>So if I want to add the rule that you are only eligible for a certain vehicle if your "stuff" is "peggy" or "waffles" and your someNumber is greater than your anotherNumber all I have to do is this:</p> <p>Make a new ConstraintByClosure with humanReadable = "peggy waffle some#>" (thats the human readable explanation) and then add this string as the closureText</p> <pre><code>{ checkRider-&gt;if( ["peggy","waffles"].contains(checkRider.stuff) &amp;&amp; checkRider.someNumber &gt; checkRider.anotherNumber ) { return true } else { return false } } </code></pre> <p>Then I just make a VehicleConstraintLinker to link it up and voila.</p> <p>My question is this: Is there any way to restrict what the GroovyShell can do? Can I make it unable to change any files, globals or database data? Is this sufficient?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload