Since the last update for the MLDash artifact, upgrades have been made to improve security. A security class was created in the security.py file, with member functions capable of encoding and decoding the arguments used to initialize a security object. The original code stored the MongoDB username and password by assigning cleartext string constants to variables, which were then used to create a MongoDB CRUD (create, read, update, delete) capable object that connected to the database using fixed credentials. This meant that database setup (using Mongo Shell) required the creation of an authorized user that was limited to a single possible username and password. Now, there is no need to expose the credentials in the source code, and database setup can use any username and password combination.
The MLDash interface has been modified to present the user with a login screen, which must be successfully authenticated to before the main content is revealed. A user enters their MongoDB username and password, and presses the “Login” button. The credentials are passed to a security object instance, which XORs the credentials with a randomly generated binary key which is truncated to the respective lengths of binary conversion of the username and password, and returns the encoded credentials in hexadecimal form. The encoded credentials and security object are then used as arguments in the creation of a new MongoDB CRUD-capable object. The MLMongo class, defined in the crud.py file, uses the security object to decode the encoded credentials and use them in the connection string for MongoDB. Only if authentication is successful does the login screen display the dashboard content. This security solution prevents unauthorized use of the dashboard, allows customization of username and password during database setup, prevents any cleartext record of the credentials in the code itself, and performs encoding and decoding of credentials with a unique randomly generated variable-length XOR key that does not persist beyond a single login session. While the encoding algorithm itself may be upgraded in the future to a more secure algorithm such as AES-256, this use of a one-time key greatly enhances XOR security and makes brute force attacks on the authentication system far less likely to succeed.
Additional documentation for the database setup was added to the README.txt file. User setup involves creating an admin user which can then set the regular user’s role to Read/Write (only) to prevent unauthorized access to other databases or rights management; the admin user also specifies the database authentication mechanism to apply SCRAM-SHA-256 to the regular user’s authentication process (also represented in the MLMongo class database connection string). In order to implement authentication-dependent dashboard content, the app.layout value assignment was changed to the value of a function containing the login screen interface code. The main content was encapsulated in another function, which is executed within a callback function connected to the “Login” button (if and only if authentication is successful).
Attempts were made to upgrade the project to use Python 3.11.x, but the particularities of the changed dependency tree forced me to table the upgrade for a later date. When testing MLDash with maximally upgraded dependencies, an unknown issue caused the Jupyter Notebook kernel to die at unpredictable times. Considering that upgrading from Python 3.7 to 3.11 caused MLDash to run almost twice as fast, this upgrade will definitely be revisited in the future.