]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Do not check the IP address with session protection disabled 1182/head
authorArthurHoaro <arthur@hoa.ro>
Tue, 17 Jul 2018 12:13:37 +0000 (14:13 +0200)
committerArthurHoaro <arthur@hoa.ro>
Tue, 17 Jul 2018 12:13:37 +0000 (14:13 +0200)
This allows the user to stay logged in if his IP changes.

Fixes #1106

application/security/LoginManager.php
tests/security/LoginManagerTest.php

index d6784d6da6424e266a21702b7f0686746e91fe20..5a58926dd16b441fa4b36db5e2c87d790c8ed07d 100644 (file)
@@ -58,6 +58,9 @@ class LoginManager
      */
     public function generateStaySignedInToken($clientIpAddress)
     {
+        if ($this->configManager->get('security.session_protection_disabled') === true) {
+            $clientIpAddress = '';
+        }
         $this->staySignedInToken = sha1(
             $this->configManager->get('credentials.hash')
             . $clientIpAddress
index f26cd1eb8635c0bd21f8f4ab68043b7569562ddf..b9ab5ec45929025d0de81040c8c9521f2785b4b0 100644 (file)
@@ -259,6 +259,20 @@ class LoginManagerTest extends TestCase
         );
     }
 
+    /**
+     * Generate a token depending on the user credentials with session protected disabled
+     */
+    public function testGenerateStaySignedInTokenSessionProtectionDisabled()
+    {
+        $this->configManager->set('security.session_protection_disabled', true);
+        $this->loginManager->generateStaySignedInToken($this->clientIpAddress);
+
+        $this->assertEquals(
+            sha1($this->passwordHash . $this->salt),
+            $this->loginManager->getStaySignedInToken()
+        );
+    }
+
     /**
      * Check user login - Shaarli has not yet been configured
      */