Behavior Manager¶
guard_core.handlers.behavior_handler.BehaviorTracker(config)
¶
Source code in guard_core/handlers/behavior_handler.py
agent_handler = None
instance-attribute
¶
config = config
instance-attribute
¶
logger = logging.getLogger('guard_core.handlers.behavior')
instance-attribute
¶
redis_handler = None
instance-attribute
¶
return_patterns = defaultdict(lambda: defaultdict(list))
instance-attribute
¶
usage_counts = defaultdict(lambda: defaultdict(list))
instance-attribute
¶
apply_action(rule, client_ip, endpoint_id, details)
async
¶
Source code in guard_core/handlers/behavior_handler.py
initialize_agent(agent_handler)
async
¶
initialize_redis(redis_handler)
async
¶
track_endpoint_usage(endpoint_id, client_ip, rule)
async
¶
Source code in guard_core/handlers/behavior_handler.py
track_return_pattern(endpoint_id, client_ip, response, rule)
async
¶
Source code in guard_core/handlers/behavior_handler.py
The Behavior Manager handles behavioral analysis for detecting suspicious usage patterns.
BehaviorRule¶
guard_core.handlers.behavior_handler.BehaviorRule(rule_type, threshold, window=3600, pattern=None, action='log', custom_action=None)
¶
Source code in guard_core/handlers/behavior_handler.py
Rule types: usage, return_pattern, frequency
Pattern formats: Simple string, JSON path (json:result.status==win), Regex (regex:win|victory), Status code (status:200)
Actions: ban, log, alert, throttle
Integration with Decorators¶
guard_deco = SecurityDecorator(config)
@guard_deco.usage_monitor(max_calls=10, window=3600, action="ban")
@guard_deco.return_monitor("rare_item", max_occurrences=3, window=86400, action="alert")
def rewards_endpoint(request):
return JsonResponse({"reward": "rare_item"})