{
"event": "PreToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "\/tmp\/bot-config-fix.sql",
"content": "-- ============================================================\n-- Bot Config Fix: PROD (karlkratz_de)\n-- ============================================================\n\n-- 1. Clean stale rows in PROD\nDELETE FROM karlkratz_de.tenant_config WHERE section='bot' AND config_key IN (\n 'whitelist.ips', 'whitelist.user_agents', 'whitelist.user_agent_patterns',\n 'bot.whitelist.ips', 'bot.whitelist.user_agents', 'bot.whitelist.user_agent_patterns',\n 'bot.settings'\n);\n\n-- 2. Update whitelist with comprehensive patterns\nUPDATE karlkratz_de.tenant_config SET config_value = '{\"ips\":[\"144.76.103.30\",\"148.251.27.17\",\"148.251.27.18\",\"127.0.0.1\",\"::1\",\"66.249.64.0\/19\",\"66.249.96.0\/19\",\"72.14.199.0\/24\",\"209.85.238.0\/24\",\"207.46.0.0\/16\",\"40.77.167.0\/24\",\"157.55.39.0\/24\",\"199.16.156.0\/22\",\"208.65.144.0\/20\",\"17.0.0.0\/8\"],\"user_agents\":[\"Googlebot\",\"Bingbot\",\"Slurp\",\"DuckDuckBot\",\"Applebot\",\"facebookexternalhit\",\"Twitterbot\",\"LinkedInBot\",\"WhatsApp\",\"Telegram\",\"karlsCORE\"],\"user_agent_patterns\":[\"Google.*Bot\",\"Googlebot\",\"FeedFetcher-Google\",\"Google-Read-Aloud\",\"Google-InspectionTool\",\"Google-Site-Verification\",\"Bing.*Bot\",\"Yahoo.*Slurp\",\"Applebot\",\"DuckDuckBot\",\"facebookexternalhit\",\"Twitterbot\",\"LinkedInBot\",\"Pinterest\",\"WhatsApp\",\"TelegramBot\",\"Slackbot\",\"GPTBot\",\"ChatGPT-User\",\"ClaudeBot\",\"Claude-Web\",\"anthropic-ai\",\"PerplexityBot\",\"OAI-SearchBot\",\"UptimeRobot\",\"Pingdom\",\"GTmetrix\",\"PageSpeed\",\"Lighthouse\",\"W3C_Validator\",\"Feedly\",\"Feedbin\"]}' WHERE section='bot' AND config_key='whitelist';\n\n-- 3. Insert actions config\nINSERT INTO karlkratz_de.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'actions', '{\"block_request\":true,\"add_to_ufw\":false,\"log_attempt\":true,\"return_403\":true,\"return_404\":false}', 'all');\n\n-- 4. Insert blacklist config\nINSERT INTO karlkratz_de.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'blacklist', '{\"user_agents\":[\"AhrefsBot\",\"SemrushBot\",\"MJ12bot\",\"DotBot\",\"SiteAuditBot\",\"SEOkicks\",\"BLEXBot\",\"YandexBot\",\"PetalBot\",\"Sogou\",\"Baiduspider\",\"360Spider\",\"CCBot\",\"DataForSeoBot\",\"MegaIndex\",\"AspiegelBot\",\"Awario\",\"SEObility\",\"SurdotlyBot\",\"ZoominfoBot\",\"CensysInspect\",\"Nuclei\",\"gobuster\",\"sqlmap\",\"nmap\",\"masscan\",\"ZGrab\",\"Shodan\",\"censys\",\"BinaryEdge\"],\"user_agent_patterns\":[\".*[Ss]crape.*\",\".*penetration.*\",\".*vulnerability.*\",\".*security.*scan.*\",\".*hack.*\",\".*exploit.*\"]}', 'all');\n\n-- 5. Insert rate_limiting config\nINSERT INTO karlkratz_de.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'rate_limiting', '{\"enabled\":true,\"primary\":{\"requests_per_minute\":45,\"burst_requests\":12,\"burst_window_seconds\":5},\"levels\":{\"gentle\":{\"requests\":30,\"window_seconds\":60,\"action\":\"log_warning\",\"penalty_duration\":0},\"moderate\":{\"requests\":60,\"window_seconds\":60,\"action\":\"temporary_delay\",\"penalty_duration\":30},\"aggressive\":{\"requests\":90,\"window_seconds\":60,\"action\":\"temporary_block\",\"penalty_duration\":300},\"severe\":{\"requests\":150,\"window_seconds\":60,\"action\":\"block\",\"penalty_duration\":3600}},\"tolerance_multipliers\":{\"authenticated_users\":1.5,\"known_browsers\":1.3,\"mobile_apps\":1.2,\"api_clients\":0.8,\"unknown\":0.6,\"suspected_bots\":0.3}}', 'all');\n\n\n-- ============================================================\n-- Bot Config Fix: DEV (karlkratz_de_dev)\n-- ============================================================\n\n-- 1. Clean stale rows in DEV\nDELETE FROM karlkratz_de_dev.tenant_config WHERE section='bot' AND config_key IN (\n 'whitelist.ips', 'whitelist.user_agents', 'whitelist.user_agent_patterns',\n 'bot.whitelist.ips', 'bot.whitelist.user_agents', 'bot.whitelist.user_agent_patterns',\n 'bot.settings'\n);\n\n-- 2. Update whitelist (same as PROD)\nUPDATE karlkratz_de_dev.tenant_config SET config_value = '{\"ips\":[\"144.76.103.30\",\"148.251.27.17\",\"148.251.27.18\",\"127.0.0.1\",\"::1\",\"66.249.64.0\/19\",\"66.249.96.0\/19\",\"72.14.199.0\/24\",\"209.85.238.0\/24\",\"207.46.0.0\/16\",\"40.77.167.0\/24\",\"157.55.39.0\/24\",\"199.16.156.0\/22\",\"208.65.144.0\/20\",\"17.0.0.0\/8\"],\"user_agents\":[\"Googlebot\",\"Bingbot\",\"Slurp\",\"DuckDuckBot\",\"Applebot\",\"facebookexternalhit\",\"Twitterbot\",\"LinkedInBot\",\"WhatsApp\",\"Telegram\",\"karlsCORE\"],\"user_agent_patterns\":[\"Google.*Bot\",\"Googlebot\",\"FeedFetcher-Google\",\"Google-Read-Aloud\",\"Google-InspectionTool\",\"Google-Site-Verification\",\"Bing.*Bot\",\"Yahoo.*Slurp\",\"Applebot\",\"DuckDuckBot\",\"facebookexternalhit\",\"Twitterbot\",\"LinkedInBot\",\"Pinterest\",\"WhatsApp\",\"TelegramBot\",\"Slackbot\",\"GPTBot\",\"ChatGPT-User\",\"ClaudeBot\",\"Claude-Web\",\"anthropic-ai\",\"PerplexityBot\",\"OAI-SearchBot\",\"UptimeRobot\",\"Pingdom\",\"GTmetrix\",\"PageSpeed\",\"Lighthouse\",\"W3C_Validator\",\"Feedly\",\"Feedbin\"]}' WHERE section='bot' AND config_key='whitelist';\n\n-- 3. Insert actions config\nINSERT INTO karlkratz_de_dev.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'actions', '{\"block_request\":true,\"add_to_ufw\":false,\"log_attempt\":true,\"return_403\":true,\"return_404\":false}', 'all');\n\n-- 4. Insert blacklist config\nINSERT INTO karlkratz_de_dev.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'blacklist', '{\"user_agents\":[\"AhrefsBot\",\"SemrushBot\",\"MJ12bot\",\"DotBot\",\"SiteAuditBot\",\"SEOkicks\",\"BLEXBot\",\"YandexBot\",\"PetalBot\",\"Sogou\",\"Baiduspider\",\"360Spider\",\"CCBot\",\"DataForSeoBot\",\"MegaIndex\",\"AspiegelBot\",\"Awario\",\"SEObility\",\"SurdotlyBot\",\"ZoominfoBot\",\"CensysInspect\",\"Nuclei\",\"gobuster\",\"sqlmap\",\"nmap\",\"masscan\",\"ZGrab\",\"Shodan\",\"censys\",\"BinaryEdge\"],\"user_agent_patterns\":[\".*[Ss]crape.*\",\".*penetration.*\",\".*vulnerability.*\",\".*security.*scan.*\",\".*hack.*\",\".*exploit.*\"]}', 'all');\n\n-- 5. Insert rate_limiting config\nINSERT INTO karlkratz_de_dev.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'rate_limiting', '{\"enabled\":true,\"primary\":{\"requests_per_minute\":45,\"burst_requests\":12,\"burst_window_seconds\":5},\"levels\":{\"gentle\":{\"requests\":30,\"window_seconds\":60,\"action\":\"log_warning\",\"penalty_duration\":0},\"moderate\":{\"requests\":60,\"window_seconds\":60,\"action\":\"temporary_delay\",\"penalty_duration\":30},\"aggressive\":{\"requests\":90,\"window_seconds\":60,\"action\":\"temporary_block\",\"penalty_duration\":300},\"severe\":{\"requests\":150,\"window_seconds\":60,\"action\":\"block\",\"penalty_duration\":3600}},\"tolerance_multipliers\":{\"authenticated_users\":1.5,\"known_browsers\":1.3,\"mobile_apps\":1.2,\"api_clients\":0.8,\"unknown\":0.6,\"suspected_bots\":0.3}}', 'all');\n"
}
}
{
"tool_response": {
"type": "create",
"filePath": "\/tmp\/bot-config-fix.sql",
"content": "-- ============================================================\n-- Bot Config Fix: PROD (karlkratz_de)\n-- ============================================================\n\n-- 1. Clean stale rows in PROD\nDELETE FROM karlkratz_de.tenant_config WHERE section='bot' AND config_key IN (\n 'whitelist.ips', 'whitelist.user_agents', 'whitelist.user_agent_patterns',\n 'bot.whitelist.ips', 'bot.whitelist.user_agents', 'bot.whitelist.user_agent_patterns',\n 'bot.settings'\n);\n\n-- 2. Update whitelist with comprehensive patterns\nUPDATE karlkratz_de.tenant_config SET config_value = '{\"ips\":[\"144.76.103.30\",\"148.251.27.17\",\"148.251.27.18\",\"127.0.0.1\",\"::1\",\"66.249.64.0\/19\",\"66.249.96.0\/19\",\"72.14.199.0\/24\",\"209.85.238.0\/24\",\"207.46.0.0\/16\",\"40.77.167.0\/24\",\"157.55.39.0\/24\",\"199.16.156.0\/22\",\"208.65.144.0\/20\",\"17.0.0.0\/8\"],\"user_agents\":[\"Googlebot\",\"Bingbot\",\"Slurp\",\"DuckDuckBot\",\"Applebot\",\"facebookexternalhit\",\"Twitterbot\",\"LinkedInBot\",\"WhatsApp\",\"Telegram\",\"karlsCORE\"],\"user_agent_patterns\":[\"Google.*Bot\",\"Googlebot\",\"FeedFetcher-Google\",\"Google-Read-Aloud\",\"Google-InspectionTool\",\"Google-Site-Verification\",\"Bing.*Bot\",\"Yahoo.*Slurp\",\"Applebot\",\"DuckDuckBot\",\"facebookexternalhit\",\"Twitterbot\",\"LinkedInBot\",\"Pinterest\",\"WhatsApp\",\"TelegramBot\",\"Slackbot\",\"GPTBot\",\"ChatGPT-User\",\"ClaudeBot\",\"Claude-Web\",\"anthropic-ai\",\"PerplexityBot\",\"OAI-SearchBot\",\"UptimeRobot\",\"Pingdom\",\"GTmetrix\",\"PageSpeed\",\"Lighthouse\",\"W3C_Validator\",\"Feedly\",\"Feedbin\"]}' WHERE section='bot' AND config_key='whitelist';\n\n-- 3. Insert actions config\nINSERT INTO karlkratz_de.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'actions', '{\"block_request\":true,\"add_to_ufw\":false,\"log_attempt\":true,\"return_403\":true,\"return_404\":false}', 'all');\n\n-- 4. Insert blacklist config\nINSERT INTO karlkratz_de.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'blacklist', '{\"user_agents\":[\"AhrefsBot\",\"SemrushBot\",\"MJ12bot\",\"DotBot\",\"SiteAuditBot\",\"SEOkicks\",\"BLEXBot\",\"YandexBot\",\"PetalBot\",\"Sogou\",\"Baiduspider\",\"360Spider\",\"CCBot\",\"DataForSeoBot\",\"MegaIndex\",\"AspiegelBot\",\"Awario\",\"SEObility\",\"SurdotlyBot\",\"ZoominfoBot\",\"CensysInspect\",\"Nuclei\",\"gobuster\",\"sqlmap\",\"nmap\",\"masscan\",\"ZGrab\",\"Shodan\",\"censys\",\"BinaryEdge\"],\"user_agent_patterns\":[\".*[Ss]crape.*\",\".*penetration.*\",\".*vulnerability.*\",\".*security.*scan.*\",\".*hack.*\",\".*exploit.*\"]}', 'all');\n\n-- 5. Insert rate_limiting config\nINSERT INTO karlkratz_de.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'rate_limiting', '{\"enabled\":true,\"primary\":{\"requests_per_minute\":45,\"burst_requests\":12,\"burst_window_seconds\":5},\"levels\":{\"gentle\":{\"requests\":30,\"window_seconds\":60,\"action\":\"log_warning\",\"penalty_duration\":0},\"moderate\":{\"requests\":60,\"window_seconds\":60,\"action\":\"temporary_delay\",\"penalty_duration\":30},\"aggressive\":{\"requests\":90,\"window_seconds\":60,\"action\":\"temporary_block\",\"penalty_duration\":300},\"severe\":{\"requests\":150,\"window_seconds\":60,\"action\":\"block\",\"penalty_duration\":3600}},\"tolerance_multipliers\":{\"authenticated_users\":1.5,\"known_browsers\":1.3,\"mobile_apps\":1.2,\"api_clients\":0.8,\"unknown\":0.6,\"suspected_bots\":0.3}}', 'all');\n\n\n-- ============================================================\n-- Bot Config Fix: DEV (karlkratz_de_dev)\n-- ============================================================\n\n-- 1. Clean stale rows in DEV\nDELETE FROM karlkratz_de_dev.tenant_config WHERE section='bot' AND config_key IN (\n 'whitelist.ips', 'whitelist.user_agents', 'whitelist.user_agent_patterns',\n 'bot.whitelist.ips', 'bot.whitelist.user_agents', 'bot.whitelist.user_agent_patterns',\n 'bot.settings'\n);\n\n-- 2. Update whitelist (same as PROD)\nUPDATE karlkratz_de_dev.tenant_config SET config_value = '{\"ips\":[\"144.76.103.30\",\"148.251.27.17\",\"148.251.27.18\",\"127.0.0.1\",\"::1\",\"66.249.64.0\/19\",\"66.249.96.0\/19\",\"72.14.199.0\/24\",\"209.85.238.0\/24\",\"207.46.0.0\/16\",\"40.77.167.0\/24\",\"157.55.39.0\/24\",\"199.16.156.0\/22\",\"208.65.144.0\/20\",\"17.0.0.0\/8\"],\"user_agents\":[\"Googlebot\",\"Bingbot\",\"Slurp\",\"DuckDuckBot\",\"Applebot\",\"facebookexternalhit\",\"Twitterbot\",\"LinkedInBot\",\"WhatsApp\",\"Telegram\",\"karlsCORE\"],\"user_agent_patterns\":[\"Google.*Bot\",\"Googlebot\",\"FeedFetcher-Google\",\"Google-Read-Aloud\",\"Google-InspectionTool\",\"Google-Site-Verification\",\"Bing.*Bot\",\"Yahoo.*Slurp\",\"Applebot\",\"DuckDuckBot\",\"facebookexternalhit\",\"Twitterbot\",\"LinkedInBot\",\"Pinterest\",\"WhatsApp\",\"TelegramBot\",\"Slackbot\",\"GPTBot\",\"ChatGPT-User\",\"ClaudeBot\",\"Claude-Web\",\"anthropic-ai\",\"PerplexityBot\",\"OAI-SearchBot\",\"UptimeRobot\",\"Pingdom\",\"GTmetrix\",\"PageSpeed\",\"Lighthouse\",\"W3C_Validator\",\"Feedly\",\"Feedbin\"]}' WHERE section='bot' AND config_key='whitelist';\n\n-- 3. Insert actions config\nINSERT INTO karlkratz_de_dev.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'actions', '{\"block_request\":true,\"add_to_ufw\":false,\"log_attempt\":true,\"return_403\":true,\"return_404\":false}', 'all');\n\n-- 4. Insert blacklist config\nINSERT INTO karlkratz_de_dev.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'blacklist', '{\"user_agents\":[\"AhrefsBot\",\"SemrushBot\",\"MJ12bot\",\"DotBot\",\"SiteAuditBot\",\"SEOkicks\",\"BLEXBot\",\"YandexBot\",\"PetalBot\",\"Sogou\",\"Baiduspider\",\"360Spider\",\"CCBot\",\"DataForSeoBot\",\"MegaIndex\",\"AspiegelBot\",\"Awario\",\"SEObility\",\"SurdotlyBot\",\"ZoominfoBot\",\"CensysInspect\",\"Nuclei\",\"gobuster\",\"sqlmap\",\"nmap\",\"masscan\",\"ZGrab\",\"Shodan\",\"censys\",\"BinaryEdge\"],\"user_agent_patterns\":[\".*[Ss]crape.*\",\".*penetration.*\",\".*vulnerability.*\",\".*security.*scan.*\",\".*hack.*\",\".*exploit.*\"]}', 'all');\n\n-- 5. Insert rate_limiting config\nINSERT INTO karlkratz_de_dev.tenant_config (section, config_key, config_value, environment) VALUES\n('bot', 'rate_limiting', '{\"enabled\":true,\"primary\":{\"requests_per_minute\":45,\"burst_requests\":12,\"burst_window_seconds\":5},\"levels\":{\"gentle\":{\"requests\":30,\"window_seconds\":60,\"action\":\"log_warning\",\"penalty_duration\":0},\"moderate\":{\"requests\":60,\"window_seconds\":60,\"action\":\"temporary_delay\",\"penalty_duration\":30},\"aggressive\":{\"requests\":90,\"window_seconds\":60,\"action\":\"temporary_block\",\"penalty_duration\":300},\"severe\":{\"requests\":150,\"window_seconds\":60,\"action\":\"block\",\"penalty_duration\":3600}},\"tolerance_multipliers\":{\"authenticated_users\":1.5,\"known_browsers\":1.3,\"mobile_apps\":1.2,\"api_clients\":0.8,\"unknown\":0.6,\"suspected_bots\":0.3}}', 'all');\n",
"structuredPatch": [],
"originalFile": null
}
}