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

securestack

v0.1.0

Published

A comprehensive authentication and security solution

Downloads

82

Readme

securestack is a Comprehensive Authentication Package

A robust and flexible authentication solution for Node.js applications, providing a suite of security features to protect your web applications.

Table of Contents

  1. Features
  2. Installation
  3. Quick Start
  4. Documentation
  5. Examples
  6. Contributing
  7. License

Features

  • Auth Helpers: Password hashing, JWT token generation and verification, authentication and authorization middleware.
  • Password Policy: Customizable password strength enforcement, including length, character types, and common password checks.
  • Password Reset: Secure token generation and verification for password reset functionality.
  • Session Management: Flexible session handling with support for various storage backends.
  • Two-Factor Authentication: TOTP-based two-factor authentication with QR code generation and backup codes.
  • XSS Protection: Content sanitization and CSP header generation to prevent cross-site scripting attacks.
  • SQL Injection Prevention: Tools for creating parameterized queries and sanitizing user inputs.
  • Rate Limiting: Configurable rate limiting to prevent abuse and brute-force attacks.
  • Secure Headers: Easy setup for security-related HTTP headers.

Installation

npm install securestack

Quick Start

Here's a basic example of how to use some of the core features:

const express = require("express");
const { AuthHelpers, SessionManager, XssProtector } = require("securestack");

const app = express();
const authHelpers = new AuthHelpers();
const sessionManager = new SessionManager();
const xssProtector = new XssProtector();

app.use(express.json());
app.use(sessionManager.middleware());

// XSS protection middleware
app.use((req, res, next) => {
  const cspHeader = xssProtector.generateCspHeader({
    defaultSrc: ["'self'"],
    scriptSrc: ["'self'", "'unsafe-inline'"],
    styleSrc: ["'self'", "'unsafe-inline'"],
  });
  res.setHeader("Content-Security-Policy", cspHeader);
  next();
});

// User registration
app.post("/register", async (req, res) => {
  const { username, password } = req.body;
  const hashedPassword = await authHelpers.hashPassword(password);
  // Save user to database
  res.json({ message: "User registered successfully" });
});

// User login
app.post(
  "/login",
  authHelpers.authenticate(async (username) => {
    // Fetch user from database
    // Return user object or null if not found
  }),
  async (req, res) => {
    const session = await sessionManager.createSession(req.user.id, {
      role: req.user.role,
    });
    res.json({ message: "Logged in successfully", sessionId: session.id });
  }
);

// Protected route
app.get("/profile", authHelpers.authorize("user"), (req, res) => {
  res.json({ user: req.session.userId, role: req.session.data.role });
});

app.listen(3000, () => console.log("Server running on port 3000"));

Documentation

For detailed information on each feature, please refer to the following documentation:

Examples

For comprehensive examples of how to use this package in both server-side and client-side projects, check out our Examples Guide.

Contributing

We welcome contributions soon! Stay tuned for details on how to submit pull requests, report issues, and suggest improvements.

License

This project is licensed under the MIT License. LICENSE

Disclaimer

This software is provided "as is," and does not guarantee complete protection against all security threats. Users should implement additional security measures and keep their systems updated, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository and we will review and fix accordingly.