0

We are passing secret keys to authenticate the GET requests between https enabled websites. Which of the following ways are more secured:

GET /auth?secret=8727n2i752gns982jsn'

Only 2 servers know that secret keys.

Or should we set headers as follows:

request({
    url: '/auth',
    headers: {
        'secretKey': 's87ehwdiw8y3dhj'
    }
});

Which method is more secured and why?

Sowmay Jain
  • 865
  • 1
  • 10
  • 21
  • Definitely do not append the secret in the URL, even if it's HTTPS. I believe headers are encrypted. – Vic Jun 26 '18 at 13:04

2 Answers2

2

Ideally sending secret key isn't a good option. But if there is utmost need I would suggest you to send the key in the headers like:

request({
    url: '/auth',
    headers: {
        'secretKey': 's87ehwdiw8y3dhj'
    }
});

If you give a "secret key" to a browser, it's not secret anymore. Javascript in the browser is just too open to really keep a key secret.

As it is less visible, yet anyone can sniff it as it's just javascript.

Here are few links to enlighten you more:

Harshal Yeole
  • 4,812
  • 1
  • 21
  • 43
1
request({
    url: '/auth',
    headers: {
        'Authorization': 'Bearer s87ehwdiw8y3dhj'
    }
});

This is a standardized way of passing tokens through header. The security part is really more about your token creation.

'Bearer' is the type of Authorization you are using. It could be 'Basic', etc ie

'Authorization': 'Basic s87ehwdiw8y3dhj'
Mikell-S
  • 42
  • 3