In oauth2 for single page application(SPA), we can revoke the access tokens of the implicit grant type by using an ajax request(this is not recommended now). I tried to do a request like below from such a SPA to an identity server in another domain. I wasn't getting blocked due to the CORS.
<script>
function revokeToken() {
var params= 'token='+ getAcceesToken() + '&token_type_hint=access_token&client_id=' + getClientID();
request = new XMLHttpRequest();
request.open('POST', getRevokeURL(), true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {//Call a function when the state changes.
if(request.readyState == 4 && request.status == 200) {
alert(request.responseText);
}
}
request.send(params);
}
</script>
As I went through the docs in [1], it says that some requests don’t trigger a CORS preflight, this includes POST requests with Content-Type application/x-www-form-urlencoded as well.
I think there is a security risk due to such exemption. Even I was able to successfully do the revocation with chrome as well. Why are browsers allowing such cases?
CORS preflight triggered only when I changed the content type to application/json