A Bash script to automatically stop spam signups on Mastodon Docker Compose instances by blocking temporary and throwaway email domains.
It automates downloading crowdsourced blocklists and imports them safely using the native tootctl email-domain-blocks add command.
- Fixes "Argument list too long": Uses
xargsto batch imports (250 domains at a time). This preventstootctlor LinuxARG_MAXerrors when handling large lists of 60,000+ domains. - Security Hardened: Uses strict alphanumeric regex validation (
grep -E) to filter incoming data, preventing command injection or shell exploits from untrusted files. - Punycode Support: Native compatibility with internationalized domain names formatted as
xn--....
- Self-hosted Mastodon using Docker Compose
- Linux environment with
bash,grep,xargs, andcurl - For the cronjob:
crontabandshuf
Save the script as mastodon-spam-blocklist-sync.sh and add it to your crontab to run daly:
# Open crontab
crontab -e
# Run every day at 2:00 AM using bash, with a random delay of up to 30 minutes to prevent spikes
0 2 * * * sleep $(shuf -i 0-1800 -n 1) && PATH=$PATH:/usr/local/bin bash /opt/mastodon/mastodon-spam-blocklist-sync.sh > /dev/null 2>&1mastodon_block_disposable_emails.sh Copyright 2026 Mia Heidenstedt and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.