Example
public class
TaintDemoClass {
private String
input;
public
TaintDemoClass(){
input = getInput();
sensitiveMethod(input);
}
private String
getInput(){
// get input from user...
return
aString;
}
private String
sanitizeInput(
String
s) {
// clean input...
return
cleanString;
}
private void
sensitiveMethod(
String
s) {
// use input...
}
}
Solution
In order to avoid the potentially harmful effects of uncontrolled input in sensitive methods, always send this input through a sanitizing method.
public class
TaintDemoClass {
private
String input;
public
TaintDemoClass() {
input = getInput();
String
cleanInput = sanitizeInput(input);
sensitiveMethod(cleanInput);
}
private void
getInput(){
// get input from user...
return
aString;
}
private String
sanitizeInput(
String
s) {
// clean input...
return
cleanString;
}
private void
sensitiveMethod(
String
aString) {
// use input...
}
}