1.0.0 • Published 5 months ago

security-gateway v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Security Gateway

A plug-and-play security gateway that detects malicious traffic and redirects it to a decoy API. This middleware/gateway sits between your clients and your actual API to protect against various types of attacks.

Features

  • Attack Detection: Identifies SQL injection, XSS, path traversal, and command injection attempts
  • Traffic Redirection: Redirects suspicious traffic to a decoy API
  • Rate Limiting: Prevents brute force attacks
  • Honeypot Features: Adds misleading headers and response data
  • Admin Dashboard: Real-time monitoring of suspicious activities
  • Configurable: Easy configuration via environment variables or options object
  • Docker Support: Ready-to-use Docker configuration for quick deployment

Installation

npm install security-gateway

Usage

As a standalone gateway

The simplest way to use Security Gateway is as a standalone service:

// server.js
const createSecurityGateway = require('security-gateway');

const gateway = createSecurityGateway({
  server: {
    port: 3000
  },
  endpoints: {
    realApi: "http://your-real-api.com",
    decoyApi: "http://your-decoy-api.com"
  }
});

gateway.start().then(() => {
  console.log('Security Gateway is running!');
});

As Express middleware

You can also use it as middleware in an existing Express application:

const express = require('express');
const createSecurityGateway = require('security-gateway');

const app = express();
const gateway = createSecurityGateway();

// Use the gateway's app as middleware
app.use(gateway.app);

app.listen(3000, () => {
  console.log('Application with Security Gateway is running on port 3000');
});

Using Docker Compose

For a quick setup with Docker:

  1. Clone this repository
  2. Configure your environment variables in a .env file (see .env.example)
  3. Run with Docker Compose:
docker-compose up -d

Configuration

You can configure the Security Gateway using environment variables or by passing an options object.

Available Options

OptionEnvironment VariableDefaultDescription
server.portPORT3000Port for the gateway server
server.logFormatLOG_FORMATcombinedMorgan log format
endpoints.realApiAPI_URLhttp://localhost:8080URL of your real API
endpoints.decoyApiDECOY_URLhttp://localhost:8081URL of the decoy API
endpoints.adminDashboardADMIN_DASHBOARD_PATH/admin/dashboardPath to access the admin dashboard
security.rateLimit.enabledRATE_LIMIT_ENABLEDtrueEnable/disable rate limiting
security.rateLimit.maxRATE_LIMIT_MAX100Maximum requests per time window
security.rateLimit.windowMsRATE_LIMIT_WINDOW_MS900000Time window in milliseconds (15 minutes)
security.attackPatterns.sqlInjectionDETECT_SQL_INJECTIONtrueEnable SQL injection detection
security.attackPatterns.xssDETECT_XSStrueEnable XSS detection
security.attackPatterns.pathTraversalDETECT_PATH_TRAVERSALtrueEnable path traversal detection
security.attackPatterns.commandInjectionDETECT_COMMAND_INJECTIONtrueEnable command injection detection
security.honeypot.addHeadersADD_HONEYPOT_HEADERStrueAdd fake server headers
security.honeypot.modifyResponsesMODIFY_RESPONSEStrueAdd honeypot data to responses

Admin Dashboard

Access the admin dashboard at /admin/dashboard (or your configured path) to monitor:

  • Suspicious IP addresses
  • Attack history
  • Real-time statistics

Creating a Decoy API

The Security Gateway redirects suspicious traffic to a decoy API. You can use the included decoy-api.js file as a starting point or create your own.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.