Skip to content

Commit

Permalink
preventing usage of bean and message fields in script
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jun 23, 2015
1 parent 2b2c008 commit b4f949f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.zomis.duga.chat.WebhookParameters
*/
abstract class ChatCommandDelegate extends Script {

// DO NOT RENAME THESE FIELDS. Their names are denied through hardcoding
private ChatMessageIncoming message
private DugaChatListener bean

Expand Down
13 changes: 13 additions & 0 deletions src/main/groovy/net/zomis/duga/tasks/ListenTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import net.zomis.duga.ChatCommands
import net.zomis.duga.DugaBot
import net.zomis.duga.DugaChatListener
import net.zomis.duga.chat.WebhookParameters
import org.codehaus.groovy.ast.expr.Expression
import org.codehaus.groovy.ast.expr.VariableExpression
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
import org.codehaus.groovy.control.customizers.SecureASTCustomizer
Expand Down Expand Up @@ -89,6 +91,17 @@ class ListenTask implements Runnable {
BigDecimal
].asImmutable()
}
scz.addExpressionCheckers(new SecureASTCustomizer.ExpressionChecker() {
@Override
boolean isAuthorized(Expression expression) {
if (expression instanceof VariableExpression) {
VariableExpression expr = (VariableExpression) expression
return expr.name != 'bean' && expr.name != 'message'
}
return true
}
})

cc.addCompilationCustomizers(scz)
def compileStaticCustomizer = new ASTTransformationCustomizer(Collections.singletonMap('extensions',
Collections.singletonList('typecheck-extension.groovy')), CompileStatic.class)
Expand Down

0 comments on commit b4f949f

Please sign in to comment.