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

[lint] Remove no-control-regex #1258

Merged
merged 4 commits into from
Sep 8, 2022
Merged

Conversation

dayo09
Copy link
Contributor

@dayo09 dayo09 commented Sep 6, 2022

This commit enables 'no-control-regex' rule
and removes the errors accordingly.

ONE-vscode-DCO-1.0-Signed-off-by: dayo09 [email protected]


For #1253

Remove no-control-regex

Reference

https://stackoverflow.com/questions/14313183/javascript-regex-how-do-i-check-if-the-string-is-ascii-only

Problematic lines

// NOTE ASCII characters have codes ranging from u+0000 to u+007f
function containsNonAscii(str: string): boolean {
  return !/^[\u0000-\u007f]*$/.test(str);
}

The line is required to check if it's an ascii, but how about checking 'printable ascii' aside from those problematic non-printables?

@dayo09 dayo09 requested a review from jyoungyun September 6, 2022 05:06
@dayo09
Copy link
Contributor Author

dayo09 commented Sep 6, 2022

I think that \n, \r and \t characters are in non-printable ascii and the tests includes them. I guess any password cannot contain them, so we may be able to remove those characters from the tests.

@@ -24,6 +24,7 @@
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off",
"no-control-regex": "warn",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this above 'no-extra-semi' to avoid possible merge conflict


const strWithSpecialChar = '\n\t\r!@#$%^&*(){}[]\\';
assert.isNotTrue(containsNonAscii(strWithSpecialChar));
const strWithSpecialChar = '!@#$%^&*(){}[]\\';
Copy link
Contributor Author

@dayo09 dayo09 Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed \n\t\r from the test.

Reasoning:

(1) \r \n

They are CR, LR keys which are 'new line' characters based on each os.

CR(\r), LF(\n)](https://m.blog.naver.com/taeil34/221325864981)

When I hit the 'enter' key, the password quick pick returns, so they are not expected to be included in passwords.

(2) \t

When I hit the 'tab' key, the password quick pick disappears, so it is not expected to be included in passwords.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any possibility that the key value will be entered through copy and paste?

Copy link
Contributor Author

@dayo09 dayo09 Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh.. sure. I tried a random password with tab(0x09, control) and space(0x20, printable), and it distinguished those two characters, allowing login by only copy&paste.

Copy link
Contributor Author

@dayo09 dayo09 Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(For lint's sake) Allowiing \t \n by the rule

It seems \t \n are allows by the eslint's rule even though they are control characters.

https://eslint.org/docs/latest/rules/no-control-regex

The following elements of regular expression patterns are considered possible errors in typing and are therefore disallowed by this rule:

Hexadecimal character escapes from \x00 to \x1F.
Unicode character escapes from \u0000 to \u001F.
Unicode code point escapes from \u{0} to \u{1F}.
Unescaped raw characters from U+0000 to U+001F.
Control escapes such as \t and \n are allowed by this rule.

(For security's sake) More to consider

It seems 0x7f is a special character(delete) too.

https://www.geeksforgeeks.org/control-characters/

Copy link
Contributor Author

@dayo09 dayo09 Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So let me add \n, \r and \t to the regex and see if they are allowed. The other control characters look not good to allow from security's view, IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with ascii 0x1,0x2 and even 0x18(Cancel) and linux os still accept all those control ascii characters.

0x1 Start of Heading
0x2  Start of Text
0x18 Cancel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with 0xff(latin y) 0x80(euro sign), which are extended ascii. They are accepted as a linux passwd but I couldn't login to vscode remote with those passwords

function containsNonAscii(str: string): boolean {
return !/^[\u0000-\u007f]*$/.test(str);
// NOTE Printable ASCII characters have codes ranging from u+0000 to u+007f
function containsOnlyPrintableAscii(str: string): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From clean code's view,
I changed negation from the function to avoid 'double negation'

https://refactoring.com/catalog/removeDoubleNegative.html

@dayo09 dayo09 marked this pull request as ready for review September 6, 2022 05:24
@dayo09 dayo09 added the 2 approvals 2 approvals required to be merged label Sep 6, 2022
@dayo09 dayo09 requested a review from a team September 6, 2022 05:24
src/View/PasswordQuickInput.ts Outdated Show resolved Hide resolved
This commit enables 'no-control-regex' rule
and removes the errors accordingly.

ONE-vscode-DCO-1.0-Signed-off-by: dayo09 <[email protected]>
ONE-vscode-DCO-1.0-Signed-off-by: dayo09 <[email protected]>
Comment on lines 19 to 30
// NOTE
//
// u+0000-u+001f: control ascii codes, ascii (ALLOWED)
// u+0020-u+007f: printable ascii codes, ascii (ALLOWED)
// u+0080-u+00ff: extended ascii codes, extended ascii (NOT ALLOWED)
//
// By experience, Linux os takes all extended ascii characters(u+0000-u+00ff) for passwords, even
// controll asciis. whereas 'eslint' recommends not using regex including control ascii codes.
// Therefore, we allow users to put control ascii codes.
//
// By experience, the passwords including extended ascii characters are not working when loging in
// to remote vscode. Therefore, here we allow only 'ascii characters'(0x00-0x7f).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyoungyun I tried several tests under what you've mentioned, I summarized here what I've found out. It seems that leaving the codes as-is is enough for now. PTAL :-D

src/View/PasswordQuickInput.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@jyoungyun jyoungyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thank you!

@dayo09 dayo09 requested a review from a team September 8, 2022 04:38
@dayo09
Copy link
Contributor Author

dayo09 commented Sep 8, 2022

@Samsung/one-vscode_committers it's ready. PTAL :-D

@llFreetimell llFreetimell merged commit 5fd09de into Samsung:main Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 approvals 2 approvals required to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants