mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-03 07:48:46 +08:00
fix(security): skip cache when checking old passwd
This commit is contained in:
parent
25eea41f60
commit
7800ef6102
@ -184,7 +184,7 @@ async function id2uuid(id){
|
|||||||
|
|
||||||
const cached = options.cached ?? true;
|
const cached = options.cached ?? true;
|
||||||
|
|
||||||
if ( cached ) {
|
if ( cached && ! options.force ) {
|
||||||
if (options.username) user = kv.get('users:username:' + options.username);
|
if (options.username) user = kv.get('users:username:' + options.username);
|
||||||
else if (options.email) user = kv.get('users:email:' + options.email);
|
else if (options.email) user = kv.get('users:email:' + options.email);
|
||||||
else if (options.uuid) user = kv.get('users:uuid:' + options.uuid);
|
else if (options.uuid) user = kv.get('users:uuid:' + options.uuid);
|
||||||
@ -194,6 +194,7 @@ async function id2uuid(id){
|
|||||||
if ( user ) return user;
|
if ( user ) return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! options.force ) {
|
||||||
if(options.username)
|
if(options.username)
|
||||||
user = await db.read("SELECT * FROM `user` WHERE `username` = ? LIMIT 1", [options.username]);
|
user = await db.read("SELECT * FROM `user` WHERE `username` = ? LIMIT 1", [options.username]);
|
||||||
else if(options.email)
|
else if(options.email)
|
||||||
@ -204,6 +205,7 @@ async function id2uuid(id){
|
|||||||
user = await db.read("SELECT * FROM `user` WHERE `id` = ? LIMIT 1", [options.id]);
|
user = await db.read("SELECT * FROM `user` WHERE `id` = ? LIMIT 1", [options.id]);
|
||||||
else if(options.referral_code)
|
else if(options.referral_code)
|
||||||
user = await db.read("SELECT * FROM `user` WHERE `referral_code` = ? LIMIT 1", [options.referral_code]);
|
user = await db.read("SELECT * FROM `user` WHERE `referral_code` = ? LIMIT 1", [options.referral_code]);
|
||||||
|
}
|
||||||
|
|
||||||
if(!user || !user[0]){
|
if(!user || !user[0]){
|
||||||
if(options.username)
|
if(options.username)
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
"use strict"
|
"use strict"
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const { invalidate_cached_user } = require('../helpers');
|
const { invalidate_cached_user, get_user } = require('../helpers');
|
||||||
const router = new express.Router();
|
const router = new express.Router();
|
||||||
const auth = require('../middleware/auth.js');
|
const auth = require('../middleware/auth.js');
|
||||||
const { DB_WRITE } = require('../services/database/consts');
|
const { DB_WRITE } = require('../services/database/consts');
|
||||||
@ -51,8 +51,9 @@ router.post('/passwd', auth, express.json(), async (req, res, next)=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
const user = await get_user({ id: req.user.id, force: true });
|
||||||
// check old_pass
|
// check old_pass
|
||||||
const isMatch = await bcrypt.compare(req.body.old_pass, req.user.password)
|
const isMatch = await bcrypt.compare(req.body.old_pass, user.password)
|
||||||
if(!isMatch)
|
if(!isMatch)
|
||||||
return res.status(400).send('old_pass does not match your current password.')
|
return res.status(400).send('old_pass does not match your current password.')
|
||||||
// check new_pass length
|
// check new_pass length
|
||||||
|
Loading…
Reference in New Issue
Block a user