Skip to content

Commit

Permalink
fix(session): correctly load tokens from file
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jun 26, 2022
1 parent 278a492 commit 24ea446
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
21 changes: 11 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ if (!process.env.FORK) {

let configFile = path.join(__dirname, '/config.yml')

nconf.defaults({
base_dir: __dirname,
tokens: {
secret: chance.hash() + chance.md5(),
expires: 900
}
})

if (nconf.get('config')) {
configFile = path.resolve(__dirname, nconf.get('config'))
}
Expand All @@ -81,9 +73,18 @@ function loadConfig () {
file: configFile,
format: require('nconf-yaml')
})

// Must load after file
nconf.defaults({
base_dir: __dirname,
tokens: {
secret: chance.hash() + chance.md5(),
expires: 900
}
})
}

function checkForOldConfig() {
function checkForOldConfig () {
const oldConfigFile = path.join(__dirname, '/config.json')
if (fs.existsSync(oldConfigFile)) {
// Convert config to yaml.
Expand All @@ -99,7 +100,7 @@ function checkForOldConfig() {
}

function start () {
if (!isDocker)loadConfig()
if (!isDocker) loadConfig()

const _db = require('./src/database')

Expand Down
4 changes: 3 additions & 1 deletion src/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const insecureHandlebars = APC.allowInsecurePrototypeAccess(HandleBars)
const hbs = require('express-hbs')
const hbsHelpers = require('../helpers/hbs/helpers')
const winston = require('../logger')
const nconf = require('nconf')
const flash = require('connect-flash')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
Expand Down Expand Up @@ -72,7 +73,8 @@ module.exports = function (app, db, callback) {
maxAge: 1000 * 60 * 60 * 24 * 365 // 1 year
}

const sessionSecret = 'trudesk$123#SessionKeY!2387'
const sessionSecret = nconf.get('tokens:secret') ? nconf.get('tokens:secret') : 'trudesk$1234#SessionKeY!2288'

async.waterfall(
[
function (next) {
Expand Down
5 changes: 3 additions & 2 deletions src/socketserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const socketServer = function (ws) {

const socketConfig = {
pingTimeout: nconf.get('socket:pingTimeout') ? nconf.get('socket:pingTimeout') : 15000,
pingInterval: nconf.get('socket:pingInterval') ? nconf.get('socket:pingInterval') : 30000
pingInterval: nconf.get('socket:pingInterval') ? nconf.get('socket:pingInterval') : 30000,
secret: nconf.get('tokens:secret') ? nconf.get('tokens:secret') : 'trudesk$1234#SessionKeY!2288'
}

const io = require('socket.io')(ws.server, {
Expand Down Expand Up @@ -74,7 +75,7 @@ const socketServer = function (ws) {
cookieParser: cookieparser,
key: 'connect.sid',
store: ws.sessionStore,
secret: 'trudesk$123#SessionKeY!2387',
secret: socketConfig.secret,
success: onAuthorizeSuccess
})(data, accept)
}
Expand Down

0 comments on commit 24ea446

Please sign in to comment.