Skip to content

Tonyjnr/apishield

Repository files navigation

๐Ÿ›ก๏ธ APIShield

Fast, lightweight API security scanner for indie developers.

APIShield analyzes your OpenAPI/Swagger specs and catches common security issues before they reach production. Perfect for CI/CD pipelines, pre-commit hooks, and local development.

npm version License: MIT


โœจ Features

  • ๐Ÿ” Multi-format support: OpenAPI 3.x, Swagger 2.0, Postman Collections, HAR files, YAML & JSON
  • ๐ŸŒ Live URL scanning: Scan APIs directly from URLs
  • ๐Ÿšจ Security checks: Missing auth, sensitive data exposure, excessive data leakage
  • โšก Lightning fast: Scans in milliseconds, perfect for CI/CD
  • โš™๏ธ Configurable: Custom sensitive fields, path ignore patterns, rule settings
  • ๐Ÿ›๏ธ Compliance modes: GDPR, CCPA, HIPAA, PCI-DSS regulatory scanning
  • ๐Ÿ›ก๏ธ Threat modeling: STRIDE-based security education and impact analysis
  • ๐ŸŽจ Beautiful output: Color-coded issues with actionable fixes
  • ๐Ÿ”ง CI-friendly: Exits with error code on issues

๐Ÿš€ Quick Start

Installation

# Global installation (recommended)
npm install -g @tonyjnr/apishield

# Or use with npx (no install needed)
npx @tonyjnr/apishield scan openapi.yaml

Usage

# Scan an OpenAPI 3 file
apishield scan openapi.yaml

# Scan a Swagger 2.0 file
apishield scan swagger.json

# Scan a Postman Collection
apishield scan collection.postman_collection.json

# Scan a HAR file
apishield scan requests.har

# Scan a live API URL
apishield scan https://api.example.com/openapi.json

# Verbose mode
apishield scan api-spec.yaml --verbose

# Compliance mode (GDPR, CCPA, HIPAA, PCI)
apishield scan api-spec.yaml --compliance gdpr

# Threat modeling report (STRIDE-based)
apishield scan api-spec.yaml --threat-model

๐Ÿ“‹ What It Checks

๐Ÿ”’ Missing Authentication

Detects endpoints without security schemes (excludes common public paths like /login, /register, /public/*, /health)

# โŒ Will flag this
/admin/users:
  get:
    responses: ...
    # No security defined!

# โœ… This is good
/admin/users:
  get:
    security:
      - bearerAuth: []
    responses: ...

๐Ÿ‘๏ธ Sensitive Data Exposure

Scans response schemas for fields that shouldn't be exposed:

  • Passwords (password, passwd, pwd)
  • Tokens (token, apiKey, secret)
  • Personal data (ssn, creditCard, cvv, dob)
  • Private keys (privateKey, private_key)
# โŒ Will flag this
/users/{id}:
  get:
    responses:
      "200":
        content:
          application/json:
            schema:
              properties:
                username: string
                password: string # ๐Ÿšจ EXPOSED!

๐Ÿ“Š Excessive Data Exposure

Warns when endpoints return too many fields (>20), suggesting pagination or field filtering to reduce attack surface.

# โŒ Will flag this (51 fields!)
/users/{id}:
  get:
    responses:
      "200":
        content:
          application/json:
            schema:
              properties:
                id: string
                username: string
                email: string
                password: string
                firstName: string
                lastName: string
                # ... 45 more fields!

Output:

โ€ข Excessive data exposure
  โ†’ GET /users/{id} returns 51 fields in response
  ๐Ÿ’ก Reduce response fields or implement field filtering (e.g., ?fields=id,name)

๐Ÿ›๏ธ Compliance Mode

APIShield supports regulatory compliance scanning to help you meet specific legal requirements:

Supported Frameworks

  • GDPR (--compliance gdpr) - European data protection
  • CCPA (--compliance ccpa) - California privacy rights
  • HIPAA (--compliance hipaa) - Healthcare data protection
  • PCI-DSS (--compliance pci) - Payment card industry standards

How It Works

Compliance mode filters findings to show only fields regulated by the specified framework:

# Standard mode - shows ALL sensitive fields
apishield scan api.yaml

# GDPR mode - shows only GDPR-regulated fields
apishield scan api.yaml --compliance gdpr

Example Output

Standard Mode:

โ€ข Sensitive data exposed in response
  โ†’ GET /users/{id} returns: email, phone, password, credit_card, ssn
  ๐Ÿ’ก Remove or mask sensitive fields from the response schema.

GDPR Mode:

โ€ข GDPR compliance violation
  โ†’ GET /users/{id} exposes GDPR-regulated data: email, phone, ssn
  ๐Ÿ’ก Remove or mask GDPR-regulated fields from the response schema.

Field Classifications

Category GDPR CCPA HIPAA PCI-DSS
Personal Info (email, phone, address) โœ… โœ… โŒ โŒ
Financial Data (credit_card, cvv) โŒ โœ… โŒ โœ…
Health Data (medical_record) โœ… โœ… โœ… โŒ
Authentication (password, token) โŒ โŒ โŒ โœ…

Input (api.yaml):

openapi: 3.0.0
paths:
  /users/{id}:
    get:
      responses:
        "200":
          content:
            application/json:
              schema:
                properties:
                  id: string
                  username: string
                  password: string

Output:


๐Ÿšจ High Severity Issues (2):

1. Missing authentication
   Endpoint GET /users/{id} has no security scheme defined.
   ๐Ÿ’ก Add a 'security' block to the operation or global spec.

2. Sensitive data exposed in response
   GET /users/{id} returns: password
   ๐Ÿ’ก Remove or mask sensitive fields from the response schema.

๐Ÿ“Š Summary: 2 issue(s) detected
   High: 2 | Medium: 0

๐Ÿ”ง CI/CD Integration

GitHub Actions

name: API Security Scan
on: [push, pull_request]

jobs:
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
      - run: npx @tonyjnr/apishield scan openapi.yaml

Pre-commit Hook

# .husky/pre-commit
npx @tonyjnr/apishield scan openapi.yaml

GitLab CI

api_security:
  script:
    - npx @tonyjnr/apishield scan openapi.yaml

๐Ÿ›ก๏ธ Threat Modeling Report

APIShield can generate STRIDE-based threat models to help you understand the real-world security implications of your API issues.

What is STRIDE?

STRIDE is a threat modeling framework that categorizes security threats:

  • Spoofing - Impersonation attacks
  • Tampering - Data modification attacks
  • Repudiation - Denial of actions
  • Information Disclosure - Data leakage
  • Denial of Service - Service disruption
  • Elevation of Privilege - Unauthorized access

How It Works

Instead of just listing issues, threat modeling explains the attacker impact and provides educational context:

# Standard mode - simple issue list
apishield scan api.yaml

# Threat modeling mode - educational threat analysis
apishield scan api.yaml --threat-model

Example Output

Standard Mode:

โš ๏ธ  Found 3 security issue(s):

โ€ข Missing authentication
  โ†’ Endpoint GET /users/{id} has no security scheme defined.
  ๐Ÿ’ก Add a 'security' block to the operation or global spec.

โ€ข Sensitive data exposed in response
  โ†’ GET /users/{id} returns: email, phone, password
  ๐Ÿ’ก Remove or mask sensitive fields from the response schema.

Threat Modeling Mode:

๐Ÿ›ก๏ธ  APIShield Threat Model Report

๐Ÿ“‹ SPOOFING
1 threat(s) identified

1. Missing authentication
   โ†’ Endpoint GET /users/{id} has no security scheme defined.
   Impact: An attacker can access or modify resources without authentication.
   OWASP: API1:2023 - Broken Object Level Authorization
   ๐Ÿ”ง Fix: Add a 'security' block to the operation or global spec.

๐Ÿ“‹ INFORMATION DISCLOSURE
1 threat(s) identified

1. Sensitive data exposed in response
   โ†’ GET /users/{id} returns: email, phone, password
   Impact: PII, secrets, or internal data may be leaked to unauthorized parties.
   OWASP: API3:2023 - Excessive Data Exposure
   ๐Ÿ”ง Fix: Remove or mask sensitive fields from the response schema.

๐Ÿ“Š Threat Summary
Total threats: 2
   High: 2

Benefits

  • ๐ŸŽ“ Educational: Learn why each issue matters
  • ๐ŸŽฏ Contextual: Understand attacker motivations
  • ๐Ÿ“š Standards-aligned: Maps to OWASP API Security Top 10
  • ๐Ÿ” Categorized: Groups threats by STRIDE category
  • ๐Ÿ“Š Summarized: Shows threat severity breakdown

โš™๏ธ Configuration

Create a config.apishield.json file in your project root to customize scanning behavior:

{
  "ignorePaths": ["/health", "/metrics", "/version", "/internal/*"],
  "customSensitiveFields": [
    "internal_token",
    "legacy_password",
    "webhook_secret"
  ],
  "rules": {
    "missingAuth": "error",
    "sensitiveData": "error"
  }
}

Configuration Options

  • ignorePaths: Array of path patterns to skip during scanning (supports * wildcards)
  • customSensitiveFields: Additional field names to flag as sensitive
  • rules: Control rule severity (error, warn, off)

๐Ÿ—บ๏ธ Roadmap

Phase 1 (Completed - v0.5.x)

  • โœ… OpenAPI 3.x support
  • โœ… Swagger 2.0 support
  • โœ… JSON & YAML parsing
  • โœ… Basic security checks
  • โœ… Postman Collection support
  • โœ… HAR file analysis
  • โœ… Live URL scanning
  • โœ… Custom rule configuration

Phase 2 (v0.6.x) - Coming Soon

  • ๐Ÿ”œ Enhanced sensitive field detection
  • ๐Ÿ”œ More security rule types
  • ๐Ÿ”œ Better error reporting
  • ๐Ÿ”œ Performance optimizations

Phase 3 (v0.7.x)

  • ๐Ÿ”ฎ GraphQL schema support
  • ๐Ÿ”ฎ AI-powered test generation
  • ๐Ÿ”ฎ Web dashboard
  • ๐Ÿ”ฎ Team collaboration features

๐Ÿค Contributing

Found a bug? Have an idea? Contributions welcome!

# Clone the repo
git clone https://github.com/tonyjnr/apishield.git
cd apishield

# Install dependencies
npm install

# Test locally
node index.js scan petstore.json

๐Ÿ“– Supported Formats

Format Extension Status
OpenAPI 3.0 .yaml, .yml, .json โœ… Full support
OpenAPI 3.1 .yaml, .yml, .json โœ… Full support
Swagger 2.0 .json, .yaml โœ… Full support
Postman Collection .postman_collection.json โœ… Full support
HAR Files .har โœ… Full support
Live URLs https://, http:// โœ… Full support
GraphQL .graphql ๐Ÿ”œ Phase 3

๐Ÿ’ก Why APIShield?

Most API security tools are:

  • ๐Ÿข Enterprise-focused (expensive, complex)
  • ๐ŸŒ Slow (require full environment setup)
  • ๐Ÿ”Œ Runtime-only (catch issues too late)

APIShield is different:

  • ๐Ÿ†“ Free and open source
  • โšก Instant feedback (static analysis)
  • ๐ŸŽฏ Built for indie devs & small teams
  • ๐Ÿ”„ CI/CD native

๐Ÿ“ License

MIT ยฉ Onuzulike Anthony Ifechukwu


๐Ÿ™ Acknowledgments

Inspired by the OWASP API Security Top 10 and built for the indie dev community.

Made with โค๏ธ for developers who ship fast but secure.


๐Ÿ“ฌ Support


Star โญ this repo if APIShield helps secure your APIs!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published