It's simple.
page.php is the dangerous page.
It's far easier to just keep page.php out of public folders, and use php to include() it if it's needed for other areas.
If page.php is in the public folder, anyone can (pedantically) access it, page.php then has to determine who is allowed to proceed or not. Why bother with the extra effort of nonces? If the page isn't include()d by a page elsewhere, it is impossible to run it.
It's like having every individual soldiers carry armor plating, when it would be much easier to just have them all board an APC.
Think of what a front controller does.. everything goes through it, and it decides who is allowed to see what. This is exactly what this is.
Thanks for the great discussion guys, will go with the suggestion further up (nonces?).
I have to sanitise the input at the Javascript level so the user can see exactly what they are submitting (This is done by defaulting to what I think the user wants if they go outside the bounds of the input for fields where numerical stuff is needed, plus I am blocking non 0-9 characters, etc). I am also going to flood- control anything that calls the dangerous php file to prevent more than 1 request every 2 seconds or so.
Does this method mean I don't have to do any sanitising on my PHP, as the only way the user can hit the page is by submitting the correct token? or is it possible for a user to spoof the token once inside the session, and send my dangerous php file massive values?
Does this method mean I don't have to do any sanitising on my PHP
In theory you could spoof the token.. depends how your generating it.
Soldiers = pages. APC = Controller or Webserver.I understand exactly what you're saying but it doesn't work.
page.php is used as an image source on the site in question, so the browser must be able to make requests to it as necessary, and any authentication process must be transparent.
What you're suggesting is that page.php is placed outside the docroot and is included by some other file. However, this intermediate file must then also be accessible in order for the browser to request the resource provided by page.php, so ultimately, the situation hasn't changed at all. Of course, the user can't directly access page.php, but that doesn't make a blind bit of difference as it's still being run, which is what Bes wants to prevent.
To break it down, the page.php resource obviously has to be accessible for displaying images on the site, but what we want to prevent is people accessing the resource for other reasons. Thus, we need to authenticate the origin of the request, and the only way of doing this transparently is by using nonces.
I also don't really understand your APC analogy; what I was suggesting was that page.php along contained nonce authentication code, so I don't see how this is analogous to lots of soldiers having armour![]()
Soldiers = pages. APC = Controller or Webserver.
I didn't realise the page would be used as an image source. Seems daft to need this security on the image source, instead of needing it on the page requiring the image in the first place.
I didn't realise the page would be used as an image source. Seems daft to need this security on the image source, instead of needing it on the page requiring the image in the first place.
<!-- some stuff -->
<img src="image.php" />
<!-- some stuff -->
<!-- some stuff -->
<img src="image.php" />
<!-- some stuff -->
<?php
// Expensive/dangerous operation:
output_image();
?>