Переключение между страницами HTTP и HTTPS с безопасным файлом cookie сеанса

Обновление: Обратите внимание, что каждый веб-сайт, переключающийся между незащищенными HTTP-страницами и зашифрованными HTTPS-страницами, неизбежно подвержен SSL-полосе . Пожалуйста, подумайте об использовании HTTPS для всего сайта, хотя это не может предотвратить SSL-полосу, по крайней мере, это дает пользователю возможность безопасно позвонить на сайт, если ему это небезразлично. Для сайтов, которым необходимо переключиться, этот метод, вероятно, по-прежнему лучший вариант.

Это распространенный сценарий, что на веб-сайте есть страницы с конфиденциальными данными, доступ к которым должен осуществляться только с помощью протокола HTTPS, и другие страницы с некритическими данными.

Я нашел решение, которое позволяет переключаться между безопасными и незащищенными страницами, сохраняя при этом сеанс, и хотел бы to спрашивать вас о каких-либо намёках на недостатки концепции. Всю статью вы можете найти здесь: Безопасный файл cookie сеанса с SSL (of course i'm also happy to hear, that it is safe).

The problem

HTTPS makes sure, that nobody between client and server can eavesdrop our communication and prevents a man-in-the-middle attack. Unfortunately this doesn't apply to the session-cookie, it is sent to unencrypted requests too.

PHP offers the function session_set_cookie_params(...) with the parameter $secure. This is what we need, but it leaves us to the problem that we loose our session, when we switch to an unsecure page.

The authentication cookie

The idea of the authentication cookie is, that when the user enters his password (increases his access privileges), we create a second cookie additionally to the unsecure session-cookie, and make sure that only encrypted HTTPS pages have access to it.

https://www.example.com/login.php

login');
  ...
?>

Now every page (HTTPS and HTTP) can read the unsecure session-cookie, but pages with sensitive information can check for the secure authentication cookie.

https://www.example.com/secret.php


An attacker could manipulate the session cookie, but he never has access to the authentication cookie. Only the person who entered the password, can own the authentication cookie, it's always sent over encrypted HTTPS connections.

Thanks a lot for every answer!

28
задан martinstoeckli 7 June 2013 в 14:59
поделиться