The question of whether cookies are safe is incorrect. Cookies themselves do not pose any threat.
This or that scheme of their use can be safe or vulnerable.
For example, a specific implementation of an authentication or authorization system that uses cookies may well be insecure. There are just a lot of common mistakes that developers make using cookies. These errors cause vulnerabilities in systems that use cookies (and not in the cookies themselves).
The article mentioned by you in no way states that the "cookies are bad and unsafe", and it is not proposed to abandon them. This article discusses the specific cases of errors and omissions in the implementations of the systems working with cookies . And a combination of certain shortcomings already creates a vulnerability that can be exploited.
Now about the typical threats.
You argue that it is not so easy to get cookies out.
First, in order to run JS on the site, it is not necessary to "hack hosting". Often it’s enough to find an XSS vulnerability , a great many techniques.
Tip: Using Content Security Policy greatly facilitates protection against XSS, CSSI, and clickjacking.
Indeed, as Konstantin Alekseev mentioned, it is useful to use httpOnly-cookies, for those cases when access from JS is not needed, so that even if a malicious script is executed, it does not have access to the value of the cookie.
But, again, this is not 100% protection against reading cookies. The cookie information with the "httpOnly" flag comes in the http header. If the site is subject to HTTP Response Splitting , the response from the server can be modified (to disable the httpOnly flag), and the old cookie values ​​are shifted into the response body. Here is a minimalistic example .
Please note that not only the theft of cookies with secret data is dangerous .
Cookies also have inter -site request forgery (CSRF) vulnerabilities. In this case, “theft of cookies” is not supposed: an attacker simply needs some of the methods to force the user's browser to make one or another request to the attacked server (and the user's browser will substitute the cookie itself, the attacker does not need to know them). If the server is vulnerable to a CSRF vulnerability, then an attacker can perform an action (buying, changing data, post) on behalf of the user, without knowing the meaning of the cookie itself.
Therefore, when performing requests to change a state, cookies are usually used in conjunction with csrf tokens. There are different types of security implementations with csrf-tokens (including sometimes not very successful: in the article you cited from the habr, a vulnerability was shown in the double submit cookies scheme, which appeared because of the features of the third-party system).
Look also at such vulnerabilities as session fixation , which are also indirectly related to cookies, but do not require their “theft”.
In the end, even some kind of SQLi attack vector can be inserted by an attacker directly into the value of cookies, manually creating a request to your site. And, if you do not filter / do not screen the contents of cookies, and then substitute it in this form in the sql query string, it turns out "unsafe": the base of your resource may go, in some cases sqli lead to remote code execution.
Are all cookies guilty? Not. But, as you see, it is also impossible to relax, the dangers are literally everywhere. :)