Skip to content

Commit

Permalink
makes changes to jwt sign
Browse files Browse the repository at this point in the history
  • Loading branch information
snoopysecurity committed Nov 21, 2020
1 parent 99b3522 commit d525abc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
15 changes: 7 additions & 8 deletions controllers/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ function set_cors(req, res) {
};


const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
algorithms: ["HS256", "none"],
ignoreExpiration: true
};

module.exports = {
list_all_notes: (req, res) => {
res = set_cors(req, res)
Expand All @@ -25,10 +32,6 @@ module.exports = {
if (!err) {
let result = {}
const token = req.headers.authorization.split(' ')[1];
const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
};
result = jwt.verify(token, process.env.JWT_SECRET, options);
Note.find({ user: result.user }, { __v: 0 }, function (err, someValue) {
if (err) res.json(err);
Expand Down Expand Up @@ -68,10 +71,6 @@ module.exports = {
if (!err) {
let result = {}
const token = req.headers.authorization.split(' ')[1]; // Bearer <token>
const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
};
result = jwt.verify(token, process.env.JWT_SECRET, options);
var body = req.body

Expand Down
11 changes: 7 additions & 4 deletions controllers/passphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ function set_cors(req, res) {
return res;
};

const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
algorithms: ["HS256", "none"],
ignoreExpiration: true
};

module.exports = {
save: (req, res) => {
res = set_cors(req, res)
Expand All @@ -24,10 +31,6 @@ module.exports = {
} else {
let result = {}
const token = req.headers.authorization.split(' ')[1];
const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
};
result = jwt.verify(token, process.env.JWT_SECRET, options);
sql.query("CREATE TABLE IF NOT EXISTS `passphrases` (`username` varchar(200) NOT NULL,`passphrase` varchar(200) NOT NULL,`reminder` varchar(200) NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP)")

Expand Down
27 changes: 15 additions & 12 deletions controllers/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ const url = require('url');
const fs = require('fs');
const http = require('http');


const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
algorithms: ["HS256", "none"],
ignoreExpiration: true
};


module.exports = {
post: (req, res) => {

Expand All @@ -12,10 +21,6 @@ module.exports = {
let result = {}

const token = req.headers.authorization.split(' ')[1];
const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
};
result = jwt.verify(token, process.env.JWT_SECRET, options);


Expand All @@ -34,9 +39,11 @@ module.exports = {
}

if (typeof sampleFile.name !== 'undefined') {
sampleFile.name = 'undefined';
}

if ( sampleFile.name.endsWith(".xml") == false ) {
res.status(400).send("Uploaded file is not an XML file.");
return;
}
}

filePath = __dirname + '/../public/uploads/' + result.user + "/" + sampleFile.name;

Expand All @@ -54,10 +61,6 @@ module.exports = {

let result = {}
const token = req.headers.authorization.split(' ')[1]; // Bearer <token>
const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
};
result = jwt.verify(token, process.env.JWT_SECRET, options);


Expand All @@ -70,9 +73,9 @@ module.exports = {
} else {
files.forEach(function (file) {
resultData.push("http://dvws.local/uploads/" + result.user + "/" + file);
res.json(resultData);

});
res.json(resultData);
}

});
Expand Down
9 changes: 6 additions & 3 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ module.exports = {
const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity',
permissions: ["user:admin"]
permissions: ["user:admin"],
algorithms: ["HS256", "none"],
ignoreExpiration: true
};

result = jwt.verify(token, process.env.JWT_SECRET, options);
if (result.permissions.includes('user:admin')) {
endresult = {}
Expand Down Expand Up @@ -119,7 +122,7 @@ module.exports = {
"user:write",
"user:admin"
] };
const options = { expiresIn: '2d', issuer: 'https://github.com/snoopysecurity' };
const options = { expiresIn: '2d', issuer: 'https://github.com/snoopysecurity', algorithm: "HS256"};
const secret = process.env.JWT_SECRET;
const token = jwt.sign(payload, secret, options);

Expand All @@ -132,7 +135,7 @@ module.exports = {
"user:read",
"user:write"
] };
const options = { expiresIn: '2d', issuer: 'https://github.com/snoopysecurity' };
const options = { expiresIn: '2d', issuer: 'https://github.com/snoopysecurity', algorithm: "HS256"};
const secret = process.env.JWT_SECRET;
const token = jwt.sign(payload, secret, options);

Expand Down
4 changes: 3 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = {
const token = req.headers.authorization.split(' ')[1]; // Bearer <token>
const options = {
expiresIn: '2d',
issuer: 'https://github.com/snoopysecurity'
issuer: 'https://github.com/snoopysecurity',
algorithms: ["HS256", "none"],
ignoreExpiration: true
};
try {
result = jwt.verify(token, process.env.JWT_SECRET, options);
Expand Down

0 comments on commit d525abc

Please sign in to comment.