Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 51a39cb

Browse files
authored
Merge pull request #203 from omar10594/master
Added validation if the socket doesn't have the referer header.
2 parents 3933def + 562eca8 commit 51a39cb

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/channels/private-channel.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,27 @@ export class PrivateChannel {
4545
* @return {string}
4646
*/
4747
protected authHost(socket: any): string {
48-
let referer = url.parse(socket.request.headers.referer);
49-
let authHostSelected = 'http://localhost';
50-
let authHosts = (this.options.authHost) ?
51-
this.options.authHost : this.options.host;
52-
53-
if (typeof authHosts === "string") {
54-
authHosts = [authHosts];
55-
}
56-
57-
for (let authHost of authHosts) {
58-
authHostSelected = authHost;
59-
60-
if (this.hasMatchingHost(referer, authHost)) {
61-
authHostSelected = `${referer.protocol}//${referer.host}`;
62-
break;
63-
}
64-
};
48+
let authHosts = (this.options.authHost) ?
49+
this.options.authHost : this.options.host;
50+
51+
if (typeof authHosts === "string") {
52+
authHosts = [authHosts];
53+
}
54+
55+
let authHostSelected = authHosts[0] || 'http://localhost';
56+
57+
if(socket.request.headers.referer) {
58+
let referer = url.parse(socket.request.headers.referer);
59+
60+
for (let authHost of authHosts) {
61+
authHostSelected = authHost;
62+
63+
if (this.hasMatchingHost(referer, authHost)) {
64+
authHostSelected = `${referer.protocol}//${referer.host}`;
65+
break;
66+
}
67+
};
68+
}
6569

6670
return authHostSelected;
6771
}

0 commit comments

Comments
 (0)