CQI-83: added new way of regex working to satisfy security requirements #77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TICKET: https://openimis.atlassian.net/browse/CQI-83
EXPLANATION: The Sonar issue is raised because the regular expression used in our code can lead to denial of service due to its vulnerability to super-linear runtime caused by backtracking. This is a security concern as it might make your application vulnerable to attacks that exploit this regex's inefficiency.
To fix this issue, we modified the regular expression to make it more efficient and less prone to backtracking. One way to do this is by using a non-capturing group to make the expression more deterministic.
The modified regular expression (?:[^\s@]+@[^\s@]+.[^\s@]+) should work in the same intended way as the previous one, while addressing the security issue. It maintains the same email address validation pattern and functionality while making the regular expression more efficient and less prone to super-linear runtime caused by backtracking.