Skip to content

Commit 8992a8c

Browse files
author
Martin Crawford
committed
Fix: convert new Buffer() to Buffer.from() for security reasons.
1 parent 6550ea4 commit 8992a8c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function nowEpochSeconds(){
4040
}
4141

4242
function base64urlEncode(str) {
43-
return new Buffer(str)
43+
return Buffer.from(str)
4444
.toString('base64')
4545
.replace(/\+/g, '-')
4646
.replace(/\//g, '_')
@@ -277,7 +277,7 @@ Parser.prototype.isSupportedAlg = isSupportedAlg;
277277
Parser.prototype.safeJsonParse = function(input) {
278278
var result;
279279
try{
280-
result = JSON.parse(new Buffer(base64urlUnescape(input),'base64'));
280+
result = JSON.parse(Buffer.from(base64urlUnescape(input),'base64'));
281281
}catch(e){
282282
return e;
283283
}
@@ -297,7 +297,7 @@ Parser.prototype.parse = function parse(jwtString,cb){
297297
var body = this.safeJsonParse(segments[1]);
298298

299299
if(segments[2]){
300-
signature = new Buffer(base64urlUnescape(segments[2]),'base64')
300+
signature = Buffer.from(base64urlUnescape(segments[2]),'base64')
301301
.toString('base64');
302302
}
303303

0 commit comments

Comments
 (0)