Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Access-Control-Allow-Origin #1

Open
workingDog opened this issue Sep 14, 2017 · 9 comments
Open

No Access-Control-Allow-Origin #1

workingDog opened this issue Sep 14, 2017 · 9 comments

Comments

@workingDog
Copy link

Hi Bret,
thanks for sharing this work on a TAXII 2.0 server and especially the test server.

I'm starting a TAXII 2.0 javascript client library at: https://github.com/workingDog/taxii2lib

I'm having some problems when trying to connect to your test server. I get:

Failed to load https://test.freetaxii.com:8000/taxii/: Response to preflight request
doesn't pass access control check: No 'Access-Control-Allow-Origin'
header is present on the requested resource. Origin 'http://localhost:8000'
is therefore not allowed access. The response had HTTP status code 405.
If an opaque response serves your needs, set the request's mode to 'no-cors'
to fetch the resource with CORS disabled.

I've tried many different headers and modes for my requests and also
browser (Chrome) settings on my part but to no avail. I just cannot get pass this.
Do you have any advice on how to overcome this?

Ringo

@jordan2175
Copy link
Contributor

jordan2175 commented Sep 14, 2017 via email

@workingDog
Copy link
Author

workingDog commented Sep 14, 2017

I'm testing things now with the following simple html file in Chrome 61 on MacOs:

<!DOCTYPE html>
<html>
<head>
    <title>TAXII2</title>
    <meta charset="UTF-8">
  </head>
  <body>
    <div>Chrome-->View-->Developer-->Developer Tools</div>
    <div id="demo"></div>
<script>
function loadTaxii() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "https://test.freetaxii.com:8000/taxii/", true);
  xhttp.setRequestHeader('Accept', 'application/vnd.oasis.taxii+json');
  xhttp.setRequestHeader('Content-type', 'application/vnd.oasis.taxii+json');
  xhttp.send();
};
loadTaxii();
</script>
 </body>
</html>

From my understanding of some of the comments on the net, the server has to be set to Access-Control-Allow-Origin.

@jordan2175
Copy link
Contributor

jordan2175 commented Sep 15, 2017 via email

@workingDog
Copy link
Author

thanks for your reply. I removed the Content-type and tried a few other things, but no success yet.
Is the example html working for you?

@workingDog
Copy link
Author

I've just dropped the html file in Safari, and it seems to be working. This problem of cross origin appear to be a Chrome problem.
Thanks for your help anyway.

@jordan2175
Copy link
Contributor

It looks like I need to add some code like this for CORS. https://stackoverflow.com/questions/12830095/setting-http-headers I will look in to adding this in the next update.

@workingDog
Copy link
Author

Hi Bret,

I'm writing a browser app for creating and sending STIX 2.1 objects to a TAXII-2.0 server at:
cyberstation

However I cannot get pass the "Access-Control-Allow-Origin" bug.
Currently I launch Chrome with "--disable-web-security --user-data-dir" and that works temporarily.
I updated Safari and now it has the same problem.

Is there any other ways to get around this while you work on a server side solution?

@jordan2175
Copy link
Contributor

Will you have time to work on this live? I can make changes to the server and you can let me know if it works for you? We can chat via slack or skype, if either of those work for you.

@workingDog
Copy link
Author

Hi Bret,

I've found a way around the 'Access-Control-Allow-Origin' problem.
I use the proxy server at: "https://cors-anywhere.herokuapp.com/"
This is really a temporary hack.

I've put a small html file: testfreetaxii.html at :

https://github.com/workingDog/cyberstation

If you drop this file on your browser it will show the problem.
As far as I know the server must respond with the appropriate
Access-Control-Allow-Origin header. Then it should work.

I've signed up to the Slack thing, it maybe a day or two before I
can spend time on it, live or otherwise. Note I'm in Tokyo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants