Nextcloud Text fails after a couple of minutes with HTTP 412 "CSRF check failed"

Nextcloud version (eg, 20.0.5): 20.0.7
Operating system and version (eg, Ubuntu 20.04): RHEL 7.9
Apache or nginx version (eg, Apache 2.4.25): unsure
PHP version (eg, 7.4): 7.4.15

I have a reproducible and very annoying problem with my Nextcloud installation. Whenever I use the “Nextcloud Text” markdown editor, I get an error after about 30-180s of use. It always works fine in the beginning, but after given amount of time I get a “File could not be loaded. Please check your internet connection. (Retry)” error in the UI and I can’t continue editing the file until I refresh the browser (after which everything works fine again for a couple of seconds/minutes).

I inspected my console/network traffic in the Dev Tools while this happens:

There’s regular requests to /sync and /push endpoints, which alle work fine and return 200. But suddently, out of nowhere, the requests to these endpoints fail with a “HTTP 412 Precondition failed”. In the body of the 412 responsse I see a “CSRF check failed”.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => '***',
  'passwordsalt' => '***'',
  'secret' => '***'',
  'trusted_domains' =>
  array (
    0 => '***'',
    1 => 'cloud.mydomain.de',
  ),
  'datadirectory' => '/home/username/nextcloud_data',
  'dbtype' => 'mysql',
  'version' => '20.0.7.1',
  'overwrite.cli.url' => 'https://cloud.mydomain.de',
  'dbname' => 'username',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'username',
  'dbpassword' => '***',
  'installed' => true,
 [... mail stuff here]
  'maintenance' => false,
  'loglevel' => 2,
  'default_language' => 'de',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'updater.release.channel' => 'stable',
  'redis' =>
  array (
    'host' => '/home/username/.redis/sock',
    'port' => '0',
    'timeout' => '1.5',
  ),
  'filelocking.enabled' => 'true',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'htaccess.RewriteBase' => '/',
  );

Nothing in the server/error logs at the time of this happening.

I know this forum is not for the Nextcloud App, but the given error is thrown in Nextcloud core, not in the app, so I thought this might still be the right place.

Found some other threads with people having a HTTP412 error during logout, but it seems to be unrelated. My logout works fine. However I feel like I sometimes also get this error during browsing files, but I am not able to recreate it as easily as the error int Nextcloud Text.

Any ideas why the CSRF error is thrown right out of nowhere?