Skip to content

Protection ​

Protection sets how hard the check is and how long a visitor's pass lasts. The check is the proof-of-work puzzle the visitor's browser solves. The pass is the signed cookie the browser gets afterward.

In the web UI, find it under Configure > Protection.

The Protection screen. The first card has the main switch, the default action and the difficulty.

These settings live under protection: in tamamo.yaml. A site can override any of them.

KeyWeb UIDefaultWhat it does
enabledProtect my sitetruefalse makes Tamamo a plain reverse proxy. Nothing is checked at all: no bypass header, rate limit, webhook, module or rule runs.
difficultyDifficulty level4Work per check, from 1 to 8. The environment variable TAMAMO_DIFFICULTY sets it only when Tamamo creates the file. See difficulty.
default_actionDefault actionchallengeWhat happens when no check, module or rule decides: allow, challenge, or block. Any other value becomes challenge.
pass_hoursVisitors stay verified for168How long a pass lasts, from 1 to 8760 hours.
challenge_minutesVisitors must finish the check within30How long a checking page stays valid, from 1 to 120 minutes.
bind_ipTie the pass to the visitor’s networktrueThe pass works only in the /24 (the first three numbers of an IPv4 address) or /64 (IPv6) network it was earned on. Mobile visitors may be asked again when their address changes. Turn this off when your visitors’ addresses change often, for example on mobile networks.
bind_user_agentTie the pass to the browsertrueThe pass works only in the browser that earned it. A browser update can trigger a new check.
cookie_nameCookie nametamamo-passLetters, digits, -, and _, up to 64 characters. Changing it signs every visitor out.
cookie_domainCookie domainemptyEmpty means the exact host name. Set example.com to share one pass across its subdomains.
max_failures_per_minuteMax failed attempts per minute30Failed checks allowed per IP address (per /64 for IPv6) in one minute. Over the limit, the address is refused until the minute ends. 0 turns the limit off.
unprotected_pathsUnprotected pagesemptyPages that are never checked at all. See unprotected pages.
verified_botsVerified botsoffConfirms that a visitor calling itself a search engine is one. See verified bots.
accept_passes_fromAccept passes from these sitesemptyFor an API on another domain than its website. See An API on another domain.
bypass_headersBypass headersemptySecret headers that skip every check. See bypass headers.
rate_limitRate limitoffRequests one address may make in a time window. See rate limit.
webhooksWebhooksemptyYour own HTTP services that decide about requests. See Webhooks.

Difficulty ​

Each level asks for about 16 times the work of the level below. Keep level 4 unless bots keep getting through. Then raise it one level at a time and watch the Activity screen.

LevelNameAverage hashesPhoneLaptop
1Barely there16under 1 msunder 1 ms
2Very light256under 1 msunder 1 ms
3Light4,09610 ms3 ms
4Balanced65,536164 ms44 ms
5Firm1,048,5762.6 s0.7 s
6Strong16,777,21642 s11 s
7Very strong268,435,45611 min3 min
8Extreme4,294,967,296about 3 hoursabout 48 min

The times assume 400,000 hashes per second on a phone and 1,500,000 on a laptop, the rates the web UI uses. Some visitors wait two or three times longer than the estimate.

Level 6 and up make phone visitors wait tens of seconds or more, so use them only during short attacks. Raising the level also invalidates passes earned at a lower level.

default_action ​

The default action runs only when no check, module or rule decides. challenge is the safe choice. API clients and feed readers that cannot run JavaScript fail the check, so allow them with a rule. allow lets unmatched requests through, and block refuses them. The default rules end with a catch-all, so this setting rarely matters. See Rules.

Checks before the rules ​

These are built into Tamamo and run on every request before any rule, in this order. All of them are optional and off until you set them up.

  1. Unprotected pages
  2. Bypass headers
  3. Verified bots
  4. The rate limit
  5. Webhooks

After them come the modules, then the rules. The first one that decides wins and the rest are skipped. In the web UI, they are the cards under Before the rules on the Protection screen.

The Before the rules part of the Protection screen, with the Bypass headers and Rate limit cards

Unprotected pages ​

A list of pages Tamamo lets through without looking at anything else. No check, rate limit, webhook, module or rule runs for them. Use it for files that everything must be able to fetch, such as robots.txt.

Put unprotected_paths: under the protection: key you already have in data/tamamo.yaml:

yaml
protection:
  unprotected_paths:
    - /robots.txt
    - /.well-known/*
    - /favicon.ico

The patterns work like the paths of a rule: * stands for any text, and re: starts a regular expression. In the web UI, the list is in the Never checked card on the Protection screen, one pattern per line.

How this differs from an allow rule: a rule runs after the rate limit, the webhooks and the modules, so any of those can still stop the request. An unprotected page skips them all.

Don't list pages that cost your server work, such as search. A bot can fetch an unprotected page as often as it likes.

Bypass headers ​

A request that carries one of these secret headers is allowed at once: it skips the rate limit, webhooks, modules, rules and the proof of work. Use them for uptime monitors and your own scripts, which can't solve the check.

KeyWeb UIWhat it does
nameNameShown in Activity as bypass:<name>. Defaults to the header name.
headerHeaderThe header name, such as X-Monitor-Token. The name ignores case.
valueSecret valueWhat the header must carry, at least 16 characters. The Generate button in the web UI makes a random one.

Put bypass_headers: under the protection: key you already have in data/tamamo.yaml. Do not add a second protection: block.

yaml
protection:
  bypass_headers:
    - name: Uptime monitor
      header: X-Monitor-Token
      value: "replace-with-a-long-random-value"
bash
curl -H "X-Monitor-Token: replace-with-a-long-random-value" https://example.com/

The value is stored in plain text, so keep tamamo.yaml private and send the header only over HTTPS. Anyone who learns it gets in unchecked. Your app receives the header too.

Verified bots ​

The default rules let search engines in by their user agent, and anyone can send a user agent that says "Googlebot". With this check on, Tamamo asks DNS whether such a visitor really comes from the search engine:

  1. It looks up the name of the visitor's IP address. For a real Googlebot, the name ends in googlebot.com or google.com.
  2. It looks up that name and checks that it leads back to the same IP address.

A visitor that passes goes on to the rules as usual. A visitor that only claims the name gets the action: block (the default) or challenge.

yaml
protection:
  verified_bots:
    enabled: true
    action: block

In the web UI, it is the Verified bots card on the Protection screen.

CrawlerRecognized byName must end in
GooglebotGooglebot, AdsBot-Google, Mediapartners-Google, Google-InspectionTool, GoogleOther, Storebot-Googlegooglebot.com, google.com
Bingbotbingbot, adidxbot, msnbotsearch.msn.com
Yandexyandex.com/botsyandex.ru, yandex.net, yandex.com
BaiduspiderBaiduspiderbaidu.com, baidu.jp
ApplebotApplebotapplebot.apple.com
PetalBotPetalBotpetalsearch.com
MojeekBotMojeekBotmojeek.com

Things to know:

  • Other visitors are never looked up. Only a user agent from the table causes a DNS question.
  • The answer is remembered per IP address: a day for a real crawler, an hour for a fake one. Only the first request from a new address waits for DNS, at most 2 seconds.
  • If DNS doesn't answer, the visitor gets the checking page that time, and nothing is remembered.
  • Tamamo must see the visitor's real IP address. Behind a proxy, set ip_source and trusted_proxies first, or every crawler looks fake.
  • Crawlers that are not in the table, such as DuckDuckBot, are not affected. They are still let in by user agent.

Rate limit ​

Limits how many requests one address can make in a time window. Past the limit, action applies. The address is the one Tamamo sees, so set the IP source first.

KeyWeb UIDefaultWhat it does
enabledLimit requests per IP addressfalseTurns the limit on.
requestsRequests allowed120Requests allowed in one window, 1 to 1000000.
window_secondsIn a window of60Length of the window in seconds, 1 to 86400.
actionPast the limitblockblock refuses the request. challenge shows the checking page; a visitor who already has a pass is let through.
ipv6_prefixIPv6 network size64IPv6 visitors are counted per network of this size, 48 to 128. IPv4 addresses are counted one by one.
max_ipsAddresses tracked100000Addresses counted at once, 100 to 10000000. When the table is full, Tamamo forgets some counts.

Put rate_limit: under the protection: key you already have in data/tamamo.yaml. Do not add a second protection: block.

yaml
protection:
  rate_limit:
    enabled: true
    requests: 120
    window_seconds: 60
    action: challenge

Start high, for example 300 requests per 60 seconds, and lower the limit after watching Activity.

Every request counts, including images and scripts, so a page with many files uses up the limit quickly. Requests with a bypass header are not counted. The window slides: it is not reset on the minute. Counts are kept in memory and start from zero after a restart.

This is separate from max_failures_per_minute, which only counts failed checks.

Per-site overrides ​

A site's protection section lists only what differs from the global settings. See Sites.

The rate limit is merged setting by setting: a site can change just requests. The lists are not merged: a site that sets bypass_headers or webhooks replaces the global list for itself. A site with its own protection settings also counts its rate limit separately from other sites.

A pass is also tied to its site. A visitor who passed on one site is checked again on another, even when cookie_domain covers both.

Released under the MIT License.