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

KeePass Import fails with large history #1729

Closed
faceroll-c293ughfp9aisucvgb3q4 opened this issue Apr 12, 2017 · 4 comments
Closed

KeePass Import fails with large history #1729

faceroll-c293ughfp9aisucvgb3q4 opened this issue Apr 12, 2017 · 4 comments

Comments

@faceroll-c293ughfp9aisucvgb3q4
Copy link

faceroll-c293ughfp9aisucvgb3q4 commented Apr 12, 2017

Steps to reproduce

  1. Create an entry in KeePass called "A" with basic info
  2. Create an entry in KeePass called "B" with a large amount of text in the description (300+ chars.)
  3. Change the entry "B" to create multiple histories (5 or more should do)
  4. Create a third entry in KeePass called "C" with basic info.
  5. Export the entries to XML
  6. Import into Teampass

Expected behaviour

  1. A imports without issue
  2. History from B gets discarded and B gets imported without issue, or ignored and reported to the user
  3. C imports without issue.
    There should be some way of sanitizing the data before it gets imported into the database, so histories get discarded, any large entries get ignored and reported back to the user, and the import should continue importing other good entries.

Actual behaviour

The error "Requested JSON parse failed." appears and the import stops. A will be imported but B and C will not.
Logs display an error:
Query: INSERT INTO teampass_items (label,description,pw,pw_iv,url,id_tree,login,anyone_can_modify) VALUES [...snip...] <br />Error: Data too long for column 'login' at row 1<br />@"

In a database with 800+ entries, having one or more with a lot of history can prevent hundreds of other entries from being imported. Makes for a mess when trying to get started with Teampass.

As a workaround, I created a copy of the KeePass DB, ran database maintenance in Keepass to delete all histories older than 0 days, then exported to XML and imported to Teampass. This doesn't protect from entries with huge descriptions though.

Server configuration

Operating system:
Ubuntu 16.04 64-bit

Web server:
Apache/2.4.18 (Ubuntu)

Database:
mysql 5.7.17-0ubuntu0.16.04.2

PHP version:
PHP 7.0.15-0ubuntu0.16.04.4
Zend Engine v3.0.0 with Zend OPcache v7.0.15-0ubuntu0.16.04.4

Teampass version:
TeamPass 2.1.27

Updated from an older Teampass or fresh install:
Fresh Install

Client configuration

Browser:
Chrome/Firefox

Operating system:
WIn10 x64

Logs

Web server error log

[Wed Apr 12 06:25:01.536789 2017] [mpm_prefork:notice] [pid 5948] AH00163: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Wed Apr 12 06:25:01.542184 2017] [core:notice] [pid 5948] AH00094: Command line: '/usr/sbin/apache2'
[Wed Apr 12 14:19:02.273412 2017] [:error] [pid 14658] [client 130.1.11.61:59709] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 14:19:02.273437 2017] [:error] [pid 14658] [client 130.1.11.61:59709] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:22:44.264915 2017] [:error] [pid 14945] [client 130.1.11.61:61189] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:22:44.264939 2017] [:error] [pid 14945] [client 130.1.11.61:61189] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:23:03.367066 2017] [:error] [pid 14652] [client 130.1.11.61:61193] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:23:03.367085 2017] [:error] [pid 14652] [client 130.1.11.61:61193] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:23:15.739122 2017] [:error] [pid 14654] [client 130.1.11.61:61195] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:23:15.739146 2017] [:error] [pid 14654] [client 130.1.11.61:61195] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:29:39.269062 2017] [:error] [pid 14656] [client 130.1.11.61:61275] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:29:39.269088 2017] [:error] [pid 14656] [client 130.1.11.61:61275] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:34:13.991535 2017] [:error] [pid 15434] [client 130.1.11.61:61323] PHP Notice:  Undefined variable: items in /var/www/html/sources/folders.queries.php on line 226, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:34:13.991563 2017] [:error] [pid 15434] [client 130.1.11.61:61323] PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/sources/folders.queries.php on line 226, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:34:39.797699 2017] [:error] [pid 14655] [client 130.1.11.61:61331] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:34:39.797739 2017] [:error] [pid 14655] [client 130.1.11.61:61331] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:34:52.095478 2017] [:error] [pid 14654] [client 130.1.11.61:61333] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:34:52.095498 2017] [:error] [pid 14654] [client 130.1.11.61:61333] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:35:02.091413 2017] [:error] [pid 14945] [client 130.1.11.61:61339] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:35:02.091432 2017] [:error] [pid 14945] [client 130.1.11.61:61339] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:35:14.414543 2017] [:error] [pid 15434] [client 130.1.11.61:61349] PHP Warning:  SessionHandler::write(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/html/sources/SecureHandler.php on line 74, referer: http://teampass/index.php?page=items
[Wed Apr 12 15:35:14.414563 2017] [:error] [pid 15434] [client 130.1.11.61:61349] PHP Warning:  session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions) in Unknown on line 0, referer: http://teampass/index.php?page=items

Insert your webserver log here


#### Firebug log ([How to?](http://teampass.net/2014-02-09-how-to-communicate-an-error-log))

Insert the Firebug log here


