Skip to content

Commit 49b257e

Browse files
committed
fix(security): Move token for socket.io to request body
Currently this commit breaks websocket events and needs to be updated.
1 parent f042b09 commit 49b257e

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

packages/backend/src/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,8 @@ async function jwt_auth(req){
11461146
else if(req.query && req.query.auth_token)
11471147
token = req.query.auth_token;
11481148
// Socket
1149-
else if(req.handshake && req.handshake.query && req.handshake.query.auth_token)
1150-
token = req.handshake.query.auth_token;
1149+
else if(req.handshake && req.handshake.auth && req.handshake.auth.auth_token)
1150+
token = req.handshake.auth.auth_token;
11511151

11521152
if(!token || token === 'null')
11531153
throw('No auth token found');

packages/backend/src/services/WebServerService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class WebServerService extends BaseService {
158158

159159
// Socket.io middleware for authentication
160160
socketio.use(async (socket, next) => {
161-
if (socket.handshake.query.auth_token) {
161+
if (socket.handshake.auth.auth_token) {
162162
try {
163163
let auth_res = await jwt_auth(socket);
164164
// successful auth
@@ -168,7 +168,7 @@ class WebServerService extends BaseService {
168168
socket.join(socket.user.id);
169169
next();
170170
} catch (e) {
171-
console.log('socket auth err');
171+
console.log('socket auth err', e);
172172
}
173173
}
174174
});

packages/puter-js/src/modules/FileSystem/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class FileSystem{
6565
}
6666

6767
this.socket = io(this.APIOrigin, {
68-
query: {
68+
auth: {
6969
auth_token: this.authToken,
7070
}
7171
});

src/UI/UIDesktop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function UIDesktop(options){
4343

4444
// connect socket.
4545
window.socket = io(window.gui_origin + '/', {
46-
query: {
46+
auth: {
4747
auth_token: window.auth_token
4848
}
4949
});

0 commit comments

Comments
 (0)