NPE when connectionCookie is undefined (#13541)
This commit is contained in:
parent
12439bc873
commit
f3f580a708
|
|
@ -167,50 +167,54 @@ async function tryAuth(socket: Socket) {
|
|||
/* ********************************************************* */
|
||||
|
||||
// const host = socket.handshake.headers.host;
|
||||
const connectionCookie = socket.handshake.headers.cookie;
|
||||
if (connectionCookie !== null && connectionCookie !== "") {
|
||||
const matchedCookie = connectionCookie.match(/\bSESSION=\S+/);
|
||||
if (matchedCookie) {
|
||||
const sessionCookie = matchedCookie[0];
|
||||
let response;
|
||||
try {
|
||||
response = await axios.request({
|
||||
method: "GET",
|
||||
url: API_BASE_URL + "/users/me",
|
||||
headers: {
|
||||
Cookie: sessionCookie,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
console.info("401 received when authenticating user with cookie: " + sessionCookie);
|
||||
} else if (error.response) {
|
||||
log.error("Error response received while authentication: ", error.response);
|
||||
} else {
|
||||
log.error("Error authenticating", error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const email = response.data.data.email;
|
||||
const name = response.data.data.name ? response.data.data.name : email;
|
||||
|
||||
// If the session check API succeeds & the email/name is anonymousUser, then the user is not authenticated
|
||||
// and we should not allow them to join any rooms
|
||||
if (email === "anonymousUser" || name === "anonymousUser") {
|
||||
return false;
|
||||
}
|
||||
|
||||
socket.data.email = email;
|
||||
socket.data.name = name;
|
||||
|
||||
if (socket.data.pendingRoomId) { // an appId or pageId is pending for this socket, join now
|
||||
joinEditRoom(socket, socket.data.pendingRoomId, socket.data.pendingRoomPrefix);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const connectionCookie = socket?.handshake?.headers?.cookie;
|
||||
if (connectionCookie === undefined || connectionCookie === null || connectionCookie === "") {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
const matchedCookie = connectionCookie.match(/\bSESSION=\S+/);
|
||||
if (!matchedCookie) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const sessionCookie = matchedCookie[0];
|
||||
let response;
|
||||
try {
|
||||
response = await axios.request({
|
||||
method: "GET",
|
||||
url: API_BASE_URL + "/users/me",
|
||||
headers: {
|
||||
Cookie: sessionCookie,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
console.info("401 received when authenticating user with cookie: " + sessionCookie);
|
||||
} else if (error.response) {
|
||||
log.error("Error response received while authentication: ", error.response);
|
||||
} else {
|
||||
log.error("Error authenticating", error);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const email = response?.data?.data?.email;
|
||||
const name = response?.data?.data?.name ?? email;
|
||||
|
||||
// If the session check API succeeds & the email/name is anonymousUser, then the user is not authenticated
|
||||
// and we should not allow them to join any rooms
|
||||
if (email == null || email === "anonymousUser" || name === "anonymousUser") {
|
||||
return false;
|
||||
}
|
||||
|
||||
socket.data.email = email;
|
||||
socket.data.name = name;
|
||||
|
||||
if (socket.data.pendingRoomId) { // an appId or pageId is pending for this socket, join now
|
||||
joinEditRoom(socket, socket.data.pendingRoomId, socket.data.pendingRoomPrefix);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async function watchMongoDB(io) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user