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

New Rule: disallow unicode confusable identifiers #117

Open
1 task
mhofman opened this issue Mar 1, 2023 · 4 comments
Open
1 task

New Rule: disallow unicode confusable identifiers #117

mhofman opened this issue Mar 1, 2023 · 4 comments

Comments

@mhofman
Copy link

mhofman commented Mar 1, 2023

Rule details

Compute the Unicode skeleton of declared identifiers and disallow if similar to an identifier already in scope

Related CVE

CVE-2021-42694

Example code

const loremIpsum = "latin only";
const lоrеmIрsum = "with Cyrillic ";
const lorem‍Ipsum = "with ZWJ";

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

The Zero-Width Joiner (\u200d) is a valid identifier character, even though some parsers like the ones used by typescript or Webpack fail to parse correctly.

Cyrillic characters in the example code is one case of confusable unicode character with latin character, but there are a lot of other possibilities, including confusion between non-latin characters. Unicode defines an algorithm to compute the skeleton of text, which we could apply to identifiers, and base the comparison on the skeleton instead of the identifier string.

First reported in eslint/eslint#15240 (comment)

@mhofman
Copy link
Author

mhofman commented Mar 1, 2023

Related to #116

@nzakas
Copy link
Contributor

nzakas commented Mar 1, 2023

When you say the zero-width joiner is causing a parsing error, where do you see that?

@mhofman
Copy link
Author

mhofman commented Mar 1, 2023

Oh my bad, it's because I'm using typescript-eslint, and tsc is choking on ZWJ!

@nzakas
Copy link
Contributor

nzakas commented Mar 1, 2023

Ah okay, good to know! I was confused because the default parser was working okay. 👍

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

No branches or pull requests

2 participants