If your organization uses Cloudflare, you can use HUMAN’s Cloudflare Enforcer to protect against malicious behavior. The Cloudflare Enforcer is installed using a Cloudflare Worker, or a snippet of code, and is deployed to your content delivery network (CDN). The Enforcer dictates how traffic should be handled per your organization’s standards.
You can learn how to install the Cloudflare Enforcer with this article.
If you do not already have an Enforcer deployed to your environment, we highly recommend using the Deploy Tool method instead. See our documentation for more information.
nvm install stable in your CLI to install it.npm install -g wrangler in your CLI to install it.There are two parts to the Cloudflare Enforcer installation:
The majority of the installation process is done through a CLI.
npm create cloudflare@latest. If you’re prompted to install additional packages to complete the installation, hit y to do so.human-cloudflare-enforcer.Hello World example option and hit return to proceed.Worker only option and hit return to proceed.Whether you use TypeScript or JavaScript is up to you, but be sure to remember what you choose. Later in the installation, you will need to choose the code snippet that corresponds to the language you installed in.
No to deploying your application.Afterwards, you should receive a success message that reads APPLICATION CREATED. This means you created a basic Cloudflare Worker, and you’re ready to move on to installing the HUMAN Enforcer.
cd folder_name to open the folder you created in Create the Cloudflare Worker, Step 2. Based on our earlier example, we would enter cd human-cloudflare-enforcer.npm i --save @humansecurity/cloudflare-enforcer. This will install the latest Cloudflare Enforcer from HUMAN.cd src.index.ts or index.js depending on your choice in Create the Cloudflare Worker, Step 4. The .ts file is for TypeScript installations, while .js is for JavaScript.You can check the file type you have by entering ls while inside the src folder. This will show you your index file’s type.
index file. The following snippet shows all the default code you should delete.index file.In addition to choosing between TypeScript and JavaScript, you must also make sure to pick the right type of Worker. This can either be an ES Module or Service Module, and it depends on your Cloudflare configuration. You can see some examples from both Workers in Cloudflare’s documentation.
px_app_id, px_auth_token, and px_cookie_secret fields with your Application ID, Server Token, and Risk Cookie Key respectively.These are the minimum required fields that must be completed in order for the Enforcer to work. You can always return to this file to customize your Enforcer later with our optional configurations.
Save and close the file.
Enter npx wrangler deploy to deploy your Worker. You may be prompted to log in to your Wrangler or Cloudflare account.
Navigate to your Cloudflare dashboard and open Workers & Pages. Your new Worker with the HUMAN Enforcer should appear with the same name you gave it in Create the Cloudflare Worker, Step 2. In our case, the Worker is named human-cloudflare-enforcer.
Select the Worker, then select Settings > Triggers > Add route under Routes. This is where you can you add URL routes and zones to monitor with the Cloudflare Enforcer. We recommend protecting your full domain, including all pages on your domain, with the pattern subdomain.apex.com/*. For example, to protect the full domain of a site with the URL www.example.com, you would provide the following fields:
www.example.com/*example.comNavigate to the Worker’s Settings > Variables > KV Namespace Bindings and select Create a KV namespace.
Select Create a namespace and enter a name for it, then select Add.
Return to your Worker’s Settings > Variables > KV Namespace Bindings and select Add binding.
Create a KV variable with the following fields:
Select Deploy.
Navigate back the Cloudflare dashboard > Websites and select the domain to trigger the Enforcer’s Worker.
Navigate to Workers Routes and select Edit next to the Route to bind your Worker to.
In the Edit route window that appears, select the Worker you created from the dropdown menu and select Save.
From the route you bound the Worker to, share the full website address with HUMAN’s Support team. Once we receive your URL, we will complete the setup for you.
Your Cloudflare Enforcer has been successfully installed with the minimum requirements to monitor activity on your Cloudflare CDN. You can further customize the Enforcer’s behavior by referencing our configuration options.
Once you finish installing, be sure to contact HUMAN to complete your tuning process.