I have a (hobby) web site that runs only on SSL (i.e., site-wide HTTPS). The site does not deal with finances, social security numbers, or anything of that level of importance. However, I'd like to secure it as much as reasonably possible. When a user logs in, two cookies are written: one cookie stores the user id and a second stores a session id. Cookies are marked Secure and HttpOnly.
I have one directory where I'd like all registered users to be able to access files. It seems to me that one way to accomplish this is to use .htaccess in the key directory to see if there is a valid user-id cookie: If so, grant access, but if not, redirect to the login page. This way, I do not need to keep updating legal values for the cookie or have much overhead in checking access.
I found the following code for .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} !^.*cookie-name.*$ [NC]
RewriteRule .* /login-error/set-cookie-first.html [NC,L]
and this is all working fine: When logged in as a registered user (i.e., when there is a cookie called cookie-name) I get access to the directory; when not logged in, I'm redirected to the login page.
However, I'm wondering: What security issues have I overlooked? For example, is it possible for an attacker to create a cookie with the correct name in the attacker's browser and then have my system think that's a real cookie?