GluuFederation / oxTrust

Gluu Server UI for managing authentication, authorization and users.
https://gluu.org/docs/ce
MIT License
134 stars 60 forks source link

Regex validation of attribute leads to Error Page #1434

Closed sahilIT2020 closed 5 years ago

sahilIT2020 commented 5 years ago

Based on this ticket,

Whenever the following Regex is passed in for attribute validation , upon an erroneous string being passed, Identity crashes and we're sent to an error page:

(((?=.*[a-z]+)(?=.*[A-Z]+)(?=.*[`~!@#$%^&*()\-+={}[\x22\x5D\x5F\\|:;',.?/]+))|((?=.*[0-9]+)(?=.*[`~!@#$%^&*()\-+={}[\x22\x5D\x5F\\|:;',.?/]+)(?=.*[a-zA-Z]+)|((?=.*[a-z]+)(?=.*[A-Z]+)(?=.*[0-9]+))))[`~!@#$%^&*()\-+={}[\x22\x5D\x5F\\|:;',.?/a-zA-Z0-9]{8,}

Steps to reproduce -

Go to Oxtrust > attributes, and add the above regular expression to nickname field. Create a user and provide invalid value to nickname, and hit save.

image

oxtrust logs 2018-12-22 00:13:00,186 INFO [qtp985655350-17] [org.gluu.oxtrust.ldap.service.OrganizationService] (OrganizationService.java:233) - Starting App version 3.1.2.Final 2018-12-22 00:28:42,737 ERROR [qtp985655350-13] [org.gluu.oxtrust.exception.GlobalExceptionHandler] (GlobalExceptionHandler.java:54) - java.util.regex.PatternSyntaxException: Unclosed character class near index 252 (((?=.[a-z]+)(?=.[A-Z]+)(?=.[`~!@#$%^&()-+={}[\x22\x5D\x5F\|:;',.?/]+))|((?=.[0-9]+)(?=.[~!@#$%^&*()\-+={}[\x22\x5D\x5F\\|:;',.?/]+)(?=.*[a-zA-Z]+)|((?=.*[a-z]+)(?=.*[A-Z]+)(?=.*[0-9]+))))[~!@#$%^&*()-+={}[\x22\x5D\x5F\|:;',.?/a-zA-Z0-9]{8,}

                                                                                                             ^

javax.faces.FacesException: java.util.regex.PatternSyntaxException: Unclosed character class near index 252 (((?=.[a-z]+)(?=.[A-Z]+)(?=.[`~!@#$%^&()-+={}[\x22\x5D\x5F\|:;',.?/]+))|((?=.[0-9]+)(?=.[~!@#$%^&*()\-+={}[\x22\x5D\x5F\\|:;',.?/]+)(?=.*[a-zA-Z]+)|((?=.*[a-z]+)(?=.*[A-Z]+)(?=.*[0-9]+))))[~!@#$%^&*()-+={}[\x22\x5D\x5F\|:;',.?/a-zA-Z0-9]{8,}

                                                                                                             ^
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:84) ~[jsf-impl-2.2.14.jar:2.2.14]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.14.jar:2.2.14]
syntrydy commented 5 years ago

@sahiliamsso that regular expression isn't correct

sahilIT2020 commented 5 years ago

In that case, a valid error must be thrown instead of generic error page.

syntrydy commented 5 years ago

image