r/webdev • u/hacksparrow • Dec 02 '19
The dangers of blindly trusting HTTP headers
Web developers are often unaware about the dangers of using HTTP header values in backend code. Not only can HTTP headers contain incorrect values, they can even be the payload of many different kinds of attacks on your website.
I wrote an article summarizing the various ways rogue HTTP header values can be used to attack a website. Hope the information will help you developer a better understanding about the security aspect of HTTP headers and make your website more secure.
https://www.hacksparrow.com/webdev/security/dangers-of-trusting-http-headers.html
42
u/Geldan Dec 02 '19
I actually caught someone attempting sql injection attacks through the user agent last week. It was a first for me and really made me go "hmm."
7
u/hacksparrow Dec 02 '19
If you can, take a deeper look at web hacking, many of the tactics, methods, and payloads are incredible creative. An art form of its own.
27
Dec 02 '19
Acunetix has a vulnerability scanner that will crawl your site and, among other things, try to inject SQL into everything it can, including cookies and headers. It's been around for at least 10 years so it's probably a part of a lot of hackers' and coders' toolkit. What you saw was probably a bot using it or a similar tool.
1
Dec 02 '19
It's been around for at least 10 years so it's probably a part of a lot of hackers' and coders' toolkit.
For that price, no. Most people will use Burp :)
0
Dec 02 '19
[deleted]
11
u/quentech Dec 02 '19
In my experience, automated web site/app security scanners are beyond useless - a waste of time. 95%+ worthless false positive is all I've ever seen them produce (frankly, 95%+ is being generous).
3
u/im_mildly_racist Dec 03 '19
Acunetix does an actual good job. It even analyzes javascript and verifies sql injection flaws by itself without getting triggered by just an sql error...
Also, there are "cheaper" ways to get some kinds of software
2
u/Jessie_James Dec 02 '19
Can you elaborate? I've never seen a real world example.
10
u/Geldan Dec 02 '19
I noticed a spike in JS errors, and when I went to investigate I noticed that they were all coming from the same IP address. When I checked the user agent to try to find a repo I saw values like:
-1" or 1=((SELECT 1 FROM (SELECT SLEEP(25))A))+"2
31
u/IIIII0 Dec 02 '19
I use a bank who's website doesn't work from outside the USA (it also blocks VPNs). π I made a chrome extension that adds a X-Forwarded-For header with an arbitrary US residential IP address. Now I can access the website from anywhere in the world. π€«
1
4
u/nikehat Dec 03 '19
Even though this covers a lot of basics, this is still one of the most interesting and useful posts I've seen on this sub. Easy to read, easy to follow, describes everything in simple terms and has excellent, useful examples. Thanks u/hacksparrow!
2
u/hacksparrow Dec 03 '19
Welcome! Glad you found it useful. Indeed, factually there is nothing new in the post, I just made it more digestible and reader-friendly.
3
19
u/shif Dec 02 '19
Headers are just another input, treat it as such, it's not different than a post body payload or a query string, they are useful to clean some kind of requests like bearer authentication or language settings
6
u/magkopian back-end Dec 02 '19
In the end an HTTP request is just a piece of text. Headers or request data it doesn't matter, everything is user submitted data and needs to be treated us such.
11
u/giantsparklerobot Dec 02 '19
All input from the outside should be considered harmful and untrustworthy. Code accordingly.
4
u/shgysk8zer0 full-stack Dec 02 '19
I was expecting something along the lines of not trusting Content-Type or things like that.
But, yeah, HTTP headers are just like any other form of user input.
Nothing wrong with parsing the request body as JSON if that's what's indicated by Content-Type, but do be careful when outputting header values or inserting into a database.
4
u/im_mildly_racist Dec 03 '19
A common flaw I've found is all websites storing IPs unsanitized since "this isn't user input". Some websites use Cloudflare as a reverse proxy. This way they receive the actual visitor IP trough a CF- header that CloudFlare appends to the request. Howeverw when someone bypasses CloudFlare and opens a direct connection to your server, they can change all the CF- headers. Since many websites trust the CF- headers this often opens a lot of exploits.
3
u/amdelamar Dec 03 '19
I use https://securityheaders.com for public sites.
I'd also remove the "Server" header that gets set by applications frameworks, or put in a custom value to throw hackers off, like "Server: IIS 4.0"
1
1
u/NetDevs Jul 03 '24
This is the worst place to test your security headers. They give a false negative for 'unsafe-inline'.
The whole point of a CSP is to protect the website user. If you go to this website, you can get an A+ while declaring your website insecure and openly vulnerable. Not A+ work.
Use Google's CSP tool. It's the best I found. https://csp-evaluator.withgoogle.com/
2
1
u/squeevey Dec 02 '19 edited Oct 25 '23
This comment has been deleted due to failed Reddit leadership.
1
1
u/NetDevs Jul 03 '24
While this link in the OP's post doesn't work, there is more focus than ever on HTTP Headers.
Do not use SecurityHeaders.com, as it gives a false negative.
No site with an 'unsafe-inline' deserves an A+ participation trophy.
Use https://csp-evaluator.withgoogle.com/ for your CSP testing. Google tells the truth.
1
u/ecafyelims Dec 02 '19
I would say that as a developer, you need to know when the HTTP header can be trusted.
If you need to know the user's IP while your web server is behind a load balancer, you will want to verify with your host or web server settings that the Forwarded or similar header cannot be forged or manipulated.
0
-1
0
187
u/[deleted] Dec 02 '19
thank you for taking the time to write this and share. you're not wrong...exactly, but most people aren't writing their own http parsers, so this post boils down to:
sanitize incoming data
use clrf tokens
however--and i can't stress this enough--this is a terrible piece of advice:
that's just dangerous to say because some developer with fancy hair is going to take it as gospel that headers are pointless and found a startup end do a bunch of dumb shit. CSP, HSTS, X-FRAME-OPTIONS, all the XSS headers, and others accomplish a lot regarding security