Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape username for regex #296

Merged
merged 4 commits into from
Mar 12, 2022
Merged

Conversation

DominikSerafin
Copy link
Contributor

@DominikSerafin DominikSerafin commented Jan 10, 2020

Currently when the usernameCaseInsensitive option is enabled then username is queried using regex constructed from unescaped username value.

This is a bit problematic because username can often contain special characters - e.g. it can be [email protected] email address.

When we construct regex from that value then it will treat plus sign as a regex quantifier rather than character match. Here's how it fails:

const username = '[email protected]';
new RegExp(`^${username}$`, 'i').test(username) // = false

And this leads to inability to authenticate using that email address after it was used for registration. It can also potentially lead to some security/stability vulnerabilities, like e.g. ReDoS.

My solution here is to escape regex token characters in username before that value gets put into RegExp constructor.

@coveralls
Copy link

coveralls commented Jan 10, 2020

Coverage Status

Coverage decreased (-0.4%) to 97.685% when pulling e20d3fc on DominikSerafin:patch-1 into 7992af4 on saintedlama:master.

@dannymout
Copy link

What's the status on this?

@saintedlama saintedlama merged commit 6713c4e into saintedlama:main Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants