{"result":{"depiction_url":null,"edges":{"observes":{"objects":[{"created":"2026-11-12T13:54:57Z","object_id":{"id":1466,"is_a":["text","documentation","reference","notification"],"name":"doc_notification_admin_menu","title":"observe_admin_menu\/3","uri":"https:\/\/zotonic.com\/id\/1466"},"seq":1},{"created":"2026-11-12T13:54:57Z","object_id":{"id":2158,"is_a":["text","documentation","reference","notification"],"name":"doc_notification_m_config_update","title":"observe_m_config_update\/2","uri":"https:\/\/zotonic.com\/id\/2158"},"seq":2},{"created":"2026-11-12T13:54:57Z","object_id":{"id":2319,"is_a":["text","documentation","reference","notification"],"name":"doc_notification_middleware","title":"observe_middleware\/3","uri":"https:\/\/zotonic.com\/id\/2319"},"seq":3}],"predicate":{"id":2550,"is_a":["meta","predicate"],"name":"observes","title":{"_type":"trans","tr":{"en":"Observes"}},"uri":"https:\/\/zotonic.com\/id\/observes"}},"subject":{"objects":[{"created":"2026-11-12T13:54:57Z","object_id":{"id":2555,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_reference","title":"Reference","uri":"https:\/\/zotonic.com\/id\/2555"},"seq":1},{"created":"2026-11-12T13:54:57Z","object_id":{"id":2564,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_backend_developer","title":"Backend developer","uri":"https:\/\/zotonic.com\/id\/2564"},"seq":2},{"created":"2026-11-12T13:54:57Z","object_id":{"id":2566,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_operator","title":"Operator","uri":"https:\/\/zotonic.com\/id\/2566"},"seq":3},{"created":"2026-11-12T13:54:57Z","object_id":{"id":2607,"is_a":["categorization","keyword","keyword_domain"],"name":"zotonic_topic_logging_and_monitoring","title":"Logging and monitoring","uri":"https:\/\/zotonic.com\/id\/2607"},"seq":4},{"created":"2026-11-12T13:54:57Z","object_id":{"id":2635,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_module","title":"Module","uri":"https:\/\/zotonic.com\/id\/2635"},"seq":5},{"created":"2026-11-12T13:54:57Z","object_id":{"id":2685,"is_a":["categorization","keyword","keyword_quality"],"name":"zotonic_topic_security","title":"Security","uri":"https:\/\/zotonic.com\/id\/2685"},"seq":6},{"created":"2026-11-12T13:54:57Z","object_id":{"id":2688,"is_a":["categorization","keyword","keyword_quality"],"name":"zotonic_topic_performance","title":"Performance","uri":"https:\/\/zotonic.com\/id\/2688"},"seq":7}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"export_revision":82,"id":3192,"is_a":["text","documentation","reference","module"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/3192"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_module_mod_traffic_guard","page_url":{"en":"https:\/\/zotonic.com\/docs\/3192\/mod_traffic_guard","x-default":"https:\/\/zotonic.com\/docs\/3192\/mod_traffic_guard"},"preview_url":null,"resource":{"version":56,"pivot_location_lat":null,"title":"mod_traffic_guard","is_authoritative":true,"body":"<p>Traffic Guard detects and limits excessive requests from individual IP addresses.\nIt protects a site from rapid crawling and repeated page requests, including\nclients that present themselves as ordinary browsers. It starts in <strong>observe<\/strong>\nmode, recording decisions without rejecting requests.<\/p>\n<h2>When to use it<\/h2>\n<p>Use Traffic Guard to limit excessive origin requests without browser challenges,\ncookies or user-agent verification. It does not require <code>mod_analytics<\/code>.<\/p>\n<p>Limits are shared by all covered requests from one IP on one site and node.\nOffices, carrier NAT and proxies share an allowance, so inspect observe-mode\nresults before enforcing. Configure trusted proxies correctly: client addresses\ncome from Cowmachine&#39;s trusted-proxy processing. This is not a DDoS firewall;\ndistributed attacks still need proxy-level protection.<\/p>\n<h2>Getting started<\/h2>\n<ol><li>Enable <code>mod_traffic_guard<\/code> in the site&#39;s Modules screen. Leave the default\nmode at <code>observe<\/code> initially.<\/li><li>Open <strong>System → Traffic guard<\/strong> to inspect currently limited addresses and\nmanage IP exceptions.<\/li><li>Use <strong>Settings<\/strong> on the Traffic guard screen to tune all five site settings, then\nset <code>mode<\/code> to <code>enforce<\/code> when the observed decisions are appropriate.<\/li><\/ol>\n<p>For example, the default settings allow an initial burst of 30 requests per IP\nand replenish two request credits per second. Reloading the same page consumes\nthe same allowance as visiting different pages.<\/p>\n<h2>Configuration and usage<\/h2>\n<table class=\"table\"><thead><tr><th>Key<\/th><th>Default<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>mode<\/code><\/td><td><code>observe<\/code><\/td><td><code>off<\/code>, <code>observe<\/code> or <code>enforce<\/code>.<\/td><\/tr><tr><td><code>period<\/code><\/td><td><code>60<\/code><\/td><td>Rate period in seconds (1–3600).<\/td><\/tr><tr><td><code>request_limit<\/code><\/td><td><code>120<\/code><\/td><td>Request credits replenished per period (1–100000).<\/td><\/tr><tr><td><code>request_burst<\/code><\/td><td><code>30<\/code><\/td><td>Maximum request credits (1–1000).<\/td><\/tr><tr><td><code>max_clients<\/code><\/td><td><code>5000<\/code><\/td><td>Retained client budgets per site\/node (1–50000).<\/td><\/tr><\/tbody><\/table>\n<p><strong>observe<\/strong> allows requests and reports <code>would_throttle<\/code> when the rate limit would\nreject them. <strong>enforce<\/strong> rejects excess requests with HTTP 429, <code>Retry-After<\/code> and\nno-cache headers. <strong>off<\/strong> bypasses checks and guard analytics. Rejected requests\ndo not consume more credits; clients recover automatically. Invalid settings use\nthe defaults. Rate-setting changes reset transient budgets.<\/p>\n<h3>IP exceptions<\/h3>\n<p>Use <strong>System → Traffic guard<\/strong> to add or edit exact IPv4\/IPv6 addresses, with a\nrequired note and optional UTC expiry. Each site list supports up to 256 entries.\nSeparate addresses with spaces, commas or newlines. Invalid entries reject the\nwhole save. IPv4-mapped IPv6 addresses match IPv4 entries; CIDR ranges and hostnames\nare not supported.<\/p>\n<p>Allow entries take precedence over blocks and bypass the request-rate limit.\nBlocks follow the configured mode and only affect guarded routes and methods.\nChoose an hour, day, week, 30-day month, forever or an explicit UTC deadline.\nExpired entries stop applying immediately. Rule edits preserve other clients&#39;\nbudgets and throttling evidence.<\/p>\n<p>The current-throttling panel shows up to 200 addresses on this node, including\nobserve-mode decisions. <strong>Block IP<\/strong> creates a timed block with a note derived\nfrom the displayed evidence. Both panels require administrator access; writes\nalso require credentials that are not read-only. See <code>m_traffic_guard<\/code> for APIs.<\/p>\n<p>Global <code>traffic_guard_allow<\/code> and <code>traffic_guard_block<\/code> lists in <code>zotonic.config<\/code>\nare merged whenever site settings load. They are permanent, appear read-only in\nthe admin page, and cannot be removed by deleting site entries. Allow precedence\nalso applies across global and site rules. The README includes configuration examples.<\/p>\n<h2>Request coverage and behavior<\/h2>\n<p>The guard covers GET\/HEAD requests to page, template, HTTP model API and agent\ninterface controllers. Custom controllers classified as pages by analytics\n(<code>{analytics, page}<\/code>) are also covered, without requiring analytics collection.\nUse <code>{traffic_guard, true}<\/code> to opt another controller in, or <code>{traffic_guard, false}<\/code>\nto exempt a route. POST requests and MQTT messages are not covered; static assets\nare not covered by default.<\/p>\n<p>There are no automatic administrator or self-declared crawler exemptions.\nCookies and user-agent changes cannot reset an IP&#39;s allowance. Limits are\nnode-local, not cluster-wide; clients rotating IP addresses can evade them.<\/p>\n<p>If rate-limit admission is unavailable, overloaded or at client capacity, requests\nfail open with an unknown assessment. Explicit IP-rule hits use a separate lookup\nand bypass the admission worker. Unknown does not mean a suspected crawler.<\/p>\n<h2>Analytics<\/h2>\n<p>With <code>mod_analytics<\/code> enabled, the default Page requests chart adds <strong>Would throttle<\/strong>\nand <strong>Throttled<\/strong> lines for <code>other<\/code> and <code>unknown<\/code> page attempts, including early\nrejections. A companion recording preserves existing page-view history and starts\ncollecting guard history when created. It reserves 10,734 group\/time slots within\nthe site budget. Attempts overlap with page views; do not add their totals.<\/p>\n<p>For additional breakdowns, record <code>mod_traffic_guard:request<\/code>. Dimensions include\n<code>crawl_behavior<\/code> (normal, excessive, unknown), <code>guard_action<\/code> (allow,\nwould_throttle, throttle), <code>guard_reason<\/code> (none, request_rate, state_capacity,\nunavailable, ip_allow, ip_block), <code>traffic<\/code>, and <code>type<\/code> (page, api, other).\nOrdinary request events also receive the three guard dimensions when assessed.\nAnalytics exclusions and consent still apply; enforcement is independent of them.\nAnalytics events contain no client IPs or raw paths.<\/p>\n<h2>Implementation and lifecycle<\/h2>\n<p>One admission worker per site serializes request-rate accounting. Its bounded,\ntransient client state contains IP addresses and budgets, not paths, query strings\nor cookies. Idle clients expire after their budgets could recover; a restart clears\nrate-limit state.<\/p>\n<p>IP exceptions persist in the site&#39;s <code>traffic_guard_ip<\/code> table. Requests check a\nsite-isolated named ETS table directly, with allow precedence. A separate supervised\nprocess removes expired entries every second; lookups also check deadlines, so\ncleanup cannot prolong a rule&#39;s validity. The admission worker retains indexed\nrules as a fallback while the shared table loads. Hourly maintenance deletes\nexpired database rows. The README contains failure limits, benchmarks and\nregression-test commands.<\/p>","slug":"mod_traffic_guard","doc_module_config":[{"default":"&lt;&lt;&quot;observe&quot;&gt;&gt;","description":"off, observe or enforce. Observe reports excess without blocking.","has_default":true,"key":"mode","module":"mod_traffic_guard","type":"string"},{"default":"60","description":"Rate period in seconds (1..3600).","has_default":true,"key":"period","module":"mod_traffic_guard","type":"integer"},{"default":"120","description":"Sustained requests per period (1..100000).","has_default":true,"key":"request_limit","module":"mod_traffic_guard","type":"integer"},{"default":"30","description":"Immediate request allowance (1..1000).","has_default":true,"key":"request_burst","module":"mod_traffic_guard","type":"integer"},{"default":"5000","description":"Maximum retained client budgets per site and node (1..50000).","has_default":true,"key":"max_clients","module":"mod_traffic_guard","type":"integer"}],"is_protected":false,"visible_for":0,"tz":"UTC","language":["en"],"doc_source_hash":"08c64a7f34d2c3f027c2e8d97511f411363a9fcebd4c94790c527681e2e9add4","is_featured":false,"content_group_id":{"id":2551,"is_a":["meta","content_group"],"name":"content_group_imported_docs","title":"Imported documentation","uri":"https:\/\/zotonic.com\/id\/content_group_imported_docs"},"category_id":{"id":320,"is_a":["meta","category"],"name":"module","title":"Modules","uri":"https:\/\/test.zotonic.com\/id\/320"},"doc_source_path":"apps\/zotonic_mod_traffic_guard\/src\/mod_traffic_guard.erl","publication_start":"2026-11-12T13:54:57Z","github_url":"https:\/\/github.com\/zotonic\/zotonic\/blob\/master\/apps\/zotonic_mod_traffic_guard\/src\/mod_traffic_guard.erl","pivot_location_lng":null,"doc_source_kind":"module","name":"doc_module_mod_traffic_guard","is_unfindable":false,"is_published":true,"pivot_geocode":null,"created":"2026-11-12T13:54:57Z","uri":null,"doc_status":"current","is_dependent":false,"erlang_app":"zotonic_mod_traffic_guard","publication_end":"9999-06-01T00:00:00Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"privacy":0,"doc_source_commit":"a11194569d649b61f4592348100d0c2089d58fa2\n","creator_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"modified":"2026-12-04T13:31:10Z","title_slug":"mod_traffic_guard"},"uri":"https:\/\/zotonic.com\/id\/3192","uri_template":"https:\/\/zotonic.com\/id\/:id","version":82,"websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/3192"}},"status":"ok"}