X-Requested-With Header Explained
What the HTTP X-Requested-With header does and when it's used.
Published October 15, 2026
X-Requested-With: XMLHttpRequest is a convention set by libraries such as jQuery to mark AJAX requests.
How it works
It is not a standard security measure, but triggering a CORS preflight makes it a weak CSRF hint.
The X-Requested-With header is part of the HTTP message and is case-insensitive in name.
In a real exchange
curl -i https://example.com/
X-Requested-With: XMLHttpRequest
Practical examples
The header
X-Requested-With: XMLHttpRequestSet or use it in code
if (req.get('X-Requested-With') === 'XMLHttpRequest') return res.json(data)Inspect it
curl -sI https://example.com | grep -i 'x-requested-with'Common mistakes
- Using it as real CSRF protection
- Assuming fetch() sends it (it does not)
- Branching responses only on this header
Key takeaways
- X-Requested-With: X-Requested-With: XMLHttpRequest is a convention set by libraries such as jQuery to mark AJAX requests.
- Check it in browser DevTools → Network.
- Test with curl -I before deploying.
FAQ
Is it standard?
No, it is a de facto convention.
Is X-Requested-With case sensitive?
Header names are case-insensitive; values may not be.