Blacklist filter Bypass Feeling

Source: Internet
Author: User

Today, we find a problem that bypasses regular filtering, and many applications use regular expressions to authenticate input data, for example, when modifying a device name:

String regex = "^.*[\\\\/:\\*\\?\" <>\\| ' %&]+.*$ "; 1 or more "\:*?" appears <>| ' %& "character means illegal

Pattern pattern = pattern. Compile (regex);

Matcher Matcher = Pattern.matcher (str);

But we found that when the input carriage return (\ r \ n) The validation of the regular expression can be bypassed (followed by security problems), such as the input "abc\r\n<>" is not detected, because '. ' default is mismatch like ' \ r ', ' \ n ', etc. If you want to match then use options pattern.dotall, so write:

Pattern pattern = pattern. Compile (regex, Pattern.dotall);

However, no one can guarantee that this writing will not be able to continue to bypass the situation, so the essence of this problem is not the wrong way to use the method, but not the use of white list filter, that is, only allow the specified character pass, the other is not allowed, the following is owasp Esapi the White list filter rules for file names and directory names for your reference:

Validator.filename=^[[email protected]#$%^&{}\\[\\] () _+\\-=,.~ "]{1,255}$//[" characters are allowed to appear in white list characters, length 1-255, Any other characters are illegal.

Validator.directoryname=^[a-za-z0-9:/\\\\[email protected]#$%^&{}\\[\\] () _+\\-=,.~ "]{1,255}$

Similarly, we can also set a list of similar characters for various user input such as device name, so we strongly recommend that we use the Fu Bai to do data security verification.

Blacklist filter Bypass Feeling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.