Skip to content

Commit

Permalink
fix: fixed rekey issue with journal mode and double quotes vs single …
Browse files Browse the repository at this point in the history
…quote
  • Loading branch information
titanism committed Nov 30, 2023
1 parent 2ebf661 commit c28f643
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions helpers/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const REDACTED_FIELDS = new Set([
'body',
'data',
'password',
'new_password',
'pass',
'token',
'tokens',
Expand Down
16 changes: 14 additions & 2 deletions helpers/parse-payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ async function parsePayload(data, ws) {
db.pragma('wal_checkpoint(PASSIVE)');

// create backup
const results = db.exec(`VACUUM INTO "${tmp}"`);
const results = db.exec(`VACUUM INTO '${tmp}'`);

logger.debug('results', { results });

Expand All @@ -1503,7 +1503,19 @@ async function parsePayload(data, ws) {
tmp
);
// rekey the database with new password
backupDb.rekey(Buffer.from(decrypt(payload.new_password)));
backupDb.pragma('wal_checkpoint(PASSIVE)');
const journalModeResult = backupDb.pragma('journal_mode=DELETE');
if (
!Array.isArray(journalModeResult) ||
journalModeResult.length !== 1 ||
!journalModeResult[0] ||
typeof journalModeResult[0] !== 'object' ||
journalModeResult[0].journal_mode !== 'delete'
)
throw new TypeError('Journal mode could not be changed');
// backupDb.rekey(Buffer.from(decrypt(payload.new_password)));
backupDb.pragma(`rekey="${decrypt(payload.new_password)}"`);
backupDb.pragma('journal_mode=WAL');
backupDb.close();

// rename backup file (overwrites existing destination file)
Expand Down

0 comments on commit c28f643

Please sign in to comment.