A plugin for ArchivesSpace that integrates Cloudflare Turnstile to protect the public interface from bots and automated attacks.
This plugin adds Cloudflare Turnstile verification to your ArchivesSpace public interface. Users will be presented with a Turnstile challenge before accessing the public site, helping to prevent bot traffic and automated attacks while maintaining a user-friendly experience.
- Cloudflare Turnstile Integration - Seamless bot protection using Cloudflare's Turnstile service
- Session-Based Verification - Once verified, users can browse without repeated challenges
- Automatic Redirect - Users are redirected back to their original destination after verification
- Configurable via AppConfig - Configuration through ArchivesSpace's config.rb
- ArchivesSpace (tested with public interface)
- Cloudflare Turnstile account with:
- Site Key (public)
- Secret Key (private)
-
Clone or download this repository into your ArchivesSpace plugins directory:
cd /path/to/archivesspace/plugins git clone https://github.com/your-username/archivesspace_cloudflare_plugin.git cloudflareOr download and extract the plugin to:
archivesspace/plugins/cloudflare/ -
Enable the plugin in your ArchivesSpace
config/config.rb:AppConfig[:plugins] = ['cloudflare']
-
Configure your Cloudflare Turnstile keys in
config/config.rb:# Cloudflare Turnstile Configuration AppConfig[:turnstile_site_key] = "your_site_key_here" AppConfig[:turnstile_secret_key] = "your_secret_key_here"
-
Restart ArchivesSpace to load the plugin:
./archivesspace.sh stop ./archivesspace.sh start
See CloudFlare documentation https://developers.cloudflare.com/
Add the following to your config/config.rb:
# Required: Cloudflare Turnstile Site Key (public)
AppConfig[:turnstile_site_key] = "1x00000000000000000000AA"
# Required: Cloudflare Turnstile Secret Key (private)
AppConfig[:turnstile_secret_key] = "1x0000000000000000000000000000000AA"Note: Replace the example keys above with your actual keys from Cloudflare.
- User Access: When a user visits the public interface, they are intercepted by the Turnstile filter
- Challenge Display: If not already verified, users see a Turnstile challenge page
- Verification: Users complete the Turnstile challenge (usually automatic)
- Session Storage: Upon successful verification, a session flag is set
- Redirect: Users are redirected to their original destination
- Subsequent Requests: Verified users can browse without additional challenges (until session expires)
- The plugin uses a
before_actionfilter onApplicationControllerto intercept requests - Turnstile verification is performed server-side via Cloudflare's API
- Session-based verification state prevents repeated challenges
- HTTP timeouts (5s connection, 10s response) prevent hanging requests
- Comprehensive error handling ensures graceful degradation
cloudflare/
├── public/
│ ├── controllers/
│ │ └── turnstile_controller.rb # Handles verification requests
│ ├── lib/
│ │ └── turnstile_filter.rb # Main filter module
│ ├── routes.rb # Plugin routes
│ ├── plugin_init.rb # Plugin initialization
│ └── views/
│ └── shared/
│ └── turnstile_challenge.html.erb # Challenge page template
├── LICENSE
└── README.md
- Verify the plugin is in the correct directory:
archivesspace/plugins/cloudflare/ - Check that
AppConfig[:plugins]includes'cloudflare'inconfig/config.rb - Review ArchivesSpace logs for initialization errors
- Verify both
AppConfig[:turnstile_site_key]andAppConfig[:turnstile_secret_key]are set - Check that keys are correct (not test keys in production)
- Review browser console for JavaScript errors
- Check ArchivesSpace logs for configuration errors
- Verify your secret key is correct
- Check Cloudflare dashboard for site configuration
- Review ArchivesSpace logs for API error messages
- Ensure your server can reach
challenges.cloudflare.com
- Clear browser cookies and try again
- Check that session storage is working in ArchivesSpace
- Verify session configuration in ArchivesSpace
If you see errors about missing partials (e.g., shared/header), this is expected if your ArchivesSpace installation doesn't have that partial. The plugin handles this gracefully and will continue to work.
The plugin logs important events to the ArchivesSpace log:
- Configuration errors: When Turnstile keys are missing or invalid
- Verification failures: When Turnstile challenges fail
- API errors: When communication with Cloudflare fails
- HTTP errors: When the API returns non-success status codes
Look for log entries prefixed with [TURNSTILE] for plugin-specific messages.
- Secret Key: Never commit your secret key to version control
- HTTPS: Always use HTTPS in production to protect the verification process
- Session Security: Ensure ArchivesSpace session security is properly configured
- Rate Limiting: Consider additional rate limiting for the verification endpoint
- Cloudflare Turnstile for the bot protection service
- ArchivesSpace for the archival management system
Note: This plugin is provided as-is. Make sure to test thoroughly in your environment before deploying to production.