AnonymousSpottedToad/securityPatternsRecovery / ground_truth /python /limit_request_rate__dchrnv_neurograph.json
| { | |
| "role_mappings": [ | |
| { | |
| "patternRole": "Entity", | |
| "entity": "_request", | |
| "file": "python-client/neurograph/client.py", | |
| "lines": "102", | |
| "notes": "In-repo SDK NeuroGraphClient._request sends HTTP requests to the NeuroGraph API (e.g. TokensAPI.create -> POST /api/v1/tokens, client.py:224) which pass through the Enforcer dispatch (src/api/middlewares/rate_limit.py:178); _handle_error_response (client.py:174) maps the Enforcer's 429 to RateLimitError.", | |
| "status": "present", | |
| "nodeId": null | |
| }, | |
| { | |
| "patternRole": "Enforcer", | |
| "entity": "dispatch", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "lines": "178", | |
| "notes": "RateLimitMiddleware.dispatch, registered via app.add_middleware(RateLimitMiddleware, ...) at src/api/main.py:114, intercepts every incoming HTTP request (health exempt), derives the id via get_user_id (rate_limit.py:110: user/API-key prefix/IP), asks the bucket's consume (line 191) and returns 429 with Retry-After when blocked, else call_next (line 225).", | |
| "status": "present", | |
| "nodeId": null | |
| }, | |
| { | |
| "patternRole": "Limiter", | |
| "entity": "consume", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "lines": "37", | |
| "notes": "Called by Enforcer dispatch at rate_limit.py:191. TokenBucket.consume refills tokens by elapsed time up to capacity and returns True (allow) if a token is available, False (block) otherwise; it also updates the bucket state (tokens/last_update).", | |
| "status": "present", | |
| "nodeId": null | |
| }, | |
| { | |
| "patternRole": "HistoryProvider", | |
| "entity": "get_bucket", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "lines": "133", | |
| "notes": "Called by Enforcer dispatch at rate_limit.py:188 to fetch the per-id TokenBucket from the in-memory dict self.buckets (declared line 105) and record last_access; the bucket's tokens/last_update are the request history consumed and updated by Limiter consume (line 37). Stale buckets pruned by cleanup_old_buckets (line 155).", | |
| "status": "present", | |
| "nodeId": null | |
| }, | |
| { | |
| "patternRole": "PolicyProvider", | |
| "entity": "get_bucket", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "lines": "133", | |
| "notes": "Same method as HistoryProvider: when creating a bucket, get_bucket (reached from dispatch at rate_limit.py:188) selects the policy per id type (ip_ -> ip_rate_limit, apikey_/user -> default_rate_limit, lines 138-147), which becomes the bucket capacity used by consume. Policy values configured at src/api/main.py:116-117 (100 / 30).", | |
| "status": "present", | |
| "nodeId": null | |
| }, | |
| { | |
| "patternRole": "System", | |
| "entity": "create_token", | |
| "file": "src/api/routers/tokens.py", | |
| "lines": "138", | |
| "notes": "Representative protected handler reached via call_next (rate_limit.py:225) after the Enforcer allows the request; POST /api/v1/tokens (router included at src/api/main.py:147) is the endpoint the SDK Entity calls via TokensAPI.create. All other /api/v1 routers are guarded the same way.", | |
| "status": "present", | |
| "nodeId": null | |
| } | |
| ], | |
| "interaction_order": { | |
| "available": true, | |
| "language": "python", | |
| "repo": "dchrnv_neurograph", | |
| "reason": "", | |
| "entryRole": "Enforcer", | |
| "entryRule": "behaviour", | |
| "interactions": [ | |
| { | |
| "rank": 1, | |
| "interaction": "Enforcer \u2192 PolicyProvider", | |
| "from": "Enforcer", | |
| "to": "PolicyProvider", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "line": 188, | |
| "via": [], | |
| "mechanism": "call", | |
| "path": [ | |
| { | |
| "caller": "src/api/middlewares/rate_limit.py:<module>.RateLimitMiddleware.dispatch", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "line": 188, | |
| "code": "self.get_bucket(user_id)", | |
| "callee": "src/api/middlewares/rate_limit.py:<module>.RateLimitMiddleware.get_bucket", | |
| "mechanism": "call" | |
| } | |
| ], | |
| "parent": "" | |
| }, | |
| { | |
| "rank": 2, | |
| "interaction": "Enforcer \u2192 HistoryProvider", | |
| "from": "Enforcer", | |
| "to": "HistoryProvider", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "line": 188, | |
| "via": [], | |
| "mechanism": "call", | |
| "path": [ | |
| { | |
| "caller": "src/api/middlewares/rate_limit.py:<module>.RateLimitMiddleware.dispatch", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "line": 188, | |
| "code": "self.get_bucket(user_id)", | |
| "callee": "src/api/middlewares/rate_limit.py:<module>.RateLimitMiddleware.get_bucket", | |
| "mechanism": "call" | |
| } | |
| ], | |
| "parent": "" | |
| }, | |
| { | |
| "rank": 3, | |
| "interaction": "Enforcer \u2192 Limiter", | |
| "from": "Enforcer", | |
| "to": "Limiter", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "line": 191, | |
| "via": [], | |
| "mechanism": "call", | |
| "path": [ | |
| { | |
| "caller": "src/api/middlewares/rate_limit.py:<module>.RateLimitMiddleware.dispatch", | |
| "file": "src/api/middlewares/rate_limit.py", | |
| "line": 191, | |
| "code": "bucket.consume()", | |
| "callee": "src/api/middlewares/rate_limit.py:<module>.TokenBucket.consume", | |
| "mechanism": "call" | |
| } | |
| ], | |
| "parent": "" | |
| } | |
| ], | |
| "anchoredRoles": [ | |
| { | |
| "role": "Enforcer", | |
| "kind": "METHOD" | |
| }, | |
| { | |
| "role": "HistoryProvider", | |
| "kind": "METHOD" | |
| }, | |
| { | |
| "role": "Limiter", | |
| "kind": "METHOD" | |
| }, | |
| { | |
| "role": "PolicyProvider", | |
| "kind": "METHOD" | |
| } | |
| ], | |
| "skippedRoles": [ | |
| "Entity", | |
| "System" | |
| ] | |
| } | |
| } |
Xet Storage Details
- Size:
- 5.85 kB
- Xet hash:
- a7d2b017320a2c3ce747e631be14fa7ef5911c0791245581fb1205bbfe91feac
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.