mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
when leaving protected session don't forget to reset note cache (titles), #1810
This commit is contained in:
parent
2318d615bb
commit
ef37a52a06
@ -1,5 +1,6 @@
|
|||||||
import utils from "./utils.js";
|
import utils from "./utils.js";
|
||||||
import options from './options.js';
|
import options from './options.js';
|
||||||
|
import server from "./server.js";
|
||||||
|
|
||||||
const PROTECTED_SESSION_ID_KEY = 'protectedSessionId';
|
const PROTECTED_SESSION_ID_KEY = 'protectedSessionId';
|
||||||
|
|
||||||
@ -23,11 +24,11 @@ function resetSessionCookie() {
|
|||||||
utils.setSessionCookie(PROTECTED_SESSION_ID_KEY, null);
|
utils.setSessionCookie(PROTECTED_SESSION_ID_KEY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetProtectedSession() {
|
async function resetProtectedSession() {
|
||||||
resetSessionCookie();
|
resetSessionCookie();
|
||||||
|
|
||||||
// most secure solution - guarantees nothing remained in memory
|
await server.post("logout/protected");
|
||||||
// since this expires because user doesn't use the app, it shouldn't be disruptive
|
|
||||||
utils.reloadApp();
|
utils.reloadApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +78,12 @@ function loginToProtectedSession(req) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logoutFromProtectedSession() {
|
||||||
|
protectedSessionService.resetDataKey();
|
||||||
|
|
||||||
|
eventService.emit(eventService.LEAVE_PROTECTED_SESSION);
|
||||||
|
}
|
||||||
|
|
||||||
function token(req) {
|
function token(req) {
|
||||||
const username = req.body.username;
|
const username = req.body.username;
|
||||||
const password = req.body.password;
|
const password = req.body.password;
|
||||||
@ -101,5 +107,6 @@ function token(req) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
loginSync,
|
loginSync,
|
||||||
loginToProtectedSession,
|
loginToProtectedSession,
|
||||||
|
logoutFromProtectedSession,
|
||||||
token
|
token
|
||||||
};
|
};
|
||||||
|
@ -270,6 +270,8 @@ function register(app) {
|
|||||||
route(POST, '/api/login/sync', [], loginApiRoute.loginSync, apiResultHandler);
|
route(POST, '/api/login/sync', [], loginApiRoute.loginSync, apiResultHandler);
|
||||||
// this is for entering protected mode so user has to be already logged-in (that's the reason we don't require username)
|
// this is for entering protected mode so user has to be already logged-in (that's the reason we don't require username)
|
||||||
apiRoute(POST, '/api/login/protected', loginApiRoute.loginToProtectedSession);
|
apiRoute(POST, '/api/login/protected', loginApiRoute.loginToProtectedSession);
|
||||||
|
apiRoute(POST, '/api/logout/protected', loginApiRoute.logoutFromProtectedSession);
|
||||||
|
|
||||||
route(POST, '/api/login/token', [], loginApiRoute.token, apiResultHandler);
|
route(POST, '/api/login/token', [], loginApiRoute.token, apiResultHandler);
|
||||||
|
|
||||||
// in case of local electron, local calls are allowed unauthenticated, for server they need auth
|
// in case of local electron, local calls are allowed unauthenticated, for server they need auth
|
||||||
|
@ -2,6 +2,7 @@ const log = require('./log');
|
|||||||
|
|
||||||
const NOTE_TITLE_CHANGED = "NOTE_TITLE_CHANGED";
|
const NOTE_TITLE_CHANGED = "NOTE_TITLE_CHANGED";
|
||||||
const ENTER_PROTECTED_SESSION = "ENTER_PROTECTED_SESSION";
|
const ENTER_PROTECTED_SESSION = "ENTER_PROTECTED_SESSION";
|
||||||
|
const LEAVE_PROTECTED_SESSION = "LEAVE_PROTECTED_SESSION";
|
||||||
const ENTITY_CREATED = "ENTITY_CREATED";
|
const ENTITY_CREATED = "ENTITY_CREATED";
|
||||||
const ENTITY_CHANGED = "ENTITY_CHANGED";
|
const ENTITY_CHANGED = "ENTITY_CHANGED";
|
||||||
const ENTITY_DELETED = "ENTITY_DELETED";
|
const ENTITY_DELETED = "ENTITY_DELETED";
|
||||||
@ -47,6 +48,7 @@ module.exports = {
|
|||||||
// event types:
|
// event types:
|
||||||
NOTE_TITLE_CHANGED,
|
NOTE_TITLE_CHANGED,
|
||||||
ENTER_PROTECTED_SESSION,
|
ENTER_PROTECTED_SESSION,
|
||||||
|
LEAVE_PROTECTED_SESSION,
|
||||||
ENTITY_CREATED,
|
ENTITY_CREATED,
|
||||||
ENTITY_CHANGED,
|
ENTITY_CHANGED,
|
||||||
ENTITY_DELETED,
|
ENTITY_DELETED,
|
||||||
|
@ -177,6 +177,10 @@ eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eventService.subscribe(eventService.LEAVE_PROTECTED_SESSION, () => {
|
||||||
|
load();
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
load
|
load
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@ const log = require('./log');
|
|||||||
const dataEncryptionService = require('./data_encryption');
|
const dataEncryptionService = require('./data_encryption');
|
||||||
const cls = require('./cls');
|
const cls = require('./cls');
|
||||||
|
|
||||||
const dataKeyMap = {};
|
let dataKeyMap = {};
|
||||||
|
|
||||||
function setDataKey(decryptedDataKey) {
|
function setDataKey(decryptedDataKey) {
|
||||||
const protectedSessionId = utils.randomSecureToken(32);
|
const protectedSessionId = utils.randomSecureToken(32);
|
||||||
@ -29,6 +29,10 @@ function getDataKey() {
|
|||||||
return dataKeyMap[protectedSessionId];
|
return dataKeyMap[protectedSessionId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetDataKey() {
|
||||||
|
dataKeyMap = {};
|
||||||
|
}
|
||||||
|
|
||||||
function isProtectedSessionAvailable() {
|
function isProtectedSessionAvailable() {
|
||||||
const protectedSessionId = getProtectedSessionId();
|
const protectedSessionId = getProtectedSessionId();
|
||||||
|
|
||||||
@ -71,6 +75,7 @@ function decryptString(cipherText) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
setDataKey,
|
setDataKey,
|
||||||
getDataKey,
|
getDataKey,
|
||||||
|
resetDataKey,
|
||||||
isProtectedSessionAvailable,
|
isProtectedSessionAvailable,
|
||||||
encrypt,
|
encrypt,
|
||||||
decrypt,
|
decrypt,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user