Question: The filterString() method in this code example normalizes the input string, validates that the input does not contain a tag, and then removes any

The filterString() method in this code example normalizes the input string, validates

The filterString() method in this code example normalizes the input string, validates that the input does not contain a tag, and then removes any noncharacter code points from the input string. Because input validation is performed before the removal of any noncharacter code points, an attacker can include noncharacter code points in the tag to bypass the validation checks. Modify the program to replace all noncharacter code points with Unicode FFFD before validating input. import java.text.Normalizer; import java.text.Normalizer.Form; import java.util.regex.Matcher; import java.util.regex.Pattern; public class TagFilter { public static String filterString (String str) { String s = Normalizer.normalize (str, Form.NFKC); } } // Validate input Pattern pattern Matcher matcher if (matcher.find()) { throw new IllegalArgumentException ("Invalid input"); } } = = Pattern.compile(" "); pattern.matcher(s); // Deletes noncharacter code points S = s.replaceAll("[\\p{Cn}]", ""); return s; public static void main(String[] args) { // "\uFDEF" is a noncharacter code point String maliciousInput = " "; String sb = filterString (maliciousInput); // sb = " " X

Step by Step Solution

3.38 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To replace all noncharacter code points with Unicode FFD before validating input you can m... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!