1

Since it is possible to preform a cross domain php post, I believe this means someone who obtained access to my source code could create their own domain and post any values. Is there a way to disable cross domain posting or do I need to check all of the values in a post to ensure they are valid?

mucle6
  • 585
  • 7
  • 22

2 Answers2

2

It has nothing to do with another domain; ANY client anywhere can post any values your server will accept. This is why one of the primary rules of the web is never trust user-supplied data: always check it on the server side. \

Here is some worthy reading on the subject:

What's the best method for sanitizing user input with PHP?

What are the best PHP input sanitizing functions?

Community
  • 1
  • 1
Digital Chris
  • 6,098
  • 1
  • 16
  • 28
1

You better create a random hash like : md5(time().rand(1000,9999)) and,

  1. Put it in a hidden input value like: <input name='token' type='hidden' value='<?php echo $hash ?>' />
  2. And set $_SESSION['token'] = $hash;

And, every time that you process the form, check it like :

if($_SESSION['token'] !== $_POST['token']) die('invalid request');

This way, only users that submit the form from your domain will succeed submitting.

Alireza Fallah
  • 4,411
  • 3
  • 27
  • 55
  • While this might make it more difficult to script mass spam-submits, it doesn't stop me from accepting data on my remote server (or generating it) and then cURL requesting your form, accepting cookies, and feeding you your token back to you with my data. – Digital Chris Jan 30 '14 at 18:12