Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can $_SERVER['REMOTE_ADDR'] be trusted?

Tags:

php

ip

I have a website where only a couple of people can access it, so the number of IPs logged in is very limited. Everything submitted by the 'admins' logged in is sent to a specific folder dependent of their IP Address. Again they can't access the website through a proxy or anything because there's a limited range of IPs that is allowed.

Can I trust $_SERVER['REMOTE_ADDR'] to give a valid IP so the log-system would be 100 % stable and efficient ?

like image 330
ProgrammingEnthusiast Avatar asked Apr 29 '11 17:04

ProgrammingEnthusiast


People also ask

Is Remote_addr secure?

Yes, it's safe. It is the source IP of the TCP connection and can't be substituted by changing an HTTP header.

What is $_ SERVER Remote_addr?

$_SERVER['REMOTE_ADDR'] Returns the IP address from where the user is viewing the current page.

What is Remote_addr?

Returns the IP address of the remote host making the request. This variable is specific to the current gateway program request. Type and Usage. "Environment Variables"


2 Answers

$_SERVER['REMOTE_ADDR'] cannot be modified by the user or via HTTP so you CAN trust it.

like image 109
Jesse Bunch Avatar answered Oct 13 '22 01:10

Jesse Bunch


It's a basic rule that you should not trust the authenticity of a remote machine's apparent ip address for anything where forgery within the network could cause you real problems.

Secure systems authenticate not only the client to the server, but also the server to the client (to protect against impersonating the server to phish login credentials), typically using asymmetric cryptography.

like image 41
Chris Stratton Avatar answered Oct 12 '22 23:10

Chris Stratton