Cookie Security Issues
I mentioned these points in #73 (closed). The bug itself got fixed but the security items were not, so I'm posting them again here. Since cookies are used for authentication, these should be addressed.
-
Authentication cookies don't need to be accessible to JavaScript on the client side. Having them accessible via JavaScript leaves the system open to XSS attacks whereby a malicious script can directly access the user's authentication cookies. Cookies should be set on the server, using the http.SetCookiefunction in a page handler, and should have theHttpOnlyproperty set totrue. This makes it so JavaScript cannot read/write the cookie values, but the cookies are still submitted with ajax requests viaXmlHttpRequest. -
If the base URL for Commento is prefixed with https, theSecureproperty should be set totrueso that cookies are not sent over unencrypted/insecure connections. -
If the base URL for Commento contains a subdirectory, the Pathproperty on the cookie should be set to that path. This prevents an application atexample.com/foofrom receiving and/or manipulating a Commento cookie fromexample.com/commento. All paths underPathstill receive the cookie, so Commento should not be affected by the change. -
Administrative cookies should ideally be separate from commenting cookies, and the administrative cookies should have SameSiteset to true. This is an experimental (not widely adopted) property that tells browsers to send the cookie only when the requesting origin is the same as origin being requested. So the admin cookie is only sent when accessing the Commento admin page, but not any site being served comments by Commento. This can be made more secure by changing thePathproperty on this cookie to match only the administrative pages. -
Cookies should be secured against modification. I'm using gorilla/securecookiein my own projects, as this makes it easy to validate the cookie with HMAC and optionally encrypt the contents before sending to the client.