privacy-analytics-waf-skilllisted
Install: claude install-skill 4ntiDandruff/zero-bloat-skills
# Privacy Analytics & Lightweight WAF Skill
Zero-cookie, privacy-friendly visitor analytics engine persisting directly to local SQLite WAL tables without third-party tracking scripts, coupled with a bounded in-memory sliding-window Web Application Firewall (WAF) circuit breaker.
---
## 1. The Cost of Third-Party Trackers
- Commercial tracking scripts (Google Tag Manager, Meta Pixel) introduce 200-500ms of external network latency to initial page loads.
- They leak user IP addresses and browsing habits to corporate advertising platforms.
- They are frequently blocked by browser extensions and local DNS sinkholes (AdGuard Home, Pi-hole), distorting actual traffic metrics.
---
## 2. Lightweight SQLite Analytics Schema (`visitors.db`)
Collect actionable metrics using anonymized hashes without storing sensitive personal information:
```sql
CREATE TABLE IF NOT EXISTS page_views (
id INTEGER PRIMARY KEY AUTOINCREMENT,
path TEXT NOT NULL,
user_agent_hash TEXT NOT NULL,
ip_prefix TEXT NOT NULL, -- Only store subnet prefix (e.g., 192.168.1.0/24)
referer TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_path_time ON page_views(path, timestamp);
```
---
## 3. Bounded WAF Rate-Limiting Middleware (Anti-Memory Leak)
Unbounded dictionaries (`REQUEST_BUCKET = {}`) without active key eviction lead to catastrophic Out-Of-Memory (OOM) crashes on web servers facing scraper swarms.
```python
import time
from fastapi import Req