agentleFS
zahidoverflowzahidoverflow/viperclaw/skills/viper-openapi-rest-schema/SKILL.md

viper-openapi-rest-schema

Skill22 starsChanged 15 days agoMITView on GitHub

OpenAPI / Swagger Schema, Mass Assignment & REST API Security Auditor (OWASP API3 & API4). Reviews DTO allowlisting, pagination caps, and schema validation.

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 106
  4. Distinctive:

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

    line 107

≈ “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

OpenAPI Schema, Mass Assignment (BOPLA) & REST API Contract Auditor (viper-openapi-rest-schema)

1. Executive Scope, Standards & CWE/OWASP Mapping

  • Frameworks & Standards: OWASP API3:2023 (Broken Object Property Level Authorization), OWASP API4:2023, OpenAPI v3.1 Specification, CWE-915
  • Primary CWE Mapping: CWE-915 (Improperly Controlled Modification of Dynamically-Determined Object Attributes / Mass Assignment), CWE-213 (Exposure of Sensitive Information Due to Incompatible Policies / Excessive Data Exposure)
  • ViperClaw MCP Tools: viper_taint_scan, viper_diff_oracle, viper_verify_and_report
  • ViperClaw CLI Command: viperclaw taint ./src --db .viperclaw/graph.db

2. Threat Model & Root-Cause Architecture

flowchart LR
  Client["Client JSON Request"] --> InDTO["Strict Input DTO (additionalProperties: false)"] --> ORM["Explicit Field Mapping"] --> OutDTO["Redacted Output DTO Serializer"]

Root-Cause Analysis

REST controllers bind raw request JSON directly into database ORM objects (User(**req.json), Object.assign(entity, req.body)), allowing callers to overwrite protected columns (role, is_admin, tenant_id, email_verified, balance), or return raw ORM entities that serialize password_hash, mfa_secret, and PII.


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 "(\*\*request\.(json|get_json)|Object\.assign\(user,\s*req\.body|Model\.create\(req\.body)"
rg -n "(swagger-ui|openapi\.json|/docs|/redoc|api-docs)"
rg -n "(extra\s*=\s*.allow.|additionalProperties\s*:\s*true)"

4. Senior Security Engineer 8-Point Audit Checklist

Control IDAudit Verification TargetPass CriteriaFail / Vulnerability Indicator
API-01Input DTO Property Allowlisting (No Mass Assignment)Every POST/PUT/PATCH route binds to a dedicated Input DTO that explicitly lists editable user fields and sets extra='forbid' / additionalProperties: false.ORM model updated directly from req.body or request.json.
API-02Output Serializer DTO (No Excessive Data Exposure)Every read/list endpoint serializes through an explicit Output DTO that excludes password_hash, mfa_secret, reset_token, and internal metadata.Controller returns raw database row (SELECT * / return db_user) to the JSON serializer.
API-03Pagination & Batch Size Caps (OWASP API4)List endpoints enforce 1 <= limit <= 100 and cap maximum offset or use cursor pagination.GET /api/users?limit=10000000 allowed, exhausting database memory and worker threads.
API-04Production Swagger / OpenAPI UI Access ControlInteractive /docs, /redoc, /swagger-ui.html, and /openapi.json are disabled in production or gated behind internal authentication.Unauthenticated /swagger-ui in production exposing internal admin and debug endpoints.
API-05Strict JSON Type & Bound ValidationStrings enforce minLength/maxLength and regex patterns; numbers enforce minimum/maximum and reject NaN/Infinity.Unbounded 50MB string field or negative numeric value accepted by API schema.
API-06API Version Lifecycle & Shadow API RetirementLegacy API versions (/api/v1/*, /api/beta/*) are decommissioned or share the exact same auth/rate-limit middleware as /api/v2/*.Deprecated /api/v1/login remains online without MFA or rate limiting.
API-07JSON Patch (application/json-patch+json) Path GuardIf RFC 6902 JSON Patch is used, path pointers (/role, /tenantId) are validated against an editable field allowlist.Unfiltered [{ "op": "replace", "path": "/isAdmin", "value": true }] applied to entity.
API-08Uniform 401/403/422 Error SchemaValidation errors (422) do not echo back internal server configuration or full raw database constraints.Pydantic/Hibernate error response leaks internal class paths or SQL constraint names.

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
CRITICAL (9.1)CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:NMass assignment on user profile/registration overwriting role: "admin", is_superuser: true, or tenant_id.
HIGH (7.5)CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:NExcessive data exposure returning password_hash, api_key, or mfa_secret in /api/users response.
MEDIUM (5.3)CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:LUncapped pagination (limit=999999) or exposed internal Swagger documentation.

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

# ❌ VULNERABLE: Updates ORM user directly from raw dict & returns full ORM model (with password_hash!)
@router.patch("/users/me")
def update_me(req_body: dict, user: User = Depends(get_current_user), db: Session = Depends(get_db)):
    for k, v in req_body.items():
        setattr(user, k, v)  # Untrusted caller sends {"is_admin": True, "balance": 999999}
    db.commit()
    return user

# ✅ HARDENED: Strict Input DTO (extra='forbid') + Explicit Output DTO
class UserUpdateInput(BaseModel):
    model_config = ConfigDict(extra="forbid")
    display_name: str = Field(min_length=1, max_length=80)
    bio: str = Field(default="", max_length=500)

class UserPublicOutput(BaseModel):
    id: UUID
    display_name: str
    bio: str

@router.patch("/users/me", response_model=UserPublicOutput)
def update_me(req_body: UserUpdateInput, user: User = Depends(get_current_user), db: Session = Depends(get_db)):
    user.display_name = req_body.display_name
    user.bio = req_body.bio
    db.commit()
    return user

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.