In my project , I need to allow others send ajax requests to my script . So external requests may come from other websites and domains and maybe from browser extensions.
I've added simply these two lines at top of my script to let them do it:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
Now my question is this : Is here any security consideration I've missed? does this simple solution make serious problems?
If so , what is the better solution?
Thanks for response.
Like zerkms said, if they just "go" to your php page, they will be able to see whatever it echos out. If it's possible (Not sure it is), it will also allow unwanted people to create their own forms even on a localhost and submit them via AJAX to get the responses they want .. If that's ok with you, and the information is ambiguous/harmless ... Then I suppose it would be "safe". It's NOT ok method to get/transfer sensitive information
As mentioned above, anyone can send a request to you page at any time: so the major security concerns you need are to validate user input and only reveal information that is available for public consumption. But that applies to all scripts.
The two main issues you need to concentrate on (after validating user input) are:
.
Other factors to bear in mind: