javascript - How to read cross domain GET response? -


i know has been discussed lot on site , others still unable read response cross domain request.

i testing website responds csrf token when request https://domain/csrf-token/ sent site. site has has comprehensive csp policy , responds token following request:

<html> <body> <script> var httpclient = function() {     this.get = function(aurl, acallback) {         var anhttprequest = new xmlhttprequest();         anhttprequest.onreadystatechange = function() {              if (anhttprequest.readystate == 4 && anhttprequest.status == 200)                 acallback(anhttprequest.responsetext);         }          anhttprequest.open( "get", aurl, true );                     anhttprequest.send( null );     } }  var client = new httpclient(); client.get('https://domain/csrf-token/', function(response) {     alert(response); }); </script> </body> </html> 

even though request successful script unable read response contents. believe because of limited understanding of csp policy directives. site testing has comprehensive csp policy , based on research following directives relevant scenario:

  1. default-src 'self' cdn.example.com (the default-src default policy loading content such javascript, images, css, fonts, ajax requests, frames, html5 media.

  2. script-src 'self' js.example.com (defines valid sources of javascript.)

  3. connect-src 'self' (applies xmlhttprequest (ajax), websocket or eventsource.)

however, not sure directive applicable cross-domain request generated via javascript. can please me understand?

i have uploaded above code in test.html file on aws cloudfront csp states: connect-src 'self' 'self' *.cloudfront.net

http request:

get /csrf-token/ http/1.1 host: domain.com user-agent: mozilla/5.0 (windows nt 10.0; wow64; rv:55.0) gecko/20100101 firefox/55.0 accept: */* accept-language: en-us,en;q=0.5 referer: https://*.amazonaws.com/test.html origin: https://*.amazonaws.com connection: close 

http response:

http/1.1 200 ok server: ***** date: mon, 21 aug 2017 05:20:24 gmt content-type: application/octet-stream connection: close x-frame-options: sameorigin x-xss-protection: 1; mode=block x-csrf-token: 1******825-01-rddohp****csrf-token set-cookie: ****************************** cookie x-xcustomheader-xxx: xxx-frontend strict-transport-security: max-age=604800 x-content-type-options: nosniff strict-transport-security: max-age=2592000 x-frame-options: sameorigin cache-control: max-age=0 content-length: 57  1******825-01-rddohp****csrf-token 

please note no headers sent server block cross-domain requests:

appreciate patience considering beginner on cross-domain requests. also, provide links may me understand concepts better.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -