Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
node-ldapauthz
Advanced tools
A simple node.js lib for user authorization based on LDAP server groups.
A simple node.js lib for user authorization based on LDAP server groups.
##Installation
$ npm install connect-roles
var LdapAuthz = require('ldapauthz');
var authz = new LdapAuthz({url: 'ldaps://ldap.example.com:663', ...});
...
authz.getGrantedAuthorities(username, function (err, authorities) { ... });
...
authz.close(function (err) { ... })
Creates an LDAP authz class.
log4js
is also given, this will add TRACE-level logging for ldapjs (quite verbose).Closes the LDAP client.
Gets the list of authorities for the user.
function (err, authorities)
The callback function.const URL = 'ldap://localhost:389';
const ADMIN_DN = 'cn=root,ou=person,dc=sample,dc=com';
const ADMIN_PASSWORD = 'secret';
const SEARCH_BASE = 'ou=person,dc=sample,dc=com';
const SEARCH_FILTER = '(&(objectclass=inetOrgPerson)(uid={{username}}))';
const GROUP_SEARCH_BASE = 'ou=group,dc=sample,dc=com';
const GROUP_SEARCH_FILTER = '(&(uniqueMember={{username}})(objectClass=group))';
var _ = require("underscore"),
express = require('express'),
bodyParser = require('body-parser'),
session = require('express-session'),
cookieParser = require('cookie-parser'),
passport = require('passport'),
LdapStrategy = require('passport-ldapauth').Strategy,
ConnectRoles = require('connect-roles'),
LdapAuthz = require('./ldapauthz.js');
var app = express();
var user = new ConnectRoles();
passport.use(new LdapStrategy({
server: {
url: URL,
adminDn: ADMIN_DN,
adminPassword: ADMIN_PASSWORD,
searchBase: SEARCH_BASE,
searchFilter: SEARCH_FILTER
}
},
function(user, done) {
console.log('user: ' + user.dn);
var authz = new LdapAuthz({
url: URL,
adminDn: ADMIN_DN,
adminPassword: ADMIN_PASSWORD,
groupSearchBase: GROUP_SEARCH_BASE,
groupSearchFilter: GROUP_SEARCH_FILTER
});
authz.getGrantedAuthorities(user.dn, function (err, authorities) {
authz.close(function (err) {});
if (err) {
return done(err);
}
user.roles = authorities;
return done(null, user);
});
}
));
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(session({ secret: 'keyboard cat', saveUninitialized: true, resave: true }));
app.use(cookieParser());
app.use(passport.initialize());
app.use(passport.session());
app.use(user.middleware());
// Anonymous users can only access the home page
// Returning false stops any more rules from being considered
user.use(function (req, action) {
if (!req.isAuthenticated()) {
return action === 'access home page';
}
})
user.use('user', function (req) {
return _.contains(req.user.roles, 'GEC-BR-search-usuarios');
});
user.use('admin', function (req) {
return _.contains(req.user.roles, 'GEC-BR-search-administradores');
});
app.get('/', user.can('access home page'), function (req, res) {
res.send({status: 'home - ok'}).end();
});
app.get('/login', passport.authenticate('ldapauth'), function(req, res) {
res.send({status: 'login - ok'}).end();
});
app.get('/user', user.is('user'), function (req, res) {
res.send({status: 'user - ok'}).end();
});
app.get('/admin', user.is('admin'), function (req, res) {
res.send({status: 'admin - ok'}).end();
});
app.listen(8080);
FAQs
A simple node.js lib for user authorization based on LDAP server groups.
The npm package node-ldapauthz receives a total of 3 weekly downloads. As such, node-ldapauthz popularity was classified as not popular.
We found that node-ldapauthz 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.