alex-ninja commented on a change in pull request #1043:
URL: https://github.com/apache/cassandra/pull/1043#discussion_r648999196



##########
File path: src/java/org/apache/cassandra/cql3/PasswordObfuscator.java
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.cql3;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Obfuscates passwords in a given string
+ */
+class PasswordObfuscator implements IObfuscator
+{
+    private static final String OBFUSCATION_TOKEN = "*******";
+    private static final String PASSWORD_TOKEN = "password";
+
+    private static final int PATTERN_FLAGS = Pattern.CASE_INSENSITIVE | 
Pattern.DOTALL;
+    private static final Pattern PASSWORD_PATTERN = 
Pattern.compile(".*password\\s*=?\\s*'(?<password>[^\\s]+)'.*",

Review comment:
       As far as I understand, you assume passwords to not have whitespace 
characters, right? Even though it is highly unlikely to have a whitespace 
character in the password, it is currently allowed (tested manually on version 
3.11.10):
   ```
   # create a user with a password that contains spaces
   $ ./bin/cqlsh -u cassandra -p cassandra
   cassandra@cqlsh> CREATE ROLE alice WITH PASSWORD = 'PASSWORD WITH SPACES' 
AND SUPERUSER = true AND LOGIN = true;
   cassandra@cqlsh> exit
   
   # login using such a password
   $ ./bin/cqlsh -u alice -p "PASSWORD WITH SPACES"
   cassandra@cqlsh> exit
   ```
   I have not found any documentation that clearly explains what characters are 
allowed in passwords. My current assumption is that all characters are allowed 
(including control and whitespace characters). I doubt that someone really uses 
control characters, but whitespace character seems to be possible. I'd consider 
the following pattern `(?<password>.*)`  - everything including whitespace 
characters and the empty password (see below).
   
   It turned out that empty password is also allowed to set:
   ```
   # create a user with empty password
   $ ./bin/cqlsh -u cassandra -p cassandra
   cassandra@cqlsh> CREATE ROLE bob WITH PASSWORD = '' AND SUPERUSER = true AND 
LOGIN = true;
   ```
   Despite I was unable to login through `cqlsh`:
   ```
   $ ./bin/cqlsh -u bob -p ""
   Password: Traceback (most recent call last):
     File "/home/azotov/opt/apache-cassandra-3.11.10/bin/cqlsh.py", line 2458, 
in <module>
       main(*read_options(sys.argv[1:], os.environ))
     File "/home/azotov/opt/apache-cassandra-3.11.10/bin/cqlsh.py", line 2436, 
in main
       encoding=options.encoding)
     File "/home/azotov/opt/apache-cassandra-3.11.10/bin/cqlsh.py", line 466, 
in __init__
       password = getpass.getpass()
     File "/usr/lib/python2.7/getpass.py", line 71, in unix_getpass
       passwd = _raw_input(prompt, stream, input=input)
     File "/usr/lib/python2.7/getpass.py", line 135, in _raw_input
       raise EOFError
   EOFError
   ```
   I feel it is related to the logic in Python wrapper rather than to a 
protocol limit. So I bet I'd be able to login using a Java client. Assuming it 
is possible to set and login with the empty password, we also need to obfuscate 
it.
   
   Both use cases seem to be corner cases (pretty rare and weird), but I 
believe we need to handle them properly. Please, let me know your thoughts.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to