owncloud / ocis

:atom_symbol: ownCloud Infinite Scale Stack
https://doc.owncloud.com/ocis/next/
Apache License 2.0
1.42k stars 183 forks source link

Uploading with the same mtime and filename causes "internal server errors" #10496

Open rhafer opened 3 weeks ago

rhafer commented 3 weeks ago

When uploading a file with the same mtime and name but different contents multiple times, I get "500 Internal Server Error" for all uploads after the 2nd upload.

Take e.g. the these three uploads. Each uploading to the same filename using the same mtime in the the Upload-Metadata, but each time a different content:

curl 'https://localhost:9200/remote.php/dav/spaces/fa7e8b99-933b-4b0d-bb68-d6fb96ef6a82$34fbbd0c-16ef-4ac4-956c-1c5df6645286'   -H 'Content-Type: application/offset+octet-stream'   -H 'Tus-Resumable: 1.0.0'   -H 'Upload-Length: 4'   -H 'Upload-Metadata: mtime MTczMDE2MDAwMA==,filename L3Rlc3Qx'   -d'test'   -uadmin:admin -vk
curl 'https://localhost:9200/remote.php/dav/spaces/fa7e8b99-933b-4b0d-bb68-d6fb96ef6a82$34fbbd0c-16ef-4ac4-956c-1c5df6645286'   -H 'Content-Type: application/offset+octet-stream'   -H 'Tus-Resumable: 1.0.0'   -H 'Upload-Length: 4'   -H 'Upload-Metadata: mtime MTczMDE2MDAwMA==,filename L3Rlc3Qx'   -d'tast'   -uadmin:admin -vk
curl 'https://localhost:9200/remote.php/dav/spaces/fa7e8b99-933b-4b0d-bb68-d6fb96ef6a82$34fbbd0c-16ef-4ac4-956c-1c5df6645286'   -H 'Content-Type: application/offset+octet-stream'   -H 'Tus-Resumable: 1.0.0'   -H 'Upload-Length: 4'   -H 'Upload-Metadata: mtime MTczMDE2MDAwMA==,filename L3Rlc3Qx'   -d'tost'   -uadmin:admin -vk

The first two requests work fine (the 2nd one creates a new revision of the file). The 3rd one however causes a 500 reply:

* upload completely sent off: 4 bytes
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
< HTTP/1.1 500 Internal Server Error
< Access-Control-Allow-Headers: Tus-Resumable, Upload-Length, Upload-Metadata, If-Match
< Access-Control-Expose-Headers: Tus-Resumable, Upload-Offset, Location
< Content-Length: 0
< Content-Security-Policy: child-src 'self'; connect-src 'self' blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; default-src 'none'; font-src 'self'; frame-ancestors 'self'; frame-src 'self' blob: https://embed.diagrams.net/; img-src 'self' data: blob: https://raw.githubusercontent.com/owncloud/awesome-ocis/; manifest-src 'self'; media-src 'self'; object-src 'self' blob:; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'
< Date: Wed, 06 Nov 2024 15:23:23 GMT
< Location: https://localhost:9200/data/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZXZhIiwiZXhwIjoxNzMwOTkzMDAzLCJpYXQiOjE3MzA5MDY2MDMsInRhcmdldCI6Imh0dHA6Ly9sb2NhbGhvc3Q6OTE1OC9kYXRhL3R1cy8wNWQyYTkzZC1mYjI0LTQyMDAtOTVlOC0zY2ZjOGQ3NzQwYWUifQ.LAQTnICsTdNOWYzk5Qp6ms2mkGckBmtxu5IqK48S4XA
< Referrer-Policy: strict-origin-when-cross-origin
< Strict-Transport-Security: max-age=315360000; preload
< Tus-Extension: creation,creation-with-upload,checksum,expiration
< Tus-Resumable: 1.0.0
< Vary: Origin
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Permitted-Cross-Domain-Policies: none
< X-Request-Id: 58004e224a1a/p6IS9fNsSR-000089
< X-Robots-Tag: none
< X-Xss-Protection: 1; mode=block
< 

Originally posted by @rhafer in https://github.com/owncloud/ocis/issues/9498#issuecomment-2460082092

saw-jan commented 1 week ago

[!Note] All requests work fine with SAME mtime and SAME content

The problem exists with the normal upload as well. SAME mtime but DIFFERENT content.

First upload:

curl -XPUT 'https://localhost:9200/remote.php/dav/files/admin/lorem.txt' \
-d'content' \
-H'X-OC-Mtime: 1565237893' \
-uadmin:admin -k
< HTTP/1.1 201 Created

Second upload:

curl -XPUT 'https://localhost:9200/remote.php/dav/files/admin/lorem.txt' \
-d'kontent' \
-H'X-OC-Mtime: 1565237893' \
-uadmin:admin -k
< HTTP/1.1 204 No Content

Third upload:

curl -XPUT 'https://localhost:9200/remote.php/dav/files/admin/lorem.txt' \
-d'lontent' \
-H'X-OC-Mtime: 1565237893' \
-uadmin:admin -k
< HTTP/1.1 500 Internal Server Erro