I have some code like this in index.php:
if(isset($_GET['something'])){
//do something
}
Can hackers find this and request index.php?something
, or is this sufficient for security?
I have some code like this in index.php:
if(isset($_GET['something'])){
//do something
}
Can hackers find this and request index.php?something
, or is this sufficient for security?
You're relying on a principle called security through obscurity, which is generally frowned upon. There is a widely-accepted principle called Kerckhoffs's Principle which states:
A cryptosystem should be secure even if everything about the system, except the key, is public knowledge.
An alternate, and more general, form of the principle is called Shannon's maxim:
The enemy knows the system.
Essentially, this means that you should never rely on an obscurity mechanism to protect your system. You should assume that attackers know the code, and can discover any vulnerabilities like this.
As such, your access mechanism should involve proper authentication - e.g. entering a set of credentials that can be checked on the server side, using proper password hashing. This means that even if an attacker knows your code, he cannot exploit it.
As mentioned elsewhere on this site (see this and this, your "secret" can be discovered in web server logs and many other means.
Using this as a means of access control is known as "security through obscurity", and can be easily discovered.
However some less secure sites will use a variation of this theme and use it to protect a session after a user logs on. The idea here is to use a HTTP GET value instead of a session cookie. I wouldn't recommend implementing it yourself, but it is included in many software packages (Microsoft Windows Identity Foundation) for example, when client side cookies are disabled.
If this is a privileged function that should not be executed by just anyone, then you need to protect your function by also checking the identity of the user (e.g. session id).
Furthermore you should make sure that you have a CSRF token, if someone were to send a link to one of your users with that GET request and the user opens it, he might end up executing a function he didn't want to execute.
Now depending on what your function does and what the GET parameter is, "hackers" might find out what it does.
It might be that your function only shows information (immutable) than this can be ok. I would like to refer to this question: How unlikely is it that a Google Doc link is guessed?
Besides the other answers posted, there's the general problem that web browsers and their users generally do not consider URL's to be sensitive information. They are stored in history files, bookmarks, etc. without encryption by the browsers, and users will happily share them via e-mail, instant message, or cloud bookmark/url sharing services, not expecting a URL alone to give away their access. They may also be captured in web proxy logs, firewall logs, and other intermediaries, who again consider that sensitive information would not be found in the URL.
If any of those get seen by a web spider, or a user just copies the URL from their browser to their blog or a wiki, then they'll be indexed and easy for hackers to find in the search engines.
Hiding and not protecting functionality is not a good security practice.
There are indirect ways this functionality can leak, such as:
index.php
file readable.something
code.index.php
with different extensions (index.bak
, index.php.1
, etc.) can make the contents readable.First and foremost, make sure that the secret token is long enough and changes with every access. Always using the same token is very risky, for reasons the other answers pointed out.
When using different tokens, there are still several threats here, which can be (partially) mitigated:
Another good strategy is to restrict the access level of users only identified by a token - allow only very specific, potentially non-dangerous actions.