Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login rate limiting sends local time to database (postgres) which causes undesired effects #5708

Closed
scott323 opened this issue Mar 25, 2017 · 6 comments

Comments

@scott323
Copy link

My postgres db is set to use UTC as default timezone.
My system (and PHP) is set to use Europe/Bratislava as default timezone (currently it's UTC +01:00).
Column definition for users.failed_login is "timestamp with time zone", but roundcube omits timezone when setting it's value, which results in incorrect calculations in rate limiting function in rcube_user->failed_login().

Proposed (and tested) solution is simple patch:

--- roundcubemail/program/lib/Roundcube/rcube_db_pgsql.php.orig 2017-03-25 17:43:01.713984686 +0100
+++ roundcubemail/program/lib/Roundcube/rcube_db_pgsql.php      2017-03-25 17:43:39.654363537 +0100
@@ -231,4 +231,12 @@
         return $sql;
     }
 
+    /**
+     * Use ISO 8601 date (includes timezone info)
+     */
+    public function fromunixtime($timestamp)
+    {
+        return date("'c'", $timestamp);
+    }
+
 }
@alecpl
Copy link
Member

alecpl commented Mar 26, 2017

I'm afraid that's only one of many issues that you can hit when database uses different timezone than Roundcube. We do have a check for this in the installer. So, probably not something that we can fix easily.

@alecpl
Copy link
Member

alecpl commented Mar 27, 2017

For MySQL we use datetime type which ignores timezone. So, I think the best solution here would be to convert all columns to timestamp without time zone.

@alecpl alecpl added this to the 1.3-rc milestone Mar 27, 2017
@thomascube
Copy link
Member

AFAIK the datetime types in MySQL are not timezone-aware and therefore we require the database to use the same timezone as the Roundcube webserver. For other database backends which are timezone-aware, we should produce datetime values that include timezone information of the webserver. I suppose that's what @scott323 suggests here and I think that's the right approach.

@alecpl
Copy link
Member

alecpl commented Mar 31, 2017

@thomascube If we set timezone on input to db we'll need to make sure to handle it correctly on output. I tried to skip this requirement if possible and find a "global" solution. I was afraid we'll have to modify some more code, but maybe it's not that bad.

@alecpl
Copy link
Member

alecpl commented Apr 3, 2017

While it could be fixed this way:

--- a/program/lib/Roundcube/rcube_db_pgsql.php
+++ b/program/lib/Roundcube/rcube_db_pgsql.php
@@ -37,6 +52,7 @@ class rcube_db_pgsql extends rcube_db
     protected function conn_configure($dsn, $dbh)
     {
         $dbh->query("SET NAMES 'utf8'");
+        $dbh->query("SET TIME ZONE '" . date_default_timezone_get() . "'");
     }
.
     /**

I have a feeling this may be fragile. So, I'm going to fix this in a proposed way, though slightly improved.

alecpl added a commit that referenced this issue Apr 3, 2017
…than PHP host (#5708)

Allow passing DateTime variables as query arguments. Their value will
be converted to date/time input string in format specific to the database type
(with timezone on postgres).
@alecpl
Copy link
Member

alecpl commented Apr 3, 2017

Fixed. Though I wouldn't apply the fix to a stable branch yet.

@alecpl alecpl closed this as completed Apr 3, 2017
ZiBiS added a commit to ZiBiS/roundcubemail that referenced this issue Apr 13, 2017
* 'master' of https://github.com/roundcube/roundcubemail: (36 commits)
  Remove note about mail() function
  Update changelog
  Revert "extend plugin password to avoid sudo (use ssh instead calling chpasswd) (roundcube#5654)"
  Add Log to STDOUT Feature (roundcube#5721)
  extend plugin password to avoid sudo (use ssh instead calling chpasswd) (roundcube#5654)
  Fix bug where base_dn setting was ignored inside group_filters (roundcube#5720)
  Bump Net_Socket version
  Installer: Fix DB schema initialization on MS SQL Server
  Update to TinyMCE 4.5.6
  Fix undesired effects when postgres database uses different timezone than PHP host (roundcube#5708)
  Fix bug where namespace prefix could not be truncated on folders list if show_real_foldernames=true (roundcube#5695)
  Fix (restore) Tab key behaviour in autocomplete popup (roundcube#5659)
  Fix regression in LDAP fuzzy search where it always used prefix search instead (roundcube#5713)
  Ignore js deps (roundcube#5704)
  Update changelog
  Add support for DelSp=Yes messages (roundcube#5702)
  Fix permission of temporary files and removal of them when generating thumbnails
  Remove redundant entry
  Fix require entry for crypt_gpg also in Enigma's composer.json
  Use jQuery 3.2.1
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants