AI agents and automation
How to solve AWS WAF CAPTCHA in n8n
AWS WAF answers a suspicious request with a puzzle page instead of the content. In n8n you can detect that response, get the aws-waf-token cookie from the API at $1.40 per 1,000, and repeat the request so the workflow carries on.
How the AWS WAF check shows up in n8n
When AWS WAF decides a request needs a check, it does not return the page. It returns a small HTML document, often with status 405, that loads a challenge script and contains a JavaScript object named gokuProps with three values: key, iv and context. A browser would solve the check and receive a cookie named aws-waf-token. With that cookie set, the same URL returns the real content.
In n8n, the default HTTP Request node treats a 405 as an error and stops the execution. The first job is to let that response through so a later node can look at it.
The workflow layout
- Get page: HTTP Request with errors suppressed and the full response kept.
- Is WAF?: IF node that checks for the puzzle.
- WAF fields: Code node that reads
gokuProps. - Create task, Pause, Poll, Done?: the solving loop.
- Get page again: HTTP Request with the cookie header.
The false branch of Is WAF? goes straight to your processing nodes, so pages that were not challenged skip the whole loop and cost nothing. Option names match n8n 1.x at the time of writing.
Let the 405 through
In the Get page node, open Options and add the response settings: turn on "Include Response Headers and Status", turn on "Never Error", and set the response format to text. The node now outputs statusCode, headers and body (or data, depending on version) for every reply, including the puzzle.
Detect the puzzle
Add an IF node named Is WAF? with two conditions joined by OR: {{ $json.statusCode }} equals 405, or the body contains gokuProps. Checking both covers sites that serve the check with a different status. The AWS WAF parameters guide describes other markers if your target varies.
Read gokuProps in a Code node
The three values are optional for the task, but sending them when present helps. This node also remembers the target URL for the retry.
// Code node "WAF fields"
const r = $input.first().json;
const page = String(r.body ?? r.data ?? '');
const block = page.match(/gokuProps\s*=\s*(\{[\s\S]*?\})\s*;?/);
let props = {};
if (block) {
try { props = JSON.parse(block[1]); } catch (e) { props = {}; }
}
const target = $('Get page').params.url;
const task = { type: 'AntiAwsWafTaskProxyLess', websiteURL: target };
const pairs = [['awsKey', 'key'], ['awsIv', 'iv'], ['awsContext', 'context']];
for (const [field, src] of pairs) if (props[src]) task[field] = props[src];
return [{ json: { target, task } }];
Reading the URL with $('Get page').params.url works when the URL is a fixed value. If it came from an expression, carry it through the items instead, for example from the trigger. Building the whole task object here means fields that are missing on the page are simply left out.
Request the cookie
Create task is an HTTP Request node: POST to https://gatesolver.com/createTask with a JSON body. The task object from the previous node is dropped in whole with JSON.stringify, so the body stays valid JSON whether or not the optional values exist; the task also works with the page URL alone.
{
"task": {{ JSON.stringify($json.task) }},
"clientKey": "{{ $vars.GATESOLVER_KEY || 'YOUR_API_KEY' }}"
}
Then a Wait node (Pause, 3 seconds), an HTTP Request (Poll) that posts {"clientKey": ..., "taskId": "{{ $('Create task').item.json.taskId }}"} to /getTaskResult, and an IF node (Done?) that checks {{ $json.status }} equals ready. The false branch loops back to Pause through a guard that stops after 40 rounds or on a failed status. Failed and expired tasks are free. The n8n reCAPTCHA workflow shows that guard in detail.
Repeat the request with the cookie
When the task is ready, the solution has one field, cookie. Add an HTTP Request node named Get page again with the same method and URL as the first one. Under Send Headers, add:
| Header | Value |
|---|---|
| Cookie | aws-waf-token={{ $json.solution.cookie }} |
| User-Agent | the same value the first request used |
If the first response set other cookies, include them in the same header separated by semicolons. Keep the User-Agent identical between the first request and the retry, since a change in identity is a common reason for the cookie to be refused.
Reuse the cookie for the rest of the run
The cookie is not single use. It stays valid for a while for the same site, so later requests in the same execution can carry it without a new solve. Store it in a field that flows through the items, or in workflow static data if your runs are close together, and solve again only when Is WAF? fires. This makes the per page cost a small fraction of the per solve price.
Proxy tasks
If your HTTP Request nodes go through a proxy and the site rejects cookies earned elsewhere, switch the type to AntiAwsWafTask and add a proxy field with the same address in the form http://user:pass@host:port. The proxyless type is the better default; move to the proxy type only when you see refusals.
Image grid variant
Some AWS WAF pages ask the visitor to pick images, such as "choose all beds". That is a separate type, AwsWafClassification, which needs the images and the question and returns indexes to click. It suits a browser flow better than pure HTTP. See AWS WAF Image Classification for the fields and AWS WAF for the cookie type.
Confirming the retry worked
Put one more IF node after Get page again with the same test as Is WAF?. If the puzzle comes back even with the cookie, route the item to a notification instead of looping. The usual causes are a different User-Agent on the retry, a missing cookie from the first response, or a site that ties the token to the IP, which the proxy task type addresses.
Common questions
Why does my HTTP Request node fail with a 405?
That is often the AWS WAF puzzle. Turn on Never Error in the node options so the response reaches the next node.
Must the task include the three gokuProps values?
No. They are optional. Send them when gokuProps is present on the page, otherwise the URL alone is enough.
How do I attach the cookie in n8n?
Add a Cookie header with aws-waf-token= followed by the solution cookie value on the repeated request.
Can one cookie serve many pages?
Yes, for the same site and identity until it expires. Solve again only when the puzzle comes back.
Is a page without the puzzle charged?
No. Pages that are not challenged skip the solving nodes, and only solved tasks are charged.
Keep reading
- n8nA reusable n8n solve loop built only from HTTP Request, Wait and IF nodes, with an attempt cap and clean error branches.
- AWS WAF solver$1.40 per 1,000 tasks, answers under 3 seconds.
- Find AWS WAF CAPTCHA parametersWhere key, iv and context sit on the AWS WAF puzzle page, and how each value maps to a task field.
- AWS WAF CAPTCHAThe CAPTCHA and Challenge actions in Amazon's web firewall, the aws-waf-token cookie, and the page values a solve can use.