Answer the question
In order to leave comments, you need to log in
How to setup CORS for XMLHttpRequest?
I want to draw your attention right away, I am a specific teapot, I am just starting to study information security and everything connected with it.
The goal is to allow reading and displaying the contents of the user_info.html page of the localhost domain only from the trustedhost.com domain.
There is a user_info.html file with arbitrary content on the localhost domain that is being requested.
There is also a request.html file on the attacker.com domain from which the XHR request is sent:
<body>
<script>
function loadData() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://localhost/user_info.html", false);
xhr.send();
if (xhr.status != 200) {
alert(xhr.status + ': ' + xhr.statusText);
} else {
alert(xhr.responseText);
}
}
</script>
<button onclick="loadData()">getdata</button>
</body>
location / {
add_header 'Access-Control-Allow-Origin' 'http://trustedhost.com';
try_files $uri $uri/ =404;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question