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

Auth rework #953

Open
wants to merge 112 commits into
base: dev
Choose a base branch
from
Open

Auth rework #953

wants to merge 112 commits into from

Conversation

FancMa01
Copy link
Collaborator

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Vulnerability fix (package bumps or CodeQL adjustments to ensure code security)
  • This change requires a documentation update

Developer Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved any conflicts with the branch I am attempting to merge to.
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings
  • I have ensured that my code does not unecessarily duplicate existing cod
  • I have ensured that all security checks have been passed
  • All input boxes have sensible character limits applied
  • Refreshing related pages puts page in a workable and sensible state

Reviewer Checklist

  • I have pulled the branch into my local environemtn and started the project succesfully
  • I have reviewed the code for proper comments and mispellings
  • All input boxes have sensible character limits applied
  • Refreshing related pages puts page in a workable and sensible state
  • Submitting any relevant Forms relays proper messaging to user
  • I have checked that all security checks have been passed
  • I have checked that all backend routes have proper validation

ydahal1 and others added 30 commits September 16, 2024 16:51
* Remove existing manual login/logout code for fresh start

* save progress

* introduce new login

introduce login/register, basic layout component.

Able to be accessed by /login and /register respectively.

Will need to rework login and load order and such later

* Max characters applied

* update look and feel

* Further css adjustments

* give new-password so autocomplete doesn't happen

* added autoComplete off in login page aswell

---------

Co-authored-by: yadhap Dahal <yadhap.dahal@lexisnexisrisk.com>
…tiy functions. Modified RoleTypes, UserRoles model, added migration file and model for refresh_token
Added registration and login routes, middlewares, controlles and util…
* Remove existing manual login/logout code for fresh start

* save progress

* introduce new login

introduce login/register, basic layout component.

Able to be accessed by /login and /register respectively.

Will need to rework login and load order and such later

* Max characters applied

* update look and feel

* Further css adjustments

* give new-password so autocomplete doesn't happen

* added autoComplete off in login page aswell

* add forgot password, password complexity validator, reset password

---------

Co-authored-by: yadhap Dahal <yadhap.dahal@lexisnexisrisk.com>
* Remove existing manual login/logout code for fresh start

* save progress

* introduce new login

introduce login/register, basic layout component.

Able to be accessed by /login and /register respectively.

Will need to rework login and load order and such later

* Max characters applied

* update look and feel

* Further css adjustments

* give new-password so autocomplete doesn't happen

* added autoComplete off in login page aswell

* add forgot password, password complexity validator, reset password

* remove i18n and language switcher

* adjust footer

* add comment

* home css and structure adjustments

* rename css class

---------

Co-authored-by: yadhap Dahal <yadhap.dahal@lexisnexisrisk.com>
…ock data with a dedicated test database for more accurate unit tests. Implemented end-to-end route tests for authentication and user routes.
Refactored testing environment to mirror production setup.
* create my account page

* Adjust look and feel

Change password replaces logout in top left, one form for displaying and editing information.
* create my account page

* Initial Framework

Still need to add Modals and functionality, but waiting on wiring basic flow first so we can have real data to test with.

* save
additional auth routes and session mgmt routes
ydahal1 and others added 29 commits October 23, 2024 08:59
…password and new password, added utility function that makes call to the server to update the password, added the new component to the browser router
…function to use the new getAUser utility function
…registration-flow

Yadhap/add verification to registration flow
…ner-admin-created-users

Yadhap/password rest for owner admin created users
…not throw error if these items are undefined
* bug fixes for application creation/deletion/switching for left nav and application screens

* remove console logs

* remove unused functions from application screen

* Save Progress

* fixes

* Update Backend.js

* Fix Header for stability

* save progress

* Update to control reader disabled

* Update to allow user to logout no matter what

* Allow user to update their own account and create allowed resource list
…gistered-user

