-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: api v2 #68
feat: api v2 #68
Conversation
title: "加入成功", | ||
type: "success" | ||
}); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, password); |
Check failure
Code scanning / CodeQL
Clear text storage of sensitive information High
an access to password
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we need to ensure that the password is encrypted before storing it in localStorage
. We can use the crypto
module from Node.js to encrypt the password. The encrypted password can then be safely stored in localStorage
. When retrieving the password, we will need to decrypt it.
- Import the
crypto
module. - Create functions to encrypt and decrypt the password.
- Encrypt the password before storing it in
localStorage
. - Decrypt the password when retrieving it from
localStorage
.
-
Copy modified lines R12-R31 -
Copy modified line R145 -
Copy modified line R201
@@ -11,2 +11,22 @@ | ||
import { RoomMemberPermission, RoomAdminPermission, MEMBER_STATUS, RoomStatus } from "@/types/Room"; | ||
import * as crypto from 'crypto'; | ||
|
||
const algorithm = 'aes-256-ctr'; | ||
const secretKey = 'vOVH6sdmpNWjRRIqCc7rdxs01lwHzfr3'; // This should be stored securely | ||
const iv = crypto.randomBytes(16); | ||
|
||
const encrypt = (text) => { | ||
const cipher = crypto.createCipheriv(algorithm, secretKey, iv); | ||
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]); | ||
return iv.toString('hex') + ':' + encrypted.toString('hex'); | ||
}; | ||
|
||
const decrypt = (hash) => { | ||
const parts = hash.split(':'); | ||
const iv = Buffer.from(parts.shift(), 'hex'); | ||
const encryptedText = Buffer.from(parts.join(':'), 'hex'); | ||
const decipher = crypto.createDecipheriv(algorithm, secretKey, iv); | ||
const decrypted = Buffer.concat([decipher.update(encryptedText), decipher.final()]); | ||
return decrypted.toString(); | ||
}; | ||
|
||
@@ -124,3 +144,3 @@ | ||
}); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, password); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, encrypt(password)); | ||
router.replace(`/cinema/${roomId}`); | ||
@@ -180,3 +200,3 @@ | ||
}); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, password); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, encrypt(password)); | ||
router.replace(`/cinema/${roomId}`); |
title: "加入成功", | ||
type: "success" | ||
}); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, password); |
Check failure
Code scanning / CodeQL
Clear text storage of sensitive information High
an access to password
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 months ago
To fix the problem, we need to ensure that the password is encrypted before storing it in localStorage
. We can use the crypto
module from Node.js to encrypt the password. The encrypted password can then be safely stored in localStorage
. When retrieving the password, we will need to decrypt it.
- Import the
crypto
module. - Create functions to encrypt and decrypt the password.
- Use the encryption function before storing the password in
localStorage
. - Use the decryption function when retrieving the password from
localStorage
.
-
Copy modified line R2 -
Copy modified lines R14-R25 -
Copy modified line R138 -
Copy modified line R194
@@ -1,2 +1,3 @@ | ||
import { ref } from "vue"; | ||
import crypto from "crypto"; | ||
import { ElNotification } from "element-plus"; | ||
@@ -12,2 +13,14 @@ | ||
|
||
const encryptionKey = "your-encryption-key"; // Replace with your actual encryption key | ||
|
||
function encrypt(text: string): string { | ||
const cipher = crypto.createCipher('aes-256-ctr', encryptionKey); | ||
return cipher.update(text, 'utf8', 'hex') + cipher.final('hex'); | ||
} | ||
|
||
function decrypt(text: string): string { | ||
const decipher = crypto.createDecipher('aes-256-ctr', encryptionKey); | ||
return decipher.update(text, 'hex', 'utf8') + decipher.final('utf8'); | ||
} | ||
|
||
// 获取用户信息 | ||
@@ -124,3 +137,3 @@ | ||
}); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, password); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, encrypt(password)); | ||
router.replace(`/cinema/${roomId}`); | ||
@@ -180,3 +193,3 @@ | ||
}); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, password); | ||
if (password) localStorage.setItem(`room-${roomId}-pwd`, encrypt(password)); | ||
router.replace(`/cinema/${roomId}`); |
No description provided.