
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
express-persona
Advanced tools
Mozilla Persona integration for Express. express-persona is designed to quickly get Persona authentication working in your Express application, while following Persona security best practices.
Install using npm: npm install express-persona
Include the module inside your Express application:
var express = require("express"),
app = express();
app.use(express.json())
.use(express.urlencoded())
.use(express.cookieParser())
.use(express.session({
secret: "mozillapersona"
}));
require("express-persona")(app, {
audience: "http://localhost:8888" // Must match your browser's address bar
});
Include the Persona library in your web page:
<script src="https://login.persona.org/include.js"></script>
Add login and logout functionality to your buttons:
document.querySelector("#login").addEventListener("click", function() {
navigator.id.request();
}, false);
document.querySelector("#logout").addEventListener("click", function() {
navigator.id.logout();
}, false);
Watch for login and logout actions:
navigator.id.watch({
onlogin: function(assertion) {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/persona/verify", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.addEventListener("loadend", function(e) {
var data = JSON.parse(this.responseText);
if (data && data.status === "okay") {
console.log("You have been logged in as: " + data.email);
}
}, false);
xhr.send(JSON.stringify({
assertion: assertion
}));
},
onlogout: function() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/persona/logout", true);
xhr.addEventListener("loadend", function(e) {
console.log("You have been logged out");
});
xhr.send();
}
});
By default, express-persona adds the users email address to req.session.email
when their
email is validated.
This library will handle 3 of 4 essential practices for [Persona security considerations] (https://developer.mozilla.org/en-US/docs/Persona/Security_Considerations) but you should implement CSRF protection as well. I recommend the built-in express csrf middleware.
You can view and run complete examples in the examples directory.
require('express-persona')
returns function(express, options)
express
is an instance of the express server that you want to add routes tooptions
is an object. It has one required parameter, audience
.audience
- The URL of your express app when viewed in a browser. Must include the protocol, hostname, and port.
http://example.org:80
, https://example.org:443
verifyPath
- The URL that clients use to verify credentials.
/persona/verify
/browserid/verify
, /api/verify
logoutPath
- The URL that clients use to logout.
/persona/logout
/browserid/logout
, /api/logout
sessionKey
- The session key to store the validated email in.
email
user
, username
verifierURI
- The URI of the Persona Remote Verification API
https://verifier.login.persona.org/verify
verifyResponse(error, req, res, email)
- Function to generate response for verify route
error
will be a string suitable for display (the "reason" attribute in the default implementation), if an error occursreq, res
are the request and response objectsemail
is a string containing the email, and will exist if there is not an errorlogoutResponse(error, req, res)
- Function to generate response for logout route
error
will be a string suitable for display, if an error occursreq, res
are the request and response objectsmiddleware(req, res, next)
- Custom middleware for logout/login routes
req, res
are the request and response objectsnext
points to the next middleware function in the chain{
"status": "okay"
"email": "jon@example.org"
}
{
"status": "failure"
"reason": "request failed"
}
{
"status": "okay"
}
Run tests using npm test
from the root of the repository.
FAQs
Mozilla Persona authentication for your Express application
The npm package express-persona receives a total of 1 weekly downloads. As such, express-persona popularity was classified as not popular.
We found that express-persona 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
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.