Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

securenx

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

securenx

A comprehensive authentication and security solution

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-78.57%
Maintainers
0
Weekly downloads
 
Created
Source

Securenx 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 securenx

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("securenx");

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.


Keywords

FAQs

Package last updated on 02 Sep 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc