nextcloud / files_lock

GNU Affero General Public License v3.0
24 stars 8 forks source link

Error on files drop: Call to a member function getUID() on null #74

Closed nickvergessen closed 2 years ago

nickvergessen commented 2 years ago

c.nc.c today (so 24.0.1)

{
  "reqId": "Y1qDC9YIlMzWOi9qrs1h",
  "level": 4,
  "time": "2022-05-25T08:31:43+00:00",
  "remoteAddr": "…",
  "user": "--",
  "app": "webdav",
  "method": "PUT",
  "url": "/public.php/webdav/…",
  "message": "Call to a member function getUID() on null",
  "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15",
  "version": "24.0.1.1",
  "exception": {
    "Exception": "Error",
    "Message": "Call to a member function getUID() on null",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/html/apps/files_lock/lib/DAV/LockBackend.php",
        "line": 153,
        "function": "getFileFromUri",
        "class": "OCA\\FilesLock\\Service\\FileService",
        "type": "->"
      },
      {
        "file": "/var/www/html/apps/files_lock/lib/DAV/LockBackend.php",
        "line": 75,
        "function": "getFileFromUri",
        "class": "OCA\\FilesLock\\DAV\\LockBackend",
        "type": "->"
      },
      {
        "file": "/var/www/html/3rdparty/sabre/dav/lib/DAV/Locks/Plugin.php",
        "line": 141,
        "function": "getLocks",
        "class": "OCA\\FilesLock\\DAV\\LockBackend",
        "type": "->"
      },
      {
        "file": "/var/www/html/3rdparty/sabre/dav/lib/DAV/Locks/Plugin.php",
        "line": 415,
        "function": "getLocks",
        "class": "Sabre\\DAV\\Locks\\Plugin",
        "type": "->"
      },
      {
        "file": "/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php",
        "line": 89,
        "function": "validateTokens",
        "class": "Sabre\\DAV\\Locks\\Plugin",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 1448,
        "function": "emit",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
      },
      {
        "file": "/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 466,
        "function": "checkPreconditions",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
      },
      {
        "file": "/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 253,
        "function": "invokeMethod",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
      },
      {
        "file": "/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php",
        "line": 321,
        "function": "start",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
      },
      {
        "file": "/var/www/html/apps/dav/appinfo/v1/publicwebdav.php",
        "line": 113,
        "function": "exec",
        "class": "Sabre\\DAV\\Server",
        "type": "->"
      },
      {
        "file": "/var/www/html/public.php",
        "line": 80,
        "args": [
          "/var/www/html/apps/dav/appinfo/v1/publicwebdav.php"
        ],
        "function": "require_once"
      }
    ],
    "File": "/var/www/html/apps/files_lock/lib/Service/FileService.php",
    "Line": 109,
    "CustomMessage": "--"
  },
  "id": "628def2546b0c"
}
PVince81 commented 2 years ago

works fine for me on 24.0.2 RC1 with a newly created link

@szaimen pointed out to me that it might be related to the new locking app

I've tried locally now with stable24 and the "files_lock" app enabled and it fails also.

@juliushaertl @eneiluj can you have a look ?

julien-nc commented 2 years ago

It is caused by the files_lock app trying to get the current user in a public page context.

This bug affects any action that creates a file in a publicly shared directory, not only drop but upload and creation with the + button.

@ArtificialOwl Any idea why this happens? How are locks supposed to be checked in a public context? Are they even supposed to be checked when creating a file for the created file itself?

The stack trace shows that the dav server asks its locking plugin to get the locks on the uploaded file. This leads to a call to files_lock/lib/Service/FileService.php::getFileFromUri($uri) which assumes the user is logged in.

I checked and the $uri is just the file name in this case. Could there be something wrong there? The only alternative in this service is getFileFromAbsoluteUri() which gets a user ID by parsing the uri.

ArtificialOwl commented 2 years ago

This looks good: https://github.com/nextcloud/files_lock/pull/75

PVince81 commented 2 years ago

fix was merged, closing

szaimen commented 2 years ago

I guess only needs a release then 👍

juliushaertl commented 2 years ago

Released as 24.0.1