Since Angular JS version 1.1.1 removing the header is no longer necessary. This change got mentioned on https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet#Protecting_REST_Services:_Use_of_Custom_Request_Headers
As shown by Josue, this can be easily added to all requests again as follows:
angular.module('yourModule', [])
.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
}]);
Set the configuration for the header to undefined to remove the header for specific external requests.
let urlExternalValidator = 'https://openiban.com/validate/' + this.iban + '?getBIC=true&validateBankCode=true';
this.$http.get(urlExternalValidator, {
// simple request to not trigger a CORS preflight
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
headers: {
'X-Requested-With': undefined
}
})
In addition, you can supply a headers property in the config object
passed when calling $http(config), which overrides the defaults
without changing them globally.
To explicitly remove a header automatically added via
$httpProvider.defaults.headers on a per request basis, Use the headers
property, setting the desired header to undefined
https://docs.angularjs.org/api/ng/service/$http#setting-http-headers