@Cytrian
Copy link

Cytrian commented Apr 13, 2017

Yes, the session id is broken in one case:
Normally, my session id is like: g1kuqrqpblgdo6vcu501mjphj4
When doing KeePass import it sometimes is
'.$_SESSION['user_id'];?>
This seem to come from bad HTML code generated by item.import.php:

[..]
                BeforeUpload: function (up, file) {
                    up.settings.multipart_params = {
                        "PHPSESSID":"'.$_SESSION['user_id'];?>",
                        "csvFile":file.name,
                        "type_upload":"import_items_from_csv",
                        "user_token": $("#import_user_token").val()
[..]

@Cytrian
Copy link

Cytrian commented Apr 13, 2017

But even, when I fix this bug by replacing

    "PHPSESSID":"'.$_SESSION['user_id'];?>",
    "PHPSESSID":"<?php echo session_id(); ?>",

in items.import.php, the import does not work for me (latest 'master' 617f151) but tells me, that my XML file isn't a Keepass XML file.
But I think, these 2 lines are completely unnecessary and should be removed?

@nilsteampassnet
Copy link
Owner

The error shows that it is field login that not enough long for the data you want to store.
I will trunk the data if too long.

Now it seems you have also so issue on your server.
Check if you have permission correctly set for upload-tmp-dir?

@faceroll-c293ughfp9aisucvgb3q4
Copy link
Author

faceroll-c293ughfp9aisucvgb3q4 commented Apr 13, 2017

Thanks @nilsteampassnet, I wasn't aware upload-tmp-dir needed to be set in php.ini.
This was empty on Ubuntu which must have been causing the issue.
I've just configured this setting and will see if this still appears in the apache logs.

For the original issue, I just ran through another test. Here's the error log without me editing the actual info out (my OP contained production info, sorry). The description is being duplicated to the login field when there is a lot of history. I've attached the test XML from this error test.txt. If you delete the entire <history> block, it imports just fine.

Query: INSERT INTO teampass_items (label,description,pw,pw_iv,url,id_tree,login,anyone_can_modify) VALUES ('B', 'asd;lfkj qp3ewfji qp-[wcom-[304fj- [ocm;aolskdcmj; aoldnjc;v oaijdv-[saeirmfl d;askmvca p;osidjcf-p[40iwmnadsfjfals cmkpAS)Id=-jca 0kwm4;rflamksdc-awkmadsf4falm cdasdf-q3im4f lamksdc-awk3emfa;lwmkcf-a0imkw3rf;.a,mc';[poak=wadsf0oekt';aslmvgs[-0dj4=0mgs';lmkvd=-09j54 t;5elmg=[s0asdf9dje gs;l,5m4 ty=[0s9djbvgse54;/smle[ basdfv9js[0e tm/s;,lbmv'[s9i=4oktmw;es/flmb-[s0d9ij=]-54pomg'spovfkj=s0rkety's;lfmb=s-0ie5[;ysmlesd[b9g0i=s-e5kyhg's;lfbv=gs-90ei5k'y;slfmkb-0si=45adsf-0tyks';dfl,bs-[0ire4=t-o45]pytgklsd=-ie54 yplskm'bkv=s-e5i ;lyk[s90ib=09s d5rjy3';hl=gsd9i e5r3kij4'5tg;lms=90uei 5r35ymj'; m4lg=-[90su-5 3kj5gj', 'def5020038a7df503d2b058356f16a51946ac3efafc25537941fae50d6c95d152c2d26316a4b37ea4fa6cd4544533ee6ca97cb0f8decc5eb8e56c5774f74b59f7d32ca1b7c0d7e69ee61ed7409ae5a65c3ccc5de92fbec3211154ee738c8ce9fb3cc17e981c986dc', NULL, '', 263, 'asd;lfkj qp3ewfji qp-[wcom-[304fj- [ocm;aolskdcmj; aoldnjc;v oaijdv-[saeirmfl d;askmvca p;osidjcf-p[40iwmnjfals cmkpAS)Id=-jca 0kwm4;rflamksdc-awkm4falm cd-q3im4f lamksdc-awk3emfa;lwmkcf-a0imkw3rf;.a,mc';[poak=w0oekt';aslmvgs[-0dj4=0mgs';lmkvd=-09j54 t;5elmg=[s09dje gs;l,5m4 ty=[0s9djbvgse54;/smle[ bv9js[0e tm/s;,lbmv'[s9i=4oktmw;es/flmb-[s0d9ij=]-54pomg'spovfkj=s0rkety's;lfmb=s-0ie5[;ysmlesd[b9g0i=s-e5kyhg's;lfbv=gs-90ei5k'y;slfmkb-0si=45-0tyks';dfl,bs-[0ire4=t-o45]pytgklsd=-ie54 yplskm'bkv=s-e5i ;lyk[s90ib=09s d5rjy3';hl=gsd9i e5r3kij4'5tg;lms=90uei 5r35ymj'; m4lg=-[90su-5 3kj5gj', 0)<br />Error: Data too long for column 'login' at row 1<br />@

nilsteampassnet pushed a commit that referenced this issue Apr 20, 2017
Fix for #1727, #1729 and #1733
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants