ramondeklein/nwebdav

[COPY] No error generated when destination file name is too long.

vishwas-trivedi opened this issue · 4 comments

Problem Description

NWebDAV return 207 (Multi-Status) status code when trying to copy a file where destination file name is too long(320 chars).
In case of IIS if you you specify a destination file name greater than 256 characters, it returns 404 error status.

I've check the source code and found following code in CopyHandler, please have a look :

// Copy collection
await CopyAsync(sourceItem, destinationCollection, destination.Name, overwrite, depth, httpContext, destination.CollectionUri, errors).ConfigureAwait(false);

// Check if there are any errors
if (errors.HasItems)
{
    // Obtain the status document
    var xDocument = new XDocument(errors.GetXmlMultiStatus());

    // Stream the document
    await response.SendResponseAsync(DavStatusCode.MultiStatus, xDocument).ConfigureAwait(false);
}
else
{
    // Set the response
    response.SetStatus(DavStatusCode.Ok);
}

Reproduction Procedure

Try to copy a file where destination file name is greater than 256 characters.

Question

Is this intended behaviors or is it a bug?

I don't think HTTP code 400 (bad request) is the correct code here. The definition for bad request is

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

Source: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1

There is nothing wrong with the syntax, because it depends on the target whether or not the file is correct. On some Unix filesystems, this filename would be perfectly fine. The WebDAV specification doesn't specify a result code for this operation (link). I guess status code 422 (unprocessable entity) might be most appriopriate (possibly wrapped inside a multi-status response).

Could you add the actual response body that is generated by the 207 (multi-status) return code?

@ramondeklein
Sorry my bad, error code returned from IIS is 404 not 400.
I've updated my query accordingly. Please check again.

Could you add the actual response body that is generated by the 207 (multi-status) return code?

Following is the actual XML response that I'm getting from NWebDAV :

<?xml version="1.0"?>
<multistatus xmlns="DAV:">
	<response>
		<href>https://192.168.81.55:5003/WebDAV1/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.txt</href>
		<status>HTTP/1.1 500 Internal Server Error</status>
	</response>
</multistatus>

Could you please take a look?

Error-code 500 (internal server error) is never a good idea. I'll take a look, but it might take a few days. I don't have much time at the moment :-(