provokateurin / dart-nextcloud

A Nextcloud client for dart
Other
20 stars 15 forks source link

Wrong Content-Type in WebDAV requests #33

Closed demon-tdr closed 3 years ago

demon-tdr commented 3 years ago

Hi, I have mod-security enabled in my Nextcloud installation. It is blocking WebDAV requests because the content-type is wrong (it should be text/xml):

PROPFIND /remote.php/dav//files/XXXXX/ HTTP/1.1
user-agent: Nextcloud Yaga
accept: application/json
accept-encoding: gzip
content-length: 361
host: XXXXXXXX
authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
content-type: application/json
ocs-apirequest: true
x-forwarded-port: 443
x-proxy-token: XXXXXXXXXXXXXXXXXXXXXXXXXXXX
connection: close

<?xml version="1.0"?><d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns" xmlns:ocs="http://open-collaboration-services.org/ns" xmlns:ocm="http://open-cloud-mesh.org/ns" xmlns:s="http://sabredav.org/ns"><d:prop><d:getcontentlength/><d:getcontenttype/><d:getlastmodified/><oc:id/><oc:share-types/></d:prop></d:propfind>
provokateurin commented 3 years ago

Ah I think I accidentially removed it. I'll quickly add it again

provokateurin commented 3 years ago

I wasn't sure if either text/xml or application/xml is the one to use, but I'd go with application/xml after reading this: https://tools.ietf.org/html/rfc3023#section-3

provokateurin commented 3 years ago

@demon-tdr please test https://github.com/jld3103/dart-nextcloud/pull/34.

demon-tdr commented 3 years ago

Thank you for your quick response.

I tried your test script against my Nextcloud server and got some errors.

$ dart test test/webdav_test.dart
00:04 +0 -1: WebDav (setUpAll) [E]                                                                                                                                                                 
  NoSuchMethodError: The method '[]=' was called on null.
  Receiver: null
  Tried calling: []=("content-type", "application/xml")
  dart:core                                       Object.noSuchMethod
  package:nextcloud/src/webdav/client.dart 75:12  WebDavClient._send
  package:nextcloud/src/webdav/client.dart 93:28  WebDavClient.status
  test/webdav_test.dart 16:29                     main.<fn>.<fn>

00:04 +2 -1: Some tests failed.

This error does not happen in the master branch (it fails because of the content-type) I'm sorry I can't help any more, this is my first contact with Dart

provokateurin commented 3 years ago

No problem! I already fixed that. Too bad I didn't test the code :grimacing:

demon-tdr commented 3 years ago

Your last commit fixed all the error messages! I ran a shorter version of your webdav_test file:

$ dart test test/webdav2_test.dart
00:08 +2: All tests passed! 

These same tests failed before your patch

Thank you very much

provokateurin commented 3 years ago

Published as v2.1.3