Skip to content
Back to skills

Collection

ASecurity

Enterprise SSRF protection with URL validation and network segmentation

  • 24 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 8, 2026
devopstypescriptpythonrustgobashdockerawstestingapisecurity

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add mattnigh/skills_collection --skill collection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattnigh-collection-d6020fc9/badge)](https://www.skillsdirectory.com/skills/mattnigh-collection-d6020fc9)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: moai-security-ssrf
version: 4.0.0
updated: 2025-11-20
status: stable
description: Enterprise SSRF protection with URL validation and network segmentation
allowed-tools: [Read, Bash, WebSearch, WebFetch]
---

# SSRF Protection Expert

**Server-Side Request Forgery (SSRF) Prevention**

> **Focus**: URL Validation, Allowlisting, Network Segmentation  
> **Stack**: Python (urllib/ipaddress), TypeScript (URL API)

---

## Overview

Comprehensive defense strategies against SSRF attacks where an attacker induces the server to make requests to unintended locations.

### Core Defense Layers

1.  **Input Validation**: Strict allowlisting of domains and protocols.
2.  **Network Layer**: Blocking access to internal/private IP ranges (10.0.0.0/8, 127.0.0.1, etc.).
3.  **Application Layer**: Disabling redirects, validating response types.
4.  **Infrastructure**: Running services in isolated network environments.

---

## Implementation Patterns

### 1. Robust URL Validator (Python)

Validates URLs against allowlists and blocks private IP ranges (including DNS rebinding protection).

```python
import socket
import ipaddress
from urllib.parse import urlparse

class SSRFValidator:
    def __init__(self, allowed_domains=None):
        self.allowed_domains = allowed_domains or []
        self.blocked_networks = [
            ipaddress.ip_network('10.0.0.0/8'),
            ipaddress.ip_network('172.16.0.0/12'),
            ipaddress.ip_network('192.168.0.0/16'),
            ipaddress.ip_network('127.0.0.0/8'),
            ipaddress.ip_network('169.254.0.0/16'), # Cloud metadata
        ]

    def validate(self, url: str) -> bool:
        try:
            parsed = urlparse(url)

            # 1. Protocol Check
            if parsed.scheme not in ('http', 'https'):
                return False

            # 2. Domain Allowlist Check
            if self.allowed_domains and parsed.hostname not in self.allowed_domains:
                return False

            # 3. DNS Resolution & IP Check (Anti-DNS Rebinding)
            # Note: In production, use the resolved IP for the actual request
            ip_str = socket.gethostbyname(parsed.hostname)
            ip_addr = ipaddress.ip_address(ip_str)

            for network in self.blocked_networks:
                if ip_addr in network:
                    return False

            return True
        except Exception:
            return False

# Usage
validator = SSRFValidator(allowed_domains=['api.example.com', 'google.com'])
is_safe = validator.validate("https://169.254.169.254/latest/meta-data/") # False
```

### 2. Secure HTTP Client (Python)

Making requests safely using the validation logic.

```python
import requests
from requests.adapters import HTTPAdapter

class SecureClient:
    def __init__(self, validator):
        self.validator = validator
        self.session = requests.Session()
        self.session.mount('https://', HTTPAdapter(max_retries=3))

    def get(self, url: str, **kwargs):
        # 1. Validate URL first
        if not self.validator.validate(url):
            raise ValueError(f"Blocked potentially unsafe URL: {url}")

        # 2. Disable redirects to prevent open redirect bypasses
        kwargs['allow_redirects'] = False

        # 3. Set reasonable timeout
        kwargs.setdefault('timeout', 5.0)

        return self.session.get(url, **kwargs)
```

### 3. Network Segmentation (Infrastructure)

Ensure the application server cannot route to sensitive internal services.

**AWS Security Group (Outbound Rules)**:

- **Allow**: 0.0.0.0/0 (Internet) on port 80/443
- **Deny**: 10.0.0.0/8 (VPC Internal)
- **Deny**: 169.254.169.254/32 (Instance Metadata)

**Docker Network**:

```yaml
services:
  app:
    networks:
      - public_net
    # Isolate from internal services

networks:
  public_net:
    internal: false
```

---

## Security Best Practices

1.  **Allowlist over Blocklist**: Always prefer explicitly allowing known good domains over trying to block bad ones.
2.  **Disable Redirects**: Attackers often use open redirects on trusted domains to bypass filters.
3.  **Validate Response**: Check `Content-Type` and response size to prevent DoS or unexpected parsing.
4.  **Use Dedicated Parsers**: Don't use regex for URL parsing; use standard libraries (`urllib`, `URL`).

---

## Validation Checklist

- [ ] **Protocols**: Only `http` and `https` allowed? (No `file://`, `gopher://`)
- [ ] **Internal IPs**: 127.0.0.1, 10.x.x.x, 192.168.x.x blocked?
- [ ] **Cloud Metadata**: 169.254.169.254 blocked?
- [ ] **Redirects**: Disabled or strictly validated?
- [ ] **DNS**: Resolved IP checked against blocklist?

---

## Related Skills

- `moai-security-devsecops`: Security testing
- `moai-cloud-aws-advanced`: AWS network security
- `moai-security-encryption`: Secure communication

---

**Last Updated**: 2025-11-20

Files in this skill

  • 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md15.1 KB
  • 17hz__nextjs-template__claude__skills__example-skill__SKILL.md316 B
  • 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md3.5 KB
  • 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md5.4 KB
  • 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md7.7 KB
  • 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md26.1 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md15.7 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md17.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md9.4 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md12.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md16.6 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md11.2 KB
  • 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md14.8 KB
  • 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md16.2 KB
  • 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md11.8 KB
  • 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md17.5 KB
  • 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md19.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md6.2 KB
  • 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md18.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md24.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in devops →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.