Yadhap/verify email self registered user
* bug fixes for application creation/deletion/switching for left nav and application screens

* remove console logs

* remove unused functions from application screen

* Save Progress

* fixes

* Update Backend.js

* Fix Header for stability

* save progress

* Update to control reader disabled

* Update to allow user to logout no matter what

* Allow user to update their own account and create allowed resource list

* Handle login invalid values

* 403 fallback page

* save

* fix spelling error

* fix spelling

* Patch to not show owner/admin no route access and also fix authController to return user roles and applications on verify email login

* Add more conditionals
* Model and Migration

* Routes, Controllers, Middleware for instance settings
* bug fixes for application creation/deletion/switching for left nav and application screens

* remove console logs

* remove unused functions from application screen

* Save Progress

* fixes

* Update Backend.js

* Fix Header for stability

* save progress

* Update to control reader disabled

* Update to allow user to logout no matter what

* Allow user to update their own account and create allowed resource list

* Handle login invalid values

* 403 fallback page

* save

* save

* Model and Migration

* Routes, Controllers, Middleware for instance settings

* save

* save progresss

* save

* finish

* Update error message

* Changed Steps on Start up Wizard to horizontal

---------

Co-authored-by: yadhap Dahal <yadhap.dahal@lexisnexisrisk.com>
* bug fixes for application creation/deletion/switching for left nav and application screens

* remove console logs

* remove unused functions from application screen

* Save Progress

* fixes

* Update Backend.js

* Fix Header for stability

* save progress

* Update to control reader disabled

* Update to allow user to logout no matter what

* Allow user to update their own account and create allowed resource list

* Handle login invalid values

* 403 fallback page

* save

* save

* Model and Migration

* Routes, Controllers, Middleware for instance settings

* save

* save progresss

* save

* finish

* request access route

* Only Owners or Admins should see tours

* Finish notification

* remove extra  /
…es in front end so the front end gets right kind of code from Azure before sending to backend
Added login/register with azure option in the back end and made chang…
* Oauth2 front end

* wire front and backend azure login

* Show/hide traditional

* small bug fix to prevent multiple logins from being fired

* Fixed login loop that occured when MS login failed. Also fixed issue where the roles and applications for newly created azure user was coming back undefined

---------

Co-authored-by: yadhap Dahal <yadhap.dahal@lexisnexisrisk.com>
* Remove unused packages

* Bug Fixes for left nav, constraints, and consumers
* Remove unused packages

* Bug Fixes for left nav, constraints, and consumers

* updates

* Users Page and various docs updates

* adjustments
* Fix user registration to not show success unless error message is shown and remove duplicate create basic user route

* Set width of all components to 40rem for login for consistency

* hide change password method for microsoft accounts
//add application to user object in local storage so user has immediate access to it
const { user_app_id, id, title, description } = responseData;
user.applications.push({ id: user_app_id, application: { id, title, description } });
await localStorage.setItem('user', JSON.stringify(user));

Check failure

Code scanning / CodeQL

Clear text storage of sensitive information High

This stores sensitive data returned by
a call to resetTempPassword
as clear text.
//remove it from users applications
const user = JSON.parse(localStorage.getItem('user'));
user.applications = user.applications.filter((app) => app.application.id !== app_id);
localStorage.setItem('user', JSON.stringify(user));

Check failure

Code scanning / CodeQL

Clear text storage of sensitive information High

This stores sensitive data returned by
a call to resetTempPassword
as clear text.

Copilot Autofix AI about 14 hours ago

To fix the problem, we need to ensure that any sensitive information stored in local storage is encrypted. We can use the crypto-js library to encrypt and decrypt the data. The encryption key should be securely managed and not hardcoded in the code.

  1. Install the crypto-js library.
  2. Import the necessary functions from crypto-js.
  3. Encrypt the user object before storing it in local storage.
  4. Decrypt the user object when retrieving it from local storage.
