2012-05-09 16 views
11

Vorrei sapere come impostare i cookie come HTTPOnly in Codeigniter. Ho esaminato la documentazione e non ho visto come impostare questo flag.impostazione cookie con flag HTTPOnly nel codeigniter

ero anche cercando di impostare il flag sicuro per i biscotti e l'ho trovato nel file config.php:

$config['cookie_secure'] = TRUE; 

ma non c'era un'opzione HTTPOnly nel file config.php.

Come impostare tutti i cookie su HTTPOnly? E se è fatto nel framework, sarebbe utile sapere dove quel codice è per il mio apprendimento (e quale è l'impostazione predefinita).

risposta

23

Fortunatamente è possibile visualizzare il codice sorgente per Session.php su GitHub

In funzione _set_cookie si vedrà:

// Set the cookie 
setcookie(
    $this->sess_cookie_name, 
    $cookie_data, 
    $expire, 
    $this->cookie_path, 
    $this->cookie_domain, 
    $this->cookie_secure, 
    $this->cookie_httponly 
); 

Il valore per $this->cookie_httponly viene assegnato nel __construct e il valore predefinito è falso, ma è possibile impostare TRUE attraverso config.php come segue:

$config['cookie_httponly'] = TRUE; 

Ciò ENABL e i tuoi cookie all'interno del framework devono essere HTTPOnly.

+0

Grazie per questo. Accettato e upvoted. Buona cosa che ho chiesto. – chowwy

+2

Questo non funziona più nella versione 2.1.3 come menzionato nel commento qui sotto. – ethicalhack3r

3

2.1.3 non contiene cookie_httponly nel foreach, quindi non lo imposterà.

foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) 

anche non imposta qui ...

setcookie(
       $this->sess_cookie_name, 
       $cookie_data, 
       $expire, 
       $this->cookie_path, 
       $this->cookie_domain, 
       $this->cookie_secure 
      ); 
+0

Posso confermarlo nei miei test, sai come può essere impostato? – ethicalhack3r

+0

Quindi, come può essere fatto ora? –

8

ho scoperto che il loro è un drwaback in seduta mgmt di CodeIgniter perché

-

  1. 2,1 .3 versione non è un flag cookie_httponly.
    01 Soluzione:
    Passaggio 1: È necessario creare il proprio My_session.php nella libreria ed estendere il file di sessione del sistema o modificare Session.php (in system-> library-> Session.php file)
    Passaggio 2: trovare _set_cookie ($ cookie_data = NULL) la funzione, goto setcookie() e modificare come

    setcookie( $this->sess_cookie_name, $cookie_data, $expire,
    $this->cookie_path, $this->cookie_domain, $this->cookie_secure, TRUE ); // add True flag.

  2. Anche se se si aggiunge "TRUE" e se il test con lo strumento OWASP ZAP,
    qualche tempo ll darvi CSRF problemi
    vale a dire: HTTPONLY non è vero,
    Flag sicuro non è abilitato.

    Motivo: dal momento che sess_destroy stanno impostando il flag HTTPONLY e Secure su none.
    Soluzione: Aggiornamento funzione sess_destroy in Session.php come

    // Kill the cookie 
    `setcookie(
          $this->sess_cookie_name, 
         addslashes(serialize(array())), 
         ($this->now - 31500000), 
         $this->cookie_path, 
         $this->cookie_domain, 
         TRUE, 
         TRUE 
        );` 
    

Dal momento che questi problemi mi ha dato notti insonni quindi spero che questo vi aiuterà pure. :)

Problemi correlati