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

JavaScript: false positive with unicode sets for character classes that contain brackets #18854

Open
ryzokuken opened this issue Feb 24, 2025 · 2 comments

Comments

@ryzokuken
Copy link

ryzokuken commented Feb 24, 2025

Description of the false positive

Earlier, a colleague of mine filed #18721 regarding adding support for the v flag. That was implemented but it seems like there's some false positives without properly handling of the set operations.

More specifically, the regex below fails with the ID js/regex/duplicate-in-character-class since it believes [\S--[\[\]]] is a character class that contains brackets ([]) twice.

Code samples or links to source code

const regex = /\b(?:https?:\/\/|mailto:|www\.)(?:[\S--[\p{P}<>]]|\/|[\S--[\[\]]]+[\S--[\p{P}<>]])+|\b[\S--[@\p{Ps}\p{Pe}<>]]+@([\S--[\p{P}<>]]+(?:\.[\S--[\p{P}<>]]+)+)/gmv;

at https://github.com/mozilla/pdf.js/blob/fef706233d6870ddb01ac2131a2ee157262187a4/web/autolinker.js#L101-L101.

URL to the alert on GitHub code scanning (optional)

https://github.com/mozilla/pdf.js/security/code-scanning/1003

@aibaars
Copy link
Contributor

aibaars commented Feb 25, 2025

Thanks for reporting. I suspect the regex parser gets confused by the -- class subtraction operator. I'll pass it on to the team.

@erik-krogh
Copy link
Contributor

Yes, we know, and we're planning to fix it.

Our parser doesn't currently understand the -- operator in regular expressions, which is what cause the issue you observe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants