Repository navigation
[BUG] Dynamic rules, agent wiring and the custom response modifier diverge from the reference #83
Copy link
Copy link
Closed
Labels
area: engineTouches src/Engine/, src/Config/, or src/Routing/Touches src/Engine/, src/Config/, or src/Routing/bugConfirmed defectConfirmed defect
Description
Value this delivers
A dashboard dynamic rule changes protection in PHP exactly as it does in the Python reference, and the agent wiring and the response modifier work from config alone.
What happened
I compared the PHP engine with the Python reference (guard-core master at 859ac345, which includes guard-core #169) for dynamic rules, the agent wiring and custom_response_modifier. They diverge:
ip_blacklistIPs are merged into the static blacklist andip_whitelistIPs into the static whitelist (src/Rules/DynamicRuleManager.php,ruleFields). The reference bans the blacklist IPs forip_ban_durationseconds and unbans the whitelist IPs (_dynamic_rule_application.py,_apply_ip_bansand_apply_ip_whitelist).ip_ban_durationis parsed and never applied.block_cloud_providers,blocked_user_agentsandendpoint_rate_limitsare appended or merged with the base values and unknown providers are not filtered. The reference replaces them with the validated list (an all-invalid list empties it) and drops unknown providers.global_rate_windowis applied without aglobal_rate_limit. Emergency mode only halves the auto-ban threshold when the whitelist is empty or the rule carries a threshold; the reference always halves it. Country rules with no geo resolver fail the whole rule; the reference warns and skips them.- A failed application restores the base config instead of the previously active version, and
suspicious_patternsalready in the pool are added again on every version (guard-core #169). - The
emergency_mode_activatedevent is never sent, and thedynamic_rule_updatedanddynamic_rule_appliedenvelopes do not match the reference (handler name, reason, metadata). SecurityConfig::with()dropsenableAgent,enableDynamicRules,agentEnableEvents,agentEnableMetricsanddynamicRulesCachePath, so every installed dynamic config silently loses them, and consecutive candidates carry the same revision so the pipeline is not rebuilt.- Wiring: nothing in
srcinstantiatesDynamicRuleManager, soenableDynamicRulesis inert.enableAgentis accepted and never stored, and the reference validation (enable_dynamic_rulesandenable_enrichmentneedenable_agent) is missing. There is nodynamic_rule_interval.GuardResponseFactorytakes a modifier that nothing passes, andSecurityConfighas nocustom_response_modifierfield. The guard-agent-phpDynamicRulesobject is not accepted by the manager. - The last-known snapshot renders the timestamp as
+00:00instead ofZand an emptyendpoint_rate_limitsas a list. - Docs and examples still say
enableAgentfails config validation and that dynamic rules are unsupported, anddocs/usage.mdsays the metrics collector persists to Redis although the engine builds it without a Redis handler.
Steps to reproduce
- Build
new SecurityConfig(enableAgent: true, enableDynamicRules: true)and aGuardEngine, attach an agent handler withsetAgentHandler(), and callinitialize(): no manager exists and no rule is ever fetched. - Drive a
DynamicRuleManagerby hand with emergency rules v1 to v3 over a baseautoBanThresholdof 16 and fail a later version: the config falls back to the base, not to the last applied version. - Deliver
ip_blacklistwithip_ban_duration: the IP is in$config->blacklist, not banned for the duration.
Versions
guard-core-php master at fcbbb30, PHP 8.5 on macOS (the divergences are version independent).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: engineTouches src/Engine/, src/Config/, or src/Routing/Touches src/Engine/, src/Config/, or src/Routing/bugConfirmed defectConfirmed defect
Activity
fix(dynamic-rules): apply rules over the base config and wire the age…