Skip to content

Commit b3217ca

Browse files
sokraevilebottnawi
authored andcommitted
fix: check origin header for websocket connection (#1603)
1 parent 68dd49a commit b3217ca

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎lib/Server.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,16 @@ Server.prototype.setContentHeaders = function (req, res, next) {
630630
next();
631631
};
632632

633-
Server.prototype.checkHost=function(headers){
633+
Server.prototype.checkHost=function(headers,headerToCheck){
634634
// allow user to opt-out this security check, at own risk
635635
if(this.disableHostCheck){
636636
returntrue;
637637
}
638+
639+
if(!headerToCheck)headerToCheck='host';
638640
// get the Host header and extract hostname
639641
// we don't care about port not matching
640-
consthostHeader=headers.host;
642+
consthostHeader=headers[headerToCheck];
641643

642644
if(!hostHeader){
643645
returnfalse;
@@ -725,8 +727,8 @@ Server.prototype.listen = function (port, hostname, fn) {
725727
return;
726728
}
727729

728-
if(!this.checkHost(connection.headers)){
729-
this.sockWrite([connection],'error','Invalid Host header');
730+
if(!this.checkHost(connection.headers)||!this.checkHost(connection.headers,'origin')){
731+
this.sockWrite([connection],'error','Invalid Host/Origin header');
730732

731733
connection.close();
732734

0 commit comments

Comments
 (0)