Score:1

Is there any difference between using a cookie and using a normal header in the case of HTTP communication?

tr flag

I have a system consisting of a custom software and an HTTP server. The software will send some requests with some headers and the HTTP server will send response back.

Now I have some custom authentication related headers that the server will send to the software, the software will keep those headers and send them back in each additional requests to bypass the authentication process.

Based on my understanding, this should be done using cookies. However in the custom software development adding normal headers is easy while adding cookies are harder to implement, and using normal headers works functionally as well based on testing.

What I want to know is, is there any security reason and/or other reasons that a cookie should be used instead of a normal HTTP custom header?

cn flag
Cookies are also often set by sending a header from the server - in node for example: `res.setHeader('Set-Cookie', 'sessionCookie=value; HttpOnly');`
Score:2
cn flag
Bob

That is more a software development question and likely to attract better answers on the StackOverflow, Software Engineering or possibly the security SE sites.

But the most simple answer is that a header is set by the client and generally static, like for example including a particular API token with every request.

Sessions and cookies get set by the server. The later gives the server more control and arguably better security. The server can expire them while not invalidating the actual credentials with which you authenticate, making you re-authenticate (for example always after X hours or some idle time) or change their value to prevent session high jacking or replay attacks.

cn flag
To add - cookies can also be encrypted by the server so that the client can't easily modify them!
in flag
Cookie will be sent in each request while Header not always.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.