I'm currently developing a forum-like website for the purpose of learning developing web applications and application security. Some part of the website is protected by credentials.
But there is a .php script that returns latest news. And my news.php (through javascript and jquery ajax) makes a request to return_news.php to get a json file of information about latest news. And at this point a problem arises. Anyone can send a request to return_news.php and display my data on their website. I want to make it so that only the files on my host can make requests to my endpoints or make data accessible only through my domain https://www.example.com and reject any request that comes from other origins.
What I've done:
I did some research on the internet. Read some articles about CORS and .htaccess file. But my host is on a cloud server and I don't think I have access to it. And I couldn't find a way of checking the current configurations for my hosting. The issue seems to be related to CORS but I couldn't find a detailed explanation on how to achieve my goal.
Summary: How can I configure my website so that the content is only available through my domain (e.g. https://www.example.com), my api responds to requests that originate from only my domain and my content can't be obtained by just a get request and displayed in another website?