
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
moleculer-sc
Advanced tools
A API Gateway service for Moleculer framework using SocketCluster
socket.authToken
=> moleculer ctx.meta.user
)$ npm install --save moleculer-sc
Before you start, you have to create a SocketCluster project, and write the code in worker.js
.
Create your own SocketCluster Gateway service.
// SocketCluster worker.js
const SocketClusterService = require('moleculer-sc')
module.exports.run = function (worker) {
broker.createService({
name:'sc-gw',
mixins:[SocketClusterService],
settings:{
worker, // Pass the sc worker to settings.
}
})
broker.start()
}
Example events:
test.hello
action: socket.emit('test.hello',null, callback)
math.add
action with params: socket.emit('test.hello',{a:25, b:13}, callback)
socket.emit('$node.health',null, callback)
socket.emit('$node.list', null, callback)
You can implement authorization. For this you have to do 1 things.
Example authorization:
// Server code
// This is a slightly simplified version of what it might look
// like if you were using MySQL as a database.
socket.on('login', function (credentials, respond) {
var passwordHash = sha256(credentials.password);
var userQuery = 'SELECT * FROM Users WHERE username = ?';
mySQLClient.query(userQuery, [credentials.username], function (err, rows) {
var userRow = rows[0];
var isValidLogin = userRow && userRow.password === passwordHash;
if (isValidLogin) {
respond();
// This will give the client a token so that they won't
// have to login again if they lose their connection
// or revisit the app at a later time.
socket.setAuthToken({username: credentials.username, channels: userRow.channels});
} else {
// Passing string as first argument indicates error
respond('Login failed');
}
})
})
Also you can overwrite the getMeta
method to add more addition meta info. The default getMeta
method is:
getMeta(socket){
return {
user: socket.authToken
}
}
You can also pass a node_acl
instance to settings:
let acl = require('acl')
acl = new acl(new acl.memoryBackend())
acl.allow('admin', 'math', 'add') // allow admin to call math.add
acl.addUserRoles('user id here', 'admin')
module.exports.run = function (worker) {
broker.createService({
name:'sc-gw', // SocketCluster GateWay
mixins:[SocketClusterService],
settings:{
acl, //Optional
worker,
}
})
broker.start()
}
By default, moleculer-sc
will get the userId from socket.authToken.id
for node_acl
. The default getUserId
method is:
getUserId(socket){
if(socket.authToken && socket.authToken.id){
return socket.authToken.id
}
}
You can overwrite the getUserId
method to get userId from other field:
broker.createService({
name:'sc-gw', // SocketCluster GateWay
mixins:[SocketClusterService],
settings:{
acl, //Optional
worker,
},
methods:{
getUserId(socket){ //scSocket
return socket.authToken.username
}
}
})
todo
FAQs
API Gateway service for Moleculer framework using SocketCluster
The npm package moleculer-sc receives a total of 19 weekly downloads. As such, moleculer-sc popularity was classified as not popular.
We found that moleculer-sc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.