Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
http-auth
Advanced tools
The http-auth npm package provides basic and digest access authentication for Node.js applications. It allows developers to secure their web applications by requiring users to provide a username and password before accessing certain routes or resources.
Basic Authentication
This feature allows you to set up basic authentication for your Node.js server. Users will need to provide a username and password to access the protected routes.
const http = require('http');
const auth = require('http-auth');
const basic = auth.basic({
realm: 'Simon Area',
file: __dirname + '/users.htpasswd' // user:password in htpasswd format
});
http.createServer(basic, (req, res) => {
res.end(`Welcome to private area - ${req.user}!`);
}).listen(1337, () => {
console.log('Server running at http://127.0.0.1:1337/');
});
Digest Authentication
This feature allows you to set up digest authentication for your Node.js server. Digest authentication is more secure than basic authentication as it uses MD5 hashing.
const http = require('http');
const auth = require('http-auth');
const digest = auth.digest({
realm: 'Simon Area',
file: __dirname + '/users.htdigest' // user:realm:password in htdigest format
});
http.createServer(digest, (req, res) => {
res.end(`Welcome to private area - ${req.user}!`);
}).listen(1337, () => {
console.log('Server running at http://127.0.0.1:1337/');
});
The express-basic-auth package provides basic authentication middleware for Express applications. It is simpler to use with Express compared to http-auth and integrates seamlessly with the Express framework.
The passport-http package is a Passport strategy for HTTP Basic and Digest authentication. It is part of the Passport.js ecosystem, which provides a wide range of authentication strategies and is highly extensible.
The basic-auth package is a simple tool for parsing basic authentication headers. It does not provide full authentication middleware but can be used in conjunction with other packages to implement basic authentication.
Node.js package for HTTP basic and digest access authentication.
Via git (or downloaded tarball):
$ git clone git://github.com/gevorg/http-auth.git
Via npm:
$ npm install http-auth
// HTTP module
const http = require("http");
// Authentication module.
const auth = require("http-auth");
const basic = auth.basic({
realm: "Simon Area.",
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
});
// Creating new HTTP server.
http
.createServer(
basic.check((req, res) => {
res.end(`Welcome to private area - ${req.user}!`);
})
)
.listen(1337, () => {
// Log URL.
console.log("Server running at http://127.0.0.1:1337/");
});
Please check examples directory for more.
realm
- Authentication realm, by default it is Users.file
- File where user details are stored.
file: () => 'adam:adam\neve:eve',
algorithm
- Algorithm that will be used only for digest access authentication.
qop
- Quality of protection that is used only for digest access authentication.
msg401
- Message for failed authentication 401 page.msg407
- Message for failed authentication 407 page.contentType
- Content type for failed authentication page.skipUser
- Set this to true, if you don't want req.user to be filled with authentication info.proxy
- Set this to true, if you want to use it with http-proxy.It uses mocha, so just run following command in package directory:
$ npm test
You can also use stackoverflow to ask questions using http-auth tag.
Please check this link for integration packages.
The MIT License (MIT)
FAQs
Node.js package for HTTP basic and digest access authentication.
The npm package http-auth receives a total of 360,683 weekly downloads. As such, http-auth popularity was classified as popular.
We found that http-auth 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.