Suggested changeset 3
Tombolo/client-reactjs/src/components/admin/apps/Applications.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tombolo/client-reactjs/src/components/admin/apps/Applications.js b/Tombolo/client-reactjs/src/components/admin/apps/Applications.js
--- a/Tombolo/client-reactjs/src/components/admin/apps/Applications.js
+++ b/Tombolo/client-reactjs/src/components/admin/apps/Applications.js
@@ -9,3 +9,3 @@
 import AddApplication from './AddApplication';
-
+import CryptoJS from 'crypto-js';
 import Text from '../../common/Text';
@@ -74,5 +74,5 @@
         //remove it from users applications
-        const user = JSON.parse(localStorage.getItem('user'));
+        const user = JSON.parse(CryptoJS.AES.decrypt(localStorage.getItem('user'), 'encryption_key').toString(CryptoJS.enc.Utf8));
         user.applications = user.applications.filter((app) => app.application.id !== app_id);
-        localStorage.setItem('user', JSON.stringify(user));
+        localStorage.setItem('user', CryptoJS.AES.encrypt(JSON.stringify(user), 'encryption_key').toString());
 
EOF
@@ -9,3 +9,3 @@
import AddApplication from './AddApplication';

import CryptoJS from 'crypto-js';
import Text from '../../common/Text';
@@ -74,5 +74,5 @@
//remove it from users applications
const user = JSON.parse(localStorage.getItem('user'));
const user = JSON.parse(CryptoJS.AES.decrypt(localStorage.getItem('user'), 'encryption_key').toString(CryptoJS.enc.Utf8));
user.applications = user.applications.filter((app) => app.application.id !== app_id);
localStorage.setItem('user', JSON.stringify(user));
localStorage.setItem('user', CryptoJS.AES.encrypt(JSON.stringify(user), 'encryption_key').toString());

Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx b/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
--- a/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
+++ b/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
@@ -4,3 +4,3 @@
 import passwordComplexityValidator from '../common/passwordComplexityValidator';
-
+import CryptoJS from 'crypto-js';
 function ResetTempPassword() {
@@ -38,3 +38,3 @@
       // Save user token to local storage
-      localStorage.setItem('user', JSON.stringify(result.data));
+      localStorage.setItem('user', CryptoJS.AES.encrypt(JSON.stringify(result.data), 'encryption_key').toString());
       window.location.href = '/';
EOF
@@ -4,3 +4,3 @@
import passwordComplexityValidator from '../common/passwordComplexityValidator';

import CryptoJS from 'crypto-js';
function ResetTempPassword() {
@@ -38,3 +38,3 @@
// Save user token to local storage
localStorage.setItem('user', JSON.stringify(result.data));
localStorage.setItem('user', CryptoJS.AES.encrypt(JSON.stringify(result.data), 'encryption_key').toString());
window.location.href = '/';
Tombolo/client-reactjs/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tombolo/client-reactjs/package.json b/Tombolo/client-reactjs/package.json
--- a/Tombolo/client-reactjs/package.json
+++ b/Tombolo/client-reactjs/package.json
@@ -30,3 +30,4 @@
     "socket.io-client": "^4.1.3",
-    "validator": "^13.11.0"
+    "validator": "^13.11.0",
+    "crypto-js": "^4.2.0"
   },
EOF
@@ -30,3 +30,4 @@
"socket.io-client": "^4.1.3",
"validator": "^13.11.0"
"validator": "^13.11.0",
"crypto-js": "^4.2.0"
},
This fix introduces these dependencies
Package Version Security advisories
crypto-js (npm) 4.2.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
const oldUser = JSON.parse(localStorage.getItem('user'));
const newUser = { ...oldUser, firstName: response.data.firstName, lastName: response.data.lastName };

localStorage.setItem('user', JSON.stringify(newUser));

Check failure

Code scanning / CodeQL

Clear text storage of sensitive information High

This stores sensitive data returned by
a call to resetTempPassword
as clear text.

Copilot Autofix AI about 14 hours ago

To fix the problem, we need to ensure that any sensitive information stored in localStorage is encrypted. We can use the crypto-js library to encrypt and decrypt the data before storing and retrieving it from localStorage.

  1. Install the crypto-js library.
  2. Import the necessary functions from crypto-js.
  3. Encrypt the user data before storing it in localStorage.
  4. Decrypt the user data when retrieving it from localStorage.
Suggested changeset 3
Tombolo/client-reactjs/src/components/application/myAccount/myAccountInfo.jsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tombolo/client-reactjs/src/components/application/myAccount/myAccountInfo.jsx b/Tombolo/client-reactjs/src/components/application/myAccount/myAccountInfo.jsx
--- a/Tombolo/client-reactjs/src/components/application/myAccount/myAccountInfo.jsx
+++ b/Tombolo/client-reactjs/src/components/application/myAccount/myAccountInfo.jsx
@@ -1,2 +1,3 @@
 import React, { useState, useEffect } from 'react';
+import CryptoJS from 'crypto-js';
 import { Card, Form, Row, Col, Input, Button, Spin, message } from 'antd';
@@ -44,6 +45,8 @@
 
-          const oldUser = JSON.parse(localStorage.getItem('user'));
+          const encryptedOldUser = localStorage.getItem('user');
+          const oldUser = encryptedOldUser ? JSON.parse(CryptoJS.AES.decrypt(encryptedOldUser, 'secret-key').toString(CryptoJS.enc.Utf8)) : {};
           const newUser = { ...oldUser, firstName: response.data.firstName, lastName: response.data.lastName };
 
-          localStorage.setItem('user', JSON.stringify(newUser));
+          const encryptedNewUser = CryptoJS.AES.encrypt(JSON.stringify(newUser), 'secret-key').toString();
+          localStorage.setItem('user', encryptedNewUser);
           window.dispatchEvent(new Event('userStorage'));
EOF
@@ -1,2 +1,3 @@
import React, { useState, useEffect } from 'react';
import CryptoJS from 'crypto-js';
import { Card, Form, Row, Col, Input, Button, Spin, message } from 'antd';
@@ -44,6 +45,8 @@

const oldUser = JSON.parse(localStorage.getItem('user'));
const encryptedOldUser = localStorage.getItem('user');
const oldUser = encryptedOldUser ? JSON.parse(CryptoJS.AES.decrypt(encryptedOldUser, 'secret-key').toString(CryptoJS.enc.Utf8)) : {};
const newUser = { ...oldUser, firstName: response.data.firstName, lastName: response.data.lastName };

localStorage.setItem('user', JSON.stringify(newUser));
const encryptedNewUser = CryptoJS.AES.encrypt(JSON.stringify(newUser), 'secret-key').toString();
localStorage.setItem('user', encryptedNewUser);
window.dispatchEvent(new Event('userStorage'));
Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx b/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
--- a/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
+++ b/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
@@ -1,2 +1,3 @@
 import React, { useState, useEffect } from 'react';
+import CryptoJS from 'crypto-js';
 import { Form, Input, Button, Spin, message, Popover } from 'antd';
@@ -38,3 +39,4 @@
       // Save user token to local storage
-      localStorage.setItem('user', JSON.stringify(result.data));
+      const encryptedUser = CryptoJS.AES.encrypt(JSON.stringify(result.data), 'secret-key').toString();
+      localStorage.setItem('user', encryptedUser);
       window.location.href = '/';
EOF
@@ -1,2 +1,3 @@
import React, { useState, useEffect } from 'react';
import CryptoJS from 'crypto-js';
import { Form, Input, Button, Spin, message, Popover } from 'antd';
@@ -38,3 +39,4 @@
// Save user token to local storage
localStorage.setItem('user', JSON.stringify(result.data));
const encryptedUser = CryptoJS.AES.encrypt(JSON.stringify(result.data), 'secret-key').toString();
localStorage.setItem('user', encryptedUser);
window.location.href = '/';
Tombolo/client-reactjs/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tombolo/client-reactjs/package.json b/Tombolo/client-reactjs/package.json
--- a/Tombolo/client-reactjs/package.json
+++ b/Tombolo/client-reactjs/package.json
@@ -30,3 +30,4 @@
     "socket.io-client": "^4.1.3",
-    "validator": "^13.11.0"
+    "validator": "^13.11.0",
+    "crypto-js": "^4.2.0"
   },
EOF
@@ -30,3 +30,4 @@
"socket.io-client": "^4.1.3",
"validator": "^13.11.0"
"validator": "^13.11.0",
"crypto-js": "^4.2.0"
},
This fix introduces these dependencies
Package Version Security advisories
crypto-js (npm) 4.2.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
if (!user) return;
if (user?.token !== token) {
user.token = token;
await localStorage.setItem('user', JSON.stringify(user));

Check failure

Code scanning / CodeQL

Clear text storage of sensitive information High

This stores sensitive data returned by
a call to resetTempPassword
as clear text.

Copilot Autofix AI about 14 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

const result = await resetTempPassword(values);

// Save user token to local storage
localStorage.setItem('user', JSON.stringify(result.data));

Check failure

Code scanning / CodeQL

Clear text storage of sensitive information High

This stores sensitive data returned by
a call to resetTempPassword
as clear text.

Copilot Autofix AI about 14 hours ago

To fix the problem, we need to ensure that any sensitive information stored in local storage is encrypted. We can use the crypto-js library to encrypt the data before storing it and decrypt it when needed. This will protect the data from being easily accessed in plain text.

  1. Install the crypto-js library.
  2. Import the necessary functions from crypto-js.
  3. Encrypt the data before storing it in local storage.
  4. Decrypt the data when retrieving it from local storage.
Suggested changeset 2
Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx b/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
--- a/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
+++ b/Tombolo/client-reactjs/src/components/login/ResetTempPw.jsx
@@ -4,2 +4,3 @@
 import passwordComplexityValidator from '../common/passwordComplexityValidator';
+import CryptoJS from 'crypto-js';
 
@@ -38,3 +39,4 @@
       // Save user token to local storage
-      localStorage.setItem('user', JSON.stringify(result.data));
+      const encryptedData = CryptoJS.AES.encrypt(JSON.stringify(result.data), 'secret-key').toString();
+      localStorage.setItem('user', encryptedData);
       window.location.href = '/';
EOF
@@ -4,2 +4,3 @@
import passwordComplexityValidator from '../common/passwordComplexityValidator';
import CryptoJS from 'crypto-js';

@@ -38,3 +39,4 @@
// Save user token to local storage
localStorage.setItem('user', JSON.stringify(result.data));
const encryptedData = CryptoJS.AES.encrypt(JSON.stringify(result.data), 'secret-key').toString();
localStorage.setItem('user', encryptedData);
window.location.href = '/';
Tombolo/client-reactjs/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Tombolo/client-reactjs/package.json b/Tombolo/client-reactjs/package.json
--- a/Tombolo/client-reactjs/package.json
+++ b/Tombolo/client-reactjs/package.json
@@ -30,3 +30,4 @@
     "socket.io-client": "^4.1.3",
-    "validator": "^13.11.0"
+    "validator": "^13.11.0",
+    "crypto-js": "^4.2.0"
   },
EOF
@@ -30,3 +30,4 @@
"socket.io-client": "^4.1.3",
"validator": "^13.11.0"
"validator": "^13.11.0",
"crypto-js": "^4.2.0"
},
This fix introduces these dependencies
Package Version Security advisories
crypto-js (npm) 4.2.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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

Successfully merging this pull request may close these issues.

2 participants