How to Bypass WAF When Working with APIs
Summary
Sometimes, the API returns 403 or token_required, even though everything is set up correctly. This is usually a hosting (WAF) block, not an API error. Here’s how to distinguish one from the other and how to bypass the filter carefully without breaking authorization.
What is WAF and Why Does It Interfere
WAF (Web Application Firewall) is a filter that sits in front of a website and blocks suspicious requests. It protects against attacks but sometimes blocks legitimate calls as well.
A typical scenario:
- You send a
POSTrequest with the headerAuthorization: Bearer ...; - You receive a
403 Forbiddenresponse; - You think the token is incorrect or the API is broken.
This is exactly what happened in the case of rewriting cards on Webasyst: the reg.ru hosting blocked the correct authorization header, and I had to find a request format that the filter would allow.
In reality, the token may be valid, but the filter doesn’t like the header or User-Agent. This is especially common on shared hosting with pre-installed protection (reg.ru, Timeweb, and similar).
Step 1. Distinguish WAF Block from API Error
First, determine who is responding. Compare:
- API Error — usually this is a
200 OKresponse with JSON inside: `{