agentleFS
zahidoverflowzahidoverflow/viperclaw/skills/viper-rate-limit-dos-resilience/SKILL.md

viper-rate-limit-dos-resilience

Skill22 starsChanged 16 days agoMITView on GitHub

Application Rate Limiting, ReDoS & Resource Exhaustion Auditor (OWASP API4:2023). Reviews credential throttling controls, regular expression complexity, and body-size/decompression limits.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run the following discovery commands across the target repository before manual code review:

    line 30
  2. Distinctive:

    Verify whether an upstream API Gateway, global middleware, or ORM hook already enforces the control before flagging a controller.

    line 62
  3. Distinctive:

    Write a Positive Unit Test confirming authorized, schema-valid requests succeed.

    line 96
  4. Distinctive:

    Write a Negative Security Regression Test confirming unauthorized, cross-tenant, or malformed inputs are deterministically rejected.

    line 97

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rate Limiting, ReDoS & Resource Exhaustion Resilience Auditor (viper-rate-limit-dos-resilience)

1. Executive Scope, Standards & CWE/OWASP Mapping

  • Frameworks & Standards: OWASP API4:2023 (Unrestricted Resource Consumption), OWASP Denial of Service Cheat Sheet, CWE-1333, CWE-400, CWE-307
  • Primary CWE Mapping: CWE-1333 (Inefficient Regular Expression Complexity / ReDoS), CWE-400 (Uncontrolled Resource Consumption), CWE-307 (Improper Restriction of Excessive Authentication Attempts)
  • ViperClaw MCP Tools: viper_taint_scan, viper_race_burst, viper_verify_and_report
  • ViperClaw CLI Command: viperclaw taint ./src --db .viperclaw/graph.db

2. Threat Model & Root-Cause Architecture

flowchart LR
  Req["Incoming Request"] --> Quota["Body Size + Rate-Limit Bucket"] --> Regex["Linear-Time Regex / Bounded Parser"] --> Exec["Timeout-Bounded Worker"]

Root-Cause Analysis

Single-request Denial of Service (DoS) occurs when a route evaluates a catastrophic backtracking regex (^([a-zA-Z0-9]+)+$) on a 50-character string (freezing the Python GIL or Node.js event loop for minutes), accepts multi-gigabyte request bodies or JSON/XML bodies without Content-Length caps, or allows unlimited credential-guessing attempts on 6-digit OTPs.


3. Deterministic Discovery & Grep/AST Audit Commands

Run the following discovery commands across the target repository before manual code review:

# 1. Automated ViperClaw analysis
viperclaw taint ./src --db .viperclaw/graph.db

# 2. Rapid static pattern discovery (ripgrep)
rg -n "re\.(compile|match|search|sub)\(.*(\+\)|\*\))[\+\*\{]"
rg -n "(MAX_CONTENT_LENGTH|client_max_body_size|bodyParser\.json\(\{.*limit)"
rg -n "(ratelimit|RateLimiter|SlowAPI|throttler)"

4. Senior Security Engineer 8-Point Audit Checklist

Control IDAudit Verification TargetPass CriteriaFail / Vulnerability Indicator
DOS-01Auth & OTP Credential-Throttling LimitsLogin, 2FA/OTP verification, and password reset enforce strict per-account AND per-IP rate limits (e.g., max 5 attempts per 15m before invalidating the OTP).6-digit OTP endpoint allows 1,000,000 requests without invalidating the code or locking out.
DOS-02Zero Catastrophic Backtracking Regexes (ReDoS)All regular expressions evaluated on user input avoid nested quantifiers ((a+)+, `(aaa)+, ([a-z]+)*), or use linear-time google-re2`.Email/URL validation regex uses ^([a-zA-Z0-9_\.-]+)+@... (freezes CPU on 32-char non-matching input).
DOS-03Request Body & Multipart Size CapsWeb server and framework enforce explicit body size limits (e.g., 1MB for JSON APIs, 10MB for uploads).Missing MAX_CONTENT_LENGTH allows a single POST of 2GB JSON to OOM-kill the worker pod.
DOS-04Expensive Operation & AI/Export QuotasPDF generation, CSV exports, password hashing, and LLM API routes enforce strict per-user concurrency and daily quota caps.Unthrottled /api/export-all or /api/chat route allows exhausting DB CPU or LLM billing.
DOS-05Password Input Length Cap Before Hashing (<= 128 bytes)Password strings are capped at <= 128 characters before passing to bcrypt / Argon2 / PBKDF2.Passing a 10MB password string into PBKDF2 / Argon2 blocks the worker thread for several seconds per request.
DOS-06Trusted Proxy IP Resolution for Rate LimitersRate limiters extract client IP from the rightmost trusted proxy hop, never an unvalidated client X-Forwarded-For header.Clients send arbitrary X-Forwarded-For: 1.2.3.4 headers to circumvent IP rate limiting.
DOS-07Database & Upstream Outbound TimeoutsEvery DB query (statement_timeout) and outbound HTTP/RPC call defines an explicit timeout (e.g., 3s–10s).requests.get(url) called without timeout=, hanging worker threads indefinitely when upstream stalls.
DOS-08JSON Nesting Depth & Array Length BoundsJSON parsers and schema validators cap maximum object nesting depth and array element counts.10,000-element array passed to a batch endpoint triggers $O(N^2)$ processing or 10,000 sequential DB queries.

5. False-Positive Elimination & CVSS v3.1 Triage Rubric

False-Positive Gate

  1. Verify whether an upstream API Gateway, global middleware, or ORM hook already enforces the control before flagging a controller.
  2. Confirm the code path is reachable from an external entrypoint (not dead code, CLI-only admin script, or unit-test fixture).
Severity TierBaseline CVSS v3.1 VectorQualifying Security Impact
HIGH (8.1)CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:NMissing rate limit and attempt cap on 4/6-digit OTP/reset code allowing trivial account takeover.
HIGH (7.5)CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:HUnauthenticated ReDoS regex or unbounded memory allocation crashing the application server in a single request.
MEDIUM (5.3)CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:LRate limit avoidable via untrusted X-Forwarded-For header or missing password max-length cap.

6. Production Remediation Patterns (Vulnerable vs. Hardened Code)

# ❌ VULNERABLE: Catastrophic backtracking regex (ReDoS) & uncapped password length into bcrypt
SLUG_RE = re.compile(r"^([a-z0-9]+(-[a-z0-9]+)*)+$")

def verify_login(slug: str, password: str, stored_hash: bytes) -> bool:
    if not SLUG_RE.match(slug):
        return False
    return bcrypt.checkpw(password.encode("utf-8"), stored_hash)

# ✅ HARDENED: Linear-time non-nested regex + strict input length caps before hashing
SLUG_RE = re.compile(r"^[a-z0-9]+(?:-[a-z0-9]+)*$")

def verify_login(slug: str, password: str, stored_hash: bytes) -> bool:
    if len(slug) > 64 or len(password) > 128 or not SLUG_RE.match(slug):
        return False
    return bcrypt.checkpw(password.encode("utf-8"), stored_hash)

7. Regression Testing & Continuous Verification

  1. Write a Positive Unit Test confirming authorized, schema-valid requests succeed.
  2. Write a Negative Security Regression Test confirming unauthorized, cross-tenant, or malformed inputs are deterministically rejected.
  3. Re-run viperclaw taint and viperclaw verify to confirm zero remaining unmitigated flows in .viperclaw/graph.db.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.