Buckets:

AnonymousSpottedToad/securityPatternsRecovery / ground_truth /python /limit_request_rate__cemde_WhatsNext.json
download
raw
5.5 kB
{
"role_mappings": [
{
"patternRole": "Entity",
"entity": "append_queue",
"file": "whatsnext/api/client/server.py",
"lines": "215",
"notes": "In-repo Python client SDK (Server class) sends HTTP requests to the WhatsNext FastAPI server; append_queue POSTs to /jobs (server.py:237), passing through RateLimitMiddleware.dispatch (middleware.py:85). Any Server method is an equivalent Entity; rate is keyed by client IP.",
"status": "present",
"nodeId": null
},
{
"patternRole": "Enforcer",
"entity": "dispatch",
"file": "whatsnext/api/server/middleware.py",
"lines": "85",
"notes": "dispatch in RateLimitMiddleware (Starlette BaseHTTPMiddleware), registered via app.add_middleware at main.py:50, intercepts every incoming request, identifies the client via _get_client_ip (middleware.py:71) and returns 429 with Retry-After or calls call_next. Caveat: only installed when settings.rate_limit_per_minute > 0, which defaults to 0 (disabled, warning logged at main.py:52).",
"status": "present",
"nodeId": null
},
{
"patternRole": "Limiter",
"entity": "dispatch",
"file": "whatsnext/api/server/middleware.py",
"lines": "85",
"notes": "Decision is inline in the Enforcer's dispatch (same method): middleware.py:97 compares the count of timestamps in the window with requests_per_minute and blocks or allows. No smaller helper makes the decision; _clean_old_requests (line 80) only prunes history.",
"status": "present",
"nodeId": null
},
{
"patternRole": "HistoryProvider",
"entity": "_clean_old_requests",
"file": "whatsnext/api/server/middleware.py",
"lines": "80",
"notes": "Called by dispatch at middleware.py:94; prunes and returns the sliding-window history in the in-memory dict request_times (per client IP, declared middleware.py:69). The update step is the inline append in dispatch at middleware.py:109 (only allowed requests recorded).",
"status": "present",
"nodeId": null
},
{
"patternRole": "PolicyProvider",
"entity": "rate_limit_per_minute",
"file": "whatsnext/api/server/config.py",
"lines": "26",
"notes": "No method supplies the policy: the limit is the pydantic Settings field rate_limit_per_minute (env/.env configurable, default 0), passed at main.py:50 into RateLimitMiddleware.__init__ (middleware.py:64) as requests_per_minute with a fixed 60s window_size; read by dispatch at middleware.py:97. Single global policy for all entities.",
"status": "present",
"nodeId": null
},
{
"patternRole": "System",
"entity": "add_job",
"file": "whatsnext/api/server/routers/jobs.py",
"lines": "46",
"notes": "After dispatch calls call_next (middleware.py:111), the request reaches the FastAPI routers included at main.py:63-66; for the traced client call (POST /jobs) this is add_job, which creates the job in the DB. All other routes are equally protected.",
"status": "present",
"nodeId": null
}
],
"interaction_order": {
"available": true,
"language": "python",
"repo": "cemde_WhatsNext",
"reason": "",
"entryRole": "Enforcer",
"entryRule": "behaviour",
"interactions": [
{
"rank": 1,
"interaction": "Enforcer \u2192 Limiter",
"from": "Enforcer",
"to": "Limiter",
"file": "whatsnext/api/server/middleware.py",
"line": 85,
"via": [],
"mechanism": "co-located",
"path": [],
"parent": ""
},
{
"rank": 2,
"interaction": "Enforcer \u2192 HistoryProvider",
"from": "Enforcer",
"to": "HistoryProvider",
"file": "whatsnext/api/server/middleware.py",
"line": 94,
"via": [],
"mechanism": "call",
"path": [
{
"caller": "whatsnext/api/server/middleware.py:<module>.RateLimitMiddleware.dispatch",
"file": "whatsnext/api/server/middleware.py",
"line": 94,
"code": "self._clean_old_requests(client_ip, current_time)",
"callee": "whatsnext/api/server/middleware.py:<module>.RateLimitMiddleware._clean_old_requests",
"mechanism": "call"
}
],
"parent": ""
},
{
"rank": 3,
"interaction": "Limiter \u2192 HistoryProvider",
"from": "Limiter",
"to": "HistoryProvider",
"file": "whatsnext/api/server/middleware.py",
"line": 94,
"via": [],
"mechanism": "call",
"path": [
{
"caller": "whatsnext/api/server/middleware.py:<module>.RateLimitMiddleware.dispatch",
"file": "whatsnext/api/server/middleware.py",
"line": 94,
"code": "self._clean_old_requests(client_ip, current_time)",
"callee": "whatsnext/api/server/middleware.py:<module>.RateLimitMiddleware._clean_old_requests",
"mechanism": "call"
}
],
"parent": ""
}
],
"anchoredRoles": [
{
"role": "Enforcer",
"kind": "METHOD"
},
{
"role": "HistoryProvider",
"kind": "METHOD"
},
{
"role": "Limiter",
"kind": "METHOD"
},
{
"role": "PolicyProvider",
"kind": "LOCAL"
}
],
"skippedRoles": [
"Entity",
"System"
]
}
}

Xet Storage Details

Size:
5.5 kB
·
Xet hash:
3a065629b2dda51bc3e5372581ce2ad0f86bbd1165a8c786cad062c686d19b8a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.