XMLHttpRequest access the file:// when we on http:// domain
See original GitHub issueHi,
XMLHttpRequest can access the local files when we on http domain, you can produce from this repo https://github.com/selam/jsdom-xmlhttp-bug, this can be serius security problem, attacker can steal some your local files easly becouse XMLHttpRequest doesnt care window.location.href or window.document.URL
When i try to access local files from http domain from browser i got two error messages on console
XMLHttpRequest cannot load file:///home/timu/workspace/jsdom-xmlhttp-bug/test.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.(anonymous function) @ test.html:12
test.html:12 Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///home/timu/workspace/jsdom-xmlhttp-bug/test.html'.
Also i haven’t check yet but i believe XMLHttpRequest and jsdom also doesn’t care Cross origin, X-Frame-Options, Content-Security-Policy, X-XSS-Protection headers from responses
Issue Analytics
- State:
- Created 8 years ago
- Comments:41 (23 by maintainers)
Top Results From Across the Web
Using XMLHttpRequest - Web APIs | MDN
In this guide, we'll take a look at how to use XMLHttpRequest to issue HTTP requests in order to exchange data between the...
Read more >How to send a file on cross-domain with XMLHttpRequest?
XMLHttpRequest cannot load http://another-domain.com. No 'Access-Control-Allow-Origin' header is present on the requested resource.
Read more >XMLHttpRequest - The Modern JavaScript Tutorial
XMLHttpRequest is a built-in browser object that allows to make HTTP requests in JavaScript. Despite having the word “XML” in its name, ...
Read more >AJAX The XMLHttpRequest Object - W3Schools
For security reasons, modern browsers do not allow access across domains. This means that both the web page and the XML file it...
Read more >Fixing Common Problems with CORS and JavaScript
They prevent JavaScript from obtaining data from a server in a domain ... Access to fetch at 'http://localhost:8000/api/v1/messages' from ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You don’t have to change anything. The codebase is meant to run in a browser, so if it’s using
require
there, then browserify it, like @niftylettuce did.The Node global environment is not a browser global environment. Creating some monster hybrid where parts of it become pointers to a newly-created jsdom window, and parts of it are Node.js, causes many issues. Not the least of which is that jsdom is not designed to work in that environment, accessed via external pointers.
What you are doing is like trying to do a test in the browser by creating an iframe, setting
window.window = iframe.contentWindow
,window.document = iframe.contentWindow.document
. You would never actually do this. You would just load your tests in the iframe.Did you not see https://github.com/tmpvar/jsdom/issues/1203#issuecomment-160725194 ?
The approach in https://github.com/tmpvar/jsdom/issues/1203#issuecomment-160725194