npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

immunio

v1.5.3

Published

IMMUNIO protects your web app from security vulnerabilities by monitoring requests in realtime. After a two minute installation, your application will be protected from many of the top classes of attacks, including Cross-Site Scripting (XSS), SQL Injectio

Downloads

16

Readme

Immunio Node Agent

Support Matrix

| Feature | Required package & version * | Note | | ----------------------------- | -------------------------------- | ---- | | All features | Node >= 0.12 || | SQLi | Sequelize >= 2.1, pg 4.x, pg-native, mysql 2.x, sqlite3 3.x || | NoSQLi | Mongoose 4.x, mongodb 2.x | | | XSS | Jade >= 1.3, Mustache >= 2.1 || | Session, Redirect | express-session, cookie-session || | Authentication | Passport 0.3 || | CSRF | csrf 3.x || | Cookie Tampering | cookie-parser 1.4 with Express ||

* Tested versions. Other versions might also work.

Installation

From the root of your Node app:

$ npm install --save immunio

Installation from source

From the root of your Node app:

$ npm link /path/to/agent-node

Usage

To active Immunio, add the following as the first line of your app setup code:

var immunio = require('immunio');

Configuration

The agent key and secret can be configured via the IMMUNIO_KEY and IMMUNIO_SECRET environment variables.

If you are using a configuration file instead of using environment variables, it needs to be called immunio.json be in the application root folder and needs to contain the follow immunio.json:

{
  "key": "my-key",
  "secret": "my-secret"
}

Note: The environment variables will take precedence over the configuration file.

Authentication API

If you're using Passport, Immunio will automatically hook into your authentication system to protect you against attacks.

If you're not using the above framework, you will need to manually tell Immunio when authentication occurs. Use the following methods to do so.

  • After a user logs in: immunio.authentication.login(user, req)
  • After a failed login attempt: immunio.authentication.failedLogin(user, req)
  • After a user logs out: immunio.authentication.logout(user)
  • After the current user is changed (or set): immunio.authentication.setUser(user, req)
  • After a user requests a password reset: immunio.authentication.passwordReset(user, req)
  • After a failed requests for resetting a password: immunio.authentication.failedPasswordReset(user, req)

Note: immunio.authentication.setUser(user, req) should be called for every request where user data is available, not just when authentication mechanisms are used.

These methods take a user object with the following properties their first argument:

  • user_id: String or Number
  • username, login or name: String
  • email: String
  • reason: String (for failures)

The second argument should be the Node HTTP request (req) or response (res) object, if available.

Here's an example:

var immunio = require('immunio');

// ...

app.use(function(req, res, next) {
  // Assuming req.user is populated with the current user in a previous middleware.
  if (req.user) {
    immunio.authentication.setUser(req.user, req);
  }
});

app.post('/login', function(req, res) {
  var username = req.body.username;
  var password = req.body.password;

  db.findUser(username, password, function(err, user) {
    if (err) {
      // On failed login
      // ...
      immunio.authentication.failedLogin({ username: username }, req);
    } else {
      // On successful login
      // ...
      immunio.authentication.login({
        user_id: user.id,
        username: user.name,
        email: user.email
      }, req);
    }
  });
});

app.get('/logout', function(req, res) {
  // Get the current user
  var user = req.user;

  immunio.authentication.logout({
    user_id: user.id,
    username: user.name,
    email: user.email
  }, req);

  // Your logout code ...
});

Waiting for Agent readiness

By default your app will start before Immunio is ready to protect it. If you want to prevent this behavior and wait for Immunio to be fully active before starting your app, use the following:

var immunio = require('immunio');

// ...

immunio.on('ready', function() {
  // Start your web server here.
  server.listen(port);
});