
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
An XHR Cross Origin Proxy allows you to make XHR requests to different friendly API services.
XCOP (XHR Cross Origin Proxy) allows you to make XHR requests to different friendly API services.
I'm sure that you've faced this dilemma... You web application needs to "phone home" via XMLHttpRequest call back to your site to get some information. You'd like these XHR calls to use HTTPS (maybe they contain some PII). The problem is that you've served the HTML, CSS, JavaScript, and images from an HTTP server and that would constitute a cross origin call. Historically, you were left with few options:
With XCOP you can effectively make cross origin XHR requests with full verbs (not only GET and POST but also PUT, DELETE, PATCH, etc). You can also set HTTP headers to your heart's content. Simply place a simple HTML file on the friendly cross origin server (yes, you need access to the server). Under the covers, XCOP package will load this into an iframe and communicate with it via PostMessage. You will need a fairly modern browser.
$ npm install xcop
XCOP us easy to use. Just call XCOP with the origin that you would like to communicate with (xcop.html must be in the root of the cross origin server). XCOP will return a promise that is fulfilled with an XHR object.
You can pass the following options as the second parameter to XCOP:
The returned XHR object accepts a request object that consists of the following:
It returns a promise that is fulfilled with a response object. The response object contains the following:
Let's say that you have a web page that is loaded from http://www.example.com, but you need to post some data to https://api.example.com (i.e. not on the same origin). The code below will show you how to do so.
var xcop = require("xcop");
var origin = "https://api.example.com";
xcop(origin).done(function (xhr) {
var request = {
url: "/items/123",
headers: {"content-type": "application/json"},
method: "PUT",
body: JSON.stringify({id: 123, name: "new name"})
};
xhr(request).done(function(response) {
console.log(response.status + " " + response.body);
}, function (err) {
console.error("Something went wrong.", err.message);
});
}, function (err) {
console.error(err.message);
});
You can also see XCOP in action, live, on the Interwebs! Check out this fiddle. http://jsfiddle.net/donavon/6tozto6v/
Instead of opening your web service up to other websites, you may now "white list" which origins are allowed to access your server.
To do so, edit the xcop.html file served by the destination server. By default, XCOP allows access from any origin.
var whiteList = [];
To setup a whitelist, replace the whiteList array with the list of your allows origins.
In our example above, you may chose to only allow http://www.example.com to use your API.
If so, your xcop.html file will read:
var whiteList = ["http://www.example.com"];
You may choose to use different xcop.html files with different white lists for development, QA, and production.
Q. I'm getting the error "XCOP is unavailable".
A. You likely have not setup xcop.html in the root of the origin server that you are hitting with XCOP.
In the example above, that would be https://api.example.com/xcop.html
Q. How cool is XCOP?
A. Very!
For use under MIT license
FAQs
An XHR Cross Origin Proxy allows you to make XHR requests to different friendly API services.
The npm package xcop receives a total of 0 weekly downloads. As such, xcop popularity was classified as not popular.
We found that xcop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.