Skip to main content
Glama
README.md
# portwhy

[![CI](https://github.com/lostprotocol212/portwhy/actions/workflows/ci.yml/badge.svg)](https://github.com/lostprotocol212/portwhy/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![Zero Dependencies](https://img.shields.io/badge/dependencies-0-emerald.svg)](#) [![SARIF 2.1.0](https://img.shields.io/badge/SARIF-2.1.0-orange.svg)](#) [![MCP Ready](https://img.shields.io/badge/MCP-stdio-purple.svg)](#mcp-mode)

Cross-platform zero-dependency listening socket tracer, **`docker-compose.yml` static port scanner**, and **Docker-bypasses-UFW** security auditor with SARIF 2.1.0 output and ready-to-apply `DOCKER-USER` / `nftables` remediation.

![portwhy preview](assets/demo.svg)

---

## Why Docker Silently Bypasses UFW

```mermaid
flowchart LR
  Internet["Public Internet"] --> PREROUTING["iptables PREROUTING NAT"]
  PREROUTING -->|"Published Container Port (0.0.0.0:5432)"| DOCKER["DOCKER Chain (BYPASSES UFW INPUT!)"]
  PREROUTING -->|"Host Socket"| UFW["UFW INPUT Rules (Enforced)"]
  DOCKER --> Guard["Fix: DOCKER-USER DROP or 127.0.0.1 Bind"]
```

---

## Quickstart (Zero Install)

```bash
# Audit live listening sockets on Linux (ss/docker/ufw), macOS (lsof), or Windows (netstat)
npx portwhy

# Statically audit docker-compose.yml in CI/CD before deploy
npx portwhy compose docker-compose.yml --fail-on high

# Emit SARIF 2.1.0 for GitHub Code Scanning
npx portwhy compose docker-compose.yml --sarif > portwhy.sarif

# Print ready-to-apply /etc/ufw/after.rules DOCKER-USER or nftables rules
npx portwhy --ufw-fix
npx portwhy --nft-fix
```

## MCP Mode & GitHub Action

```json
{ "mcpServers": { "portwhy": { "command": "npx", "args": ["portwhy@1.2.0", "--mcp"] } } }
```

```yaml
- uses: lostprotocol212/portwhy@v1
  with:
    compose-file: 'docker-compose.yml'
    fail-on: 'high'
    sarif-output: 'portwhy.sarif'
```

Interactive auditor + Network Designer export: [serversareup.com/tools/docker-ufw-port-auditor](https://serversareup.com/tools/docker-ufw-port-auditor).