feat: Additional httpOnly token for enhanced security in browsers
parent
4176a62f1a
commit
9699fbe76a
@ -1,20 +1,22 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
async fn() {
|
async fn() {
|
||||||
const { accessToken } = this.req;
|
const { currentSession } = this.req;
|
||||||
|
|
||||||
await Session.updateOne({
|
await Session.updateOne({
|
||||||
accessToken,
|
id: currentSession.id,
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
}).set({
|
}).set({
|
||||||
deletedAt: new Date().toISOString(),
|
deletedAt: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.req.isSocket) {
|
sails.sockets.leaveAll(`@accessToken:${currentSession.accessToken}`);
|
||||||
sails.sockets.leaveAll(`@accessToken:${accessToken}`);
|
|
||||||
|
if (currentSession.httpOnlyToken && !this.req.isSocket) {
|
||||||
|
sails.helpers.utils.clearHttpOnlyTokenCookie(this.res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
item: accessToken,
|
item: currentSession.accessToken,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
module.exports = {
|
||||||
|
sync: true,
|
||||||
|
|
||||||
|
inputs: {
|
||||||
|
response: {
|
||||||
|
type: 'ref',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
fn(inputs) {
|
||||||
|
inputs.response.clearCookie('httpOnlyToken', {
|
||||||
|
path: sails.config.custom.baseUrlPath,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
module.exports = {
|
||||||
|
sync: true,
|
||||||
|
|
||||||
|
inputs: {
|
||||||
|
value: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
accessTokenPayload: {
|
||||||
|
type: 'json',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
response: {
|
||||||
|
type: 'ref',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
fn(inputs) {
|
||||||
|
inputs.response.cookie('httpOnlyToken', inputs.value, {
|
||||||
|
expires: new Date(inputs.accessTokenPayload.exp * 1000),
|
||||||
|
path: sails.config.custom.baseUrlPath,
|
||||||
|
secure: sails.config.custom.baseUrlSecure,
|
||||||
|
httpOnly: true,
|
||||||
|
sameSite: 'strict',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
module.exports.up = async (knex) =>
|
||||||
|
knex.schema.table('session', (table) => {
|
||||||
|
/* Columns */
|
||||||
|
|
||||||
|
table.text('http_only_token');
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports.down = (knex) =>
|
||||||
|
knex.schema.table('session', (table) => {
|
||||||
|
table.dropColumn('http_only_token');
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue