Having a function that generates Java code in a textual form (something similar to a template-engine, if you will), how would you sanitize user-provided fields to prevent code injection?
For instances, if I'm using a template similar to:
void function_${user_provided_function_name}() {
// Do stuff
};
And the user provides as input (){System.exit(0);}; void function_dummy
, the generated code would be:
void function_(){System.exit(0);}; void function_dummy() {
// Do stuff
};
Even if I'm tempted just to not allow parenthesis (to prevent function calls), this seems highly fragile.