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

Sabre\DAV\Exception\InvalidSyncToken: Invalid or unknown sync token #1490

Open
onxipole opened this issue Sep 29, 2023 · 5 comments
Open

Sabre\DAV\Exception\InvalidSyncToken: Invalid or unknown sync token #1490

onxipole opened this issue Sep 29, 2023 · 5 comments

Comments

@onxipole
Copy link

Hello everyone and sorry if this issue has already been documented.

I have repeated errors of the same kind in my php error log, and the sync process between client and server doesn't work :

[29-Sep-2023 10:35:00 Europe/Paris] Sabre\DAV\Exception\InvalidSyncToken: Invalid or unknown sync token in /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Sync/Plugin.php:116
Stack trace:
#0 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Sync/Plugin.php(62): Sabre\DAV\Sync\Plugin->syncCollection()
#1 /home/mydomain/public_html/vendor/sabre/event/lib/WildcardEmitterTrait.php(89): Sabre\DAV\Sync\Plugin->Sabre\DAV\Sync{closure}()
#2 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/CorePlugin.php(685): Sabre\DAV\Server->emit()
#3 /home/mydomain/public_html/vendor/sabre/event/lib/WildcardEmitterTrait.php(89): Sabre\DAV\CorePlugin->httpReport()
#4 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Server.php(472): Sabre\DAV\Server->emit()
#5 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Server.php(253): Sabre\DAV\Server->invokeMethod()
#6 /home/mydomain/public_html/vendor/sabre/dav/lib/DAV/Server.php(321): Sabre\DAV\Server->start()
#7 /home/mydomain/public_html/Core/Frameworks/Baikal/Core/Server.php(119): Sabre\DAV\Server->exec()
#8 /home/mydomain/public_html/html/dav.php(69): Baikal\Core\Server->start()
#9 {main}

I tried to update a contact (or add a new one), it stays on the client but doesn't record in the server, meaning it is not available for other clients.

The section it is referring to is that one :

$syncToken = $report->syncToken;
if (!is_null($syncToken)) {
// Sync-token must start with our prefix
if (self::SYNCTOKEN_PREFIX !== substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX))) {
throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token');
}

By performing searches on the Internet, I found a post with this workaround :

Since I really wanted the sync to work, I hacked my own system as follows:
After https://github.com/sabre-io/dav/blob/3.2/lib/DAV/Sync/Plugin.php#L119 (which is in lib/composer/sabre/dav/lib/DAV/Sync/Plugin.php) I added the following.
Definitely not a final solution; use at your own risk, I don't know the cardDAV specs nor the ownCloud system.

    $syncToken = $report->syncToken;
    // very crude macOS Mojave (10.14) Contacts sync "fix"
    // @see https://github.com/owncloud/core/issues/30820
    if ( \preg_match('/^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$/', $syncToken) ) {
      $syncToken = null;
    }

ownCloud now just outputs the full REPORT and the contacts app syncs correctly (as far as I have tested it with ownCloud, macOS and my Android phone).

What to think about this ?

Mac OS 10.13.6
DEBIAN 10 - Baïkal 0.9.3

Thanks everyone !

@DeepDiver1975
Copy link
Member

There is not really much we can do (see owncloud/core#30820) Apple is not compliant to the specs and is basically ignored since 2018. I have little hope they will fix their software.

Feel free to try the hack at your own risk. 🙈

@onxipole
Copy link
Author

Than you very much for this kind answer, DeepDiver1975. The problem is that the .php file I have to edit is slightly different than the example shown by joostdekeijzer. It states line 119 : https://github.com/sabre-io/dav/blob/3.2/lib/DAV/Sync/Plugin.php#L119, but I see the same stuff in my .php file on line 116 and I don't clearly understand what joostdekeijzer means by adding after line 119 (it seems to be the beginning of something)....

@onxipole
Copy link
Author

This is in joostdekeijzer file :

    $syncToken = $report->syncToken;
    if (!is_null($syncToken)) {
        // Sync-token must start with our prefix
        if (substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) {
            throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token');
        }

        $syncToken = substr($syncToken, strlen(self::SYNCTOKEN_PREFIX));

    }

What's in mine :

   $syncToken = $report->syncToken;
    if (!is_null($syncToken)) {
        // Sync-token must start with our prefix
        if (self::SYNCTOKEN_PREFIX !== substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX))) {
            throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token');
        }

        $syncToken = substr($syncToken, strlen(self::SYNCTOKEN_PREFIX));
    }

I know I may break things, but I would like to try, because it seems promising. Where should I insert the lines ?

I am not a coder and I don't clearly understand, so any help would be much appreciated.

@onxipole
Copy link
Author

Should this section look like this when code portion in inserted ?
Am I doing wrong ? Is it not the correct insertion point ?

$syncToken = $report->syncToken;
if ( \preg_match('/^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$/', $syncToken) ) {
$syncToken = null;
}
if (!is_null($syncToken)) {
// Sync-token must start with our prefix
if (self::SYNCTOKEN_PREFIX !== substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX))) {
throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token');
}

    $syncToken = substr($syncToken, strlen(self::SYNCTOKEN_PREFIX));
}

@onxipole
Copy link
Author

I also found this post : https://developer.apple.com/forums/thread/691818

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

2 participants