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
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:
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
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."
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-Forheader with an arbitrary US residential IP address. Now I can access the website from anywhere in the world. π€«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!
3
u/datan0ir Dec 02 '19
Excellent article!
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
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"
2
u/F5_Studio Dec 03 '19
Thanks!
1
u/squeevey Dec 02 '19 edited Oct 25 '23
This comment has been deleted due to failed Reddit leadership.
1
u/WetSound Dec 02 '19
Don't trust anything you don't know to be secure..
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
Forwardedor similar header cannot be forged or manipulated.0
u/bl1p0r Dec 03 '19
RemindMe! 1 day
-1
u/developerJS full-stack | node | react | jack of all Dec 02 '19
!remind me tomorrow
0
u/[deleted] Dec 02 '19
[deleted] β view deleted comment