Skip to content

Proxy push loops forever (100% CPU) when the payload exceeds 200 bytes without the subject #3598

Open

Description

@motoki317

How to use GitHub

  • Please use the 👍 reaction to show that you are affected by the same issue.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Steps to reproduce

  1. Log in to the Nextcloud Android or iOS app as admin, which registers a proxy push device.
  2. In the Nextcloud folder, run:
    S=$(printf '/%.0s' $(seq 64))
    sudo -u www-data php occ notification:generate admin test --object-type="$S" --object-id="$S"
    The object type and ID are 64 slashes each. JSON writes each / as \/, so they exceed the 200-byte proxy payload before the subject is added.

Expected behaviour

occ notification:generate returns.

Actual behaviour

occ notification:generate never returns and uses 100% of one CPU core.

On my server, cron.php looped the same way when the announcements crawler pushed the announcement with the link https://cert.europa.eu/publications/security-advisories/2026-018 to admin.

Cause

encodeNotif() gives the subject the bytes that the other fields leave of the 200-byte proxy payload:

notifications/lib/Push.php

Lines 908 to 932 in cd6d232

protected function encodeNotif(int $id, INotification $notification, int $maxLength): array {
$data = [
'nid' => $id,
'app' => $notification->getApp(),
'subject' => '',
'type' => $notification->getObjectType(),
'id' => $notification->getObjectId(),
];
// The link lets the service worker navigate on notificationclick; the
// subject budget below shrinks accordingly, very long links are dropped
$link = $notification->getLink();
if ($link !== '' && strlen($link) < 128) {
$data['link'] = $link;
}
// Max length of encryption is ~240, so we need to make sure the subject is shorter.
// Also, subtract two for encapsulating quotes will be added.
$maxDataLength = $maxLength - strlen((string)json_encode($data)) - 2;
$data['subject'] = Util::shortenMultibyteString($notification->getParsedSubject(), $maxDataLength);
if ($notification->getParsedSubject() !== $data['subject']) {
$data['subject'] .= '…';
}
return $data;
}

If the other fields take more than 198 bytes, that length is negative, and OCP\Util::shortenMultibyteString() loops forever. Its condition strlen(json_encode($temp)) - 2 > $dataLength stays true even for ''.

In my case, the link caused it. Since #3478, first shipped in 35.0.3, the other fields include the link. With it, the announcement's other fields took 207 bytes, so the length was 200 - 207 - 2 = -9. Without it, the length is 70.

Fix idea

  • In encodeNotif(), drop the link when it makes the length negative.
  • Pass at least 0 to shortenMultibyteString(), so that long object types or IDs cannot loop either.

Server configuration

Nextcloud version: 35.0.3 (notifications 8.0.1)

Activity

  1. nickvergessen commented on Nov 15, 2026

    @nickvergessen
    Member

    On my server, cron.php looped the same way when the announcements crawler pushed the announcement with the link https://cert.europa.eu/publications/security-advisories/2026-018 to admin.

    That sounds weird, as that uses much shorter objectId (value this time was 5), ah nvm we add the link in the push content.

    Rest however sounds plausible and we should try to address it

  2. nickvergessen commented on Nov 15, 2026

    @nickvergessen
    Member

    The object type and ID are 64 slashes each. JSON writes each / as /, so they exceed the 200-byte proxy payload before the subject is added.

    This is not considered a valid behaviour for the app sending the notification and it will result in errors if that makes the object data too long.
    But it should not create an infinite loop

  3. mafel786 commented on Nov 15, 2026

    @mafel786

    Additional data point from our instance: 34.0.6 (bundled notifications 7.0.0-dev.1, whose encodeNotif() already adds the link). Here the trigger was the core CheckCodeIntegrityJob run by cron.php.

    The integrity result had changed (a single modified core/js/mimetypelist.js after we added a custom mimetype mapping), so the job notified the admins. Its object ID is the 64-char sha256 fingerprint and the link is 59 chars, so the subject budget in encodeNotif(…, 200) becomes -13. cron.php then hung for 14 h at 100 % CPU on one core (no syscalls, no I/O).

    Stack captured via pcntl alarm:

    #0 OCP\Util::shortenMultibyteString()            lib/public/Util.php:606
    #1 OCA\Notifications\Push->encodeNotif()          apps/notifications/lib/Push.php:928
    #2 OCA\Notifications\Push->encryptAndSign()       apps/notifications/lib/Push.php:1022
    #3 OCA\Notifications\Push->proxyPushToDevice()    apps/notifications/lib/Push.php:468
    #4 OCA\Notifications\Push->pushToDevice()         apps/notifications/lib/Push.php:378
    #5 OCA\Notifications\App->notify()                apps/notifications/lib/App.php:37
    #6 OC\Notification\Manager->notify()              lib/private/Notification/Manager.php:311
    #7 OC\Core\BackgroundJobs\CheckCodeIntegrityJob->notifyAdmins()  core/BackgroundJobs/CheckCodeIntegrityJob.php:179
    #8 OC\Core\BackgroundJobs\CheckCodeIntegrityJob->run()           core/BackgroundJobs/CheckCodeIntegrityJob.php:79
    

    A stable34 backport of #3603 and nextcloud/server#66629 would fix this for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions