Server: postgresql - error while creating share (invalid input syntax for type bytea)

Created on 20 Aug 2020  路  12Comments  路  Source: nextcloud/server

Steps to reproduce

  1. NC installation with LDAP users that have a "," (comma) in their displayname.
  2. choose any file in the root of your own nextcloud directory
  3. click on the "share" symbol
  4. search for an LDAP user and choose him

Expected behaviour

File should be shared without error message and should appear in the files view of the choosen user.

Actual behaviour

Error message "error on sharing file" appears. Choosen user ist not listed in share list. After refreshing the browser the user is listed but the file doesn't appear in the files view of the choosen user.
The browser logs says: "Invalid text representation: 7 ERROR: invalid input syntax for type bytea"

Server configuration

Operating system:
Ubuntu 18.04.4 LTS

Web server:
Apache2 2.4.29

Database:
postgresql 10.12

PHP version:
php 7.2.24

Nextcloud version:
19.0.1

Updated from an older Nextcloud/ownCloud or fresh install:
Updated from 18.x

Where did you install Nextcloud from:
Stable release channel

Nextcloud configuration:


Config report

{
    "system": {
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "forwarded_for_headers": [
            "HTTP_X_FORWARDED",
            "HTTP_FORWARDED_FOR"
        ],
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "***REMOVED SENSITIVE VALUE***"
        ],
        "memcache.local": "\\OC\\Memcache\\Redis",
        "filelocking.enabled": "true",
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "timeout": 0,
            "dbindex": 0
        },
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "overwrite.cli.url": "***REMOVED SENSITIVE VALUE***",
        "overwriteprotocol": "https",
        "dbtype": "pgsql",
        "version": "19.0.1.1",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "ldapIgnoreNamingRules": false,
        "ldapProviderFactory": "\\OCA\\User_LDAP\\LDAPProviderFactory",
        "ldapUserCleanupInterval": "20",
        "sharing.maxAutocompleteResults": 0,
        "sharing.minSearchStringLength": 0,
        "sharing.enable_share_accept": false,
        "sharing.force_share_accept": false,
        "sharing.enable_share_mail": true,
        "updater.release.channel": "stable",
        "onlyoffice": {
            "verify_peer_off": true
        },
        "mail_smtpmode": "smtp",
        "mail_smtpauthtype": "LOGIN",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "25",
        "htaccess.RewriteBase": "\/",
        "maintenance": false,
        "theme": "",
        "log_type": "file",
        "loglevel": 1,
        "auth.bruteforce.protection.enabled": true,
        "app_install_overwrite": [
            "sharepoint"
        ],
        "mail_sendmailmode": "smtp"
    }
}

Are you using external storage, if yes which one: local/smb/sftp/ftp

Are you using encryption: no

Are you using an external user-backend, if yes which one: LDAP

Client configuration

Browser: Firefox

Operating system: Windows 10

Logs

Nextcloud log (data/nextcloud.log)

no entries regarding this issue

Browser log


Browser log

POSThttps://nextcloud.tld/ocs/v2.php/apps/files_sharing/api/v1/shares [HTTP/1.1 403 Forbidden 1112ms]

XHRPOSThttps://nextcloud.tld/ocs/v2.php/apps/files_sharing/api/v1/shares
[HTTP/1.1 403 Forbidden 1112ms]


    ocs Object { meta: {鈥, data: [] }
    meta    Object { status: "failure", statuscode: 403, message: "An exception occurred while executing 'INSERT INTO \"oc_recent_contact\" (\"actor_uid\", \"uid\", \"last_contact\", \"card\") VALUES(?, ?, ?, ?)' with params [\"x.x\", \"y.y\", 1597922779, \"BEGIN:VCARD\\r\\nVERSION:4.0\\r\\nPRODID:-\\/\\/Sabre\\/\\/Sabre VObject 4.3.0\\/\\/EN\\r\\nUID:sabre-vobject-d4ce47f0-be9d-474a-992d-9350efdafbcf\\r\\nURI:2bd9efd6-c866-4ef5-c6c5-c3ce3e5c3869\\r\\nFN:y\\\\, y\\r\\nCATEGORIES:Recently contacted\\r\\nX-NEXTCLOUD-UID:y.y\\r\\nEND:VCARD\\r\\n\"]:\n\nSQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bytea" }
    status  "failure"
    statuscode  403
    message "An exception occurred while executing 'INSERT INTO \"oc_recent_contact\" (\"actor_uid\", \"uid\", \"last_contact\", \"card\") VALUES(?, ?, ?, ?)' with params [\"x.x\", \"y.y\", 1597922779, \"BEGIN:VCARD\\r\\nVERSION:4.0\\r\\nPRODID:-\\/\\/Sabre\\/\\/Sabre VObject 4.3.0\\/\\/EN\\r\\nUID:sabre-vobject-d4ce47f0-be9d-474a-992d-9350efdafbcf\\r\\nURI:2bd9efd6-c866-4ef5-c6c5-c3ce3e5c3869\\r\\nFN:y\\\\, y\\r\\nCATEGORIES:Recently contacted\\r\\nX-NEXTCLOUD-UID:y.y\\r\\nEND:VCARD\\r\\n\"]:\n\nSQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bytea"
    data    []

0. Needs triage bug

Most helpful comment

My guess at last: Because we're using a "," (comma) in the displayname of our LDAP users we are getting this error. But I have no clue how to solve this...

All 12 comments

I can't replicate this on NC 19.0.1 with postgresql 12.2.

I'm not using LDAP though so perhaps that's the problem?

@Dragon988 - yes, it seems to be an LDAP issue:

Just created two new non-LDAP-users in nextcloud, created files and shared vice versa without any problems. Sharing these files to LDAP users doesn't work.

I've found one other strange thing regarding users on my installation:

No contacs are found/shown in the web interface, but I think all nextcloud users should be found here:
grafik

But table oc_cards is filled whith Database, Guests and LDAP users.

LDAP config test is fine and no errors are shown regarding cards in the log.

After having a closer look into it I still think it is a bug with inserting the contact data of LDAP users into the card field of the oc_recent_contact table (this table was introduced in Nextcloud 19).

It looks for me that the escaping of the card string seems to be wrong but Inserting the data manually with a query is working without any problem:

INSERT INTO "oc_recent_contact" ("actor_uid"
  ,"uid"
  ,"last_contact"
  ,"card")
VALUES('x.x'
  ,'y.y'
  ,1597988377
  ,'BEGIN:VCARD\\r\\nVERSION:4.0\\r\\nPRODID:-\\/\\/Sabre\\/\\/Sabre VObject 4.3.0\\/\\/EN\\r\\nUID:sabre-vobject-09c1209a-e63a-453c-aecd-572d686bffbd\\r\\nURI:2a74f9b4-564c-4027-96a4-6f2fa9fff5a9\\r\\nFN:y\\\\, y (y.y)\\r\\nCATEGORIES:Recently contacted\\r\\nX-NEXTCLOUD-UID:y.y\\r\\nEND:VCARD\\r\\n')

Because NC can't insert LDAP user's card data into the oc_recent_contact table sharing isn't possible to LDAP users.

Ok, the card data is generated with function generateCard in apps/contactsinteraction/lib/Listeners/ContactInteractionListener.php

After writing the card data into a more readable form I'm asking me why FN:y\\\\, y (y.y)\\r\\n includes 4 x "\"? This should be the displayname with no backslashes: FN:y, y (y.y)\\r\\n, or not?

BEGIN:VCARD\\r\\n
VERSION:4.0\\r\\n
PRODID:-\\/\\/Sabre\\/\\/Sabre VObject 4.3.0\\/\\/EN\\r\\n
UID:sabre-vobject-09c1209a-e63a-453c-aecd-572d686bffbd\\r\\n
URI:2a74f9b4-564c-4027-96a4-6f2fa9fff5a9\\r\\n
FN:y\\\\, y (y.y)\\r\\n
CATEGORIES:Recently contacted\\r\\n
X-NEXTCLOUD-UID:y.y\\r\\n
END:VCARD\\r\\n

My guess at last: Because we're using a "," (comma) in the displayname of our LDAP users we are getting this error. But I have no clue how to solve this...

cc @ChristophWurst @skjnldsv looks like an issue with the card serializer? 馃

For me it looks like card serializing is done in 3rdparty/sabre/vobject/lib/Parameter.php. But because of the four backslashes it seems that some backslashes were inserted before. Somewhere in user_ldap lib?

Im experiencing the same problem with users that have a comma in their displayname. Just tested it with two newly created local accounts. As soon as you remove the comma from the displayname everything works fine.

As a remedy you can disable the contactsinteraction app for now. We're looking into a fix.

Please check https://github.com/nextcloud/server/pull/22472 and tell me if this works for you setup :)

Please check #22472 and tell me if this works for you setup :)

Thanks, it's working as expected now! :clap:

Of course, disabling contactsinteraction is working as well :smirk:

Was this page helpful?
0 / 5 - 0 ratings