Patrick Murray
Patrick Murray

Reputation: 108

XSS - Send data to the source server of a script?

I am writing a JavaScript application where I plan on host the code on a CDN. Now I plan to include this code to my clients' sites. However, I have a problem, I want to use AJAX to communicate between the client and the server. Now, from my understanding of XSS, this is not possible.

Ex:

  1. User visits site.com, where a script tag's source is pointing to a file on cdn.somedomain.com
  2. The script on cdn.somedomain.com fires an event.
  3. This event will communicate with a PHP. I know it is possible for the script from cdn.somedomain.com to request documents on site.com. However, is it possible to send data back to a PHP file on cdn.somedomain.com?

Thanks for helping an entrepenuer! :D

Upvotes: 0

Views: 575

Answers (2)

Erlend
Erlend

Reputation: 4416

Sounds like a weird use of a cdn. Normally cdns serve static assets, so you wouldnt put a php file there. In fact the cdn wouldnt normally run dynamic server side code at all. You can address the problem in several ways. Newer browsers support CORS and cross domain ajax. The cdn would then have to use the Access-control-* headers. You could also look at something like easyXDM, which works in older browsers.

Upvotes: 0

Michael
Michael

Reputation: 2261

The short is I think this is possible, but it depends on a couple of things. The same origin policy is a weird thing in that it won't allow cross domain reads, but will allow cross domain writes.

I think a way you could accomplish your goal is by making a GET request (minimally by creating an iframe, img, or whatever else that pulls a src) or possibly even using AJAX. If your goal is to only send data, then that should be fine. However, if you want to read this data back then I think that'll be a little less straight forward. I can't really answer that right now - especially without knowing more details about your system setup.

Upvotes: 1

Related Questions