Skip to content

Commit

Permalink
🔀 Merge pull request #113 from Lissy93/FIX/auth-security-fix
Browse files Browse the repository at this point in the history
[SECURITY] Improve Robustness of Auth Checking
  • Loading branch information
Lissy93 committed Aug 1, 2021
2 parents 01e4c0f + 87f6438 commit fe48310
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## ✨ 1.4.8 - Optional Crash Reports [PR #120](https://github.com/Lissy93/dashy/pull/112)
## 🔒 1.5.0 - Improve Robustness of Auth [PR #113](https://github.com/Lissy93/dashy/pull/113)
- Use both username + password for generating token, so that a change in either will log the user out
- Prevent privilege escalation by disallowing a user from modifying their user type through the UI
- Improve the isAuthenticated check, by taking account of empty users array

## ✨ 1.4.8 - Optional Crash Reports [PR #112](https://github.com/Lissy93/dashy/pull/112)
- Adds an optional, off by default method of getting crash reports
- This can be enabled in `appConfig.enableErrorReporting`, and will not be used at all unless explicitly activated by user
- This is needed for when a user raises a bug which is hard to fix
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dashy",
"version": "1.4.8",
"version": "1.5.0",
"license": "MIT",
"main": "server",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/components/Configuration/JsonEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export default {
localStorage.setItem(localStorageKeys.PAGE_INFO, JSON.stringify(data.pageInfo));
}
if (data.appConfig) {
data.appConfig.auth = this.config.appConfig.auth || [];
localStorage.setItem(localStorageKeys.APP_CONFIG, JSON.stringify(data.appConfig));
}
if (data.appConfig.theme) {
Expand Down
7 changes: 6 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import { metaTagData } from '@/utils/defaults';

Vue.use(Router);

/**
* Checks if the current user is either authenticated,
* or if authentication is not enabled
* @returns true if user logged in, or user management not enabled
*/
const isAuthenticated = () => {
const users = config.appConfig.auth;
return (!users || isLoggedIn(users));
return (!users || users.length === 0 || isLoggedIn(users));
};

const router = new Router({
Expand Down
8 changes: 6 additions & 2 deletions src/utils/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { cookieKeys, localStorageKeys } from './defaults';
* @param {String} user The username of user
* @returns {String} The hashed token
*/
const generateUserToken = (user) => sha256(user.toString()).toString().toLowerCase();
const generateUserToken = (user) => {
const strAndUpper = (input) => input.toString().toUpperCase();
const sha = sha256(strAndUpper(user.user) + strAndUpper(user.hash));
return strAndUpper(sha);
};

/**
* Checks if the user is currently authenticated
Expand Down Expand Up @@ -47,7 +51,7 @@ export const checkCredentials = (username, pass, users) => {
response = { correct: false, msg: 'Missing Password' };
} else {
users.forEach((user) => {
if (user.user === username) {
if (user.user.toLowerCase() === username.toLowerCase()) {
if (user.hash.toLowerCase() === sha256(pass).toString().toLowerCase()) {
response = { correct: true, msg: 'Logging in...' };
} else {
Expand Down

0 comments on commit fe48310

Please sign in to comment.