Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read X-Forwarded-For header

Tags:

I want to read the value of the X-Forwarded-For header value in a request.

I've tried

HttpContext.Current.Request.Headers["X-Forwarded-For"].Split(new char[] { ',' }).FirstOrDefault();   

in C#.

OR do I need to split the header by ":" and the take the second string? I am asking this because, Wikipedia says

The general format of the field is: X-Forwarded-For: client1, proxy1, proxy2

like image 956
Kuttan Sujith Avatar asked Jun 11 '11 15:06

Kuttan Sujith


People also ask

How do you read X-Forwarded-For headers?

To check the X-Forwarded-For in action go to Inspect Element -> Network check the request header for X-Forwarded-For like below.

How do I get rid of X-Forwarded-For header?

Go the HTTP > Configuration > X-Forwarded-For Header.To disable, select Disable from the drop-down list.

Can you spoof X-Forwarded-For header?

Bypassing the IP block The X-Forwarded-For header is usually set by a proxy, but it can also be added by an attacker. By adding his own X-Forwarded-For header, the attacker can spoof his IP address.

What is X-Forwarded scheme header?

The X-Forwarded-Proto (XFP) header is a de-facto standard header for identifying the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer.


1 Answers

The format that you get in return is client1, proxy1, proxy2

So you split it with the comma, and get the first to see the ip of your client.

like image 92
Aristos Avatar answered Sep 23 '22 18:09

Aristos