Okay, I have stumbled upon this issue by myself today. Short answer: you can add ‘some white-listed headers’. The complete list can be found in SockJS source code (though even they do not explain that in their documentation ).
Here is the link to the source: https://github.com/sockjs/sockjs-node/blob/02c4dcd6ff7112834cad50fae236335fb407208f/src/transport.coffee
And here is the list of the supported headers:
['referer', 'x-client-ip', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-port', 'x-cluster-client-ip', 'via', 'x-real-ip', 'x-forwarded-proto', 'x-ssl', 'dnt', 'host', 'user-agent', 'accept-language']
You just add the headers in the second parameter in DDP.connect function (it also not documented on Meteor side, but is visible in source code: https://github.com/meteor/meteor/blob/master/packages/ddp-client/common/livedata_connection.js
), for example:
DDP.connect('http://localhost:3000',{
headers: {
"User-Agent": 'my-white-listed-string'
}
})
and then on the host server see it like this:
Meteor.onConnection(function (connection) {
console.log('User-Agent', connection.httpHeaders['user-agent']);
})
The SockJS guys also explain and discuss why they do not support Authorization header here:
https://github.com/sockjs/sockjs-client/issues/196 and the short answer is: Authorization header is threat to security and thus authorization “should occur over the SockJS channel”.
BUT. Here are 2 questions to Meteor DDP experts:
-
Please share your opinion on what kind of security threat can it be, when on every connection I would just pass an api key and validate it (and when it is not valid - just close the connection)? Since I am just connecting Meteor server to Meteor server, it has nothing to do with the mentioned iFrame they are using under the hood…
-
Can there be any issue if I pass my api key using the white listed ‘User-Agent’ header, for example like “User-Agent”: “auth:some-super-long-api-key”
, and then firstly validate user agents quickly by the first 4 letters and then if it is valid, will perform full api key validation?