Seafdav : renaming files with space in directory names doesn't work

I’m using Seafile 9.0.8, and I have a problem with the webdav access to the files (the webdav client is Nextcloud).

The problem appends when I try to rename a file inside the webdav client, only when there is a least on space in the name of the library or in the name of one directory of the path of the file (no problem if there is a space in the name of the file). If no spaces in the library or directories names, it works.

The error in seafdav.log:

2022-09-13 14:07:51.584 - <139947561834240> wsgidav.wsgidav_app         INFO    :  127.0.0.1 - contact@utopons.org - [2022-09-13 12:07:51] "MOVE /test/test espaces/test.docx" dest="/seafdav/test/test%2520espaces/test%2520e.docx", length=0, depth=0, overwrite=T, elap=0.107sec -> 409 Conflict

My Nginx configuration:

location /seafdav {
            proxy_pass         http://127.0.0.1:8080/seafdav;
            proxy_http_version 1.1;
            proxy_set_header   Host $host;
            proxy_set_header   X-NginX-Proxy true;
            proxy_buffering off;
            client_max_body_size 0;
            proxy_request_buffering off;
            set $dest $http_destination;
            if ($http_destination ~ "^https://docs.tila.im/seafdav/(.+)") {
                    set $dest /seafdav$1;
            }
            proxy_set_header DESTINATION $dest;

            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_read_timeout  1200s;

            access_log      /var/log/nginx/seafdav.access.log;
            error_log       /var/log/nginx/seafdav.error.log;

    }

Any idea to solve this ?

(All other operations using webdav seams to work well…)

After some more work trying to solve this issue, it seems that the encoding of special characters is done twice : instead of “%20” for a space, the “%” is encoded itself, and thus there is “%2520” instead of “%20” in the destination path.

So I change my ngnix configuration to substitute “%25” by “%” using a lua line, and this resolve my problem:

    location /seafdav {
            proxy_pass         http://127.0.0.1:8080/seafdav;
            proxy_http_version 1.1;
            proxy_set_header   Host $host;
            proxy_set_header   X-NginX-Proxy true;
            proxy_buffering off;
            client_max_body_size 0;
            proxy_request_buffering off;
            set $dest $http_destination;
            if ($http_destination ~ "^https://docs.tila.im/seafdav/(.+)") {
                    set $dest /seafdav$1;
            }
            set $fixed_dest '';
            access_by_lua_block {
                    ngx.var.fixed_dest = string.gsub(ngx.var.dest, "%%25", "%%")
            }
            proxy_set_header DESTINATION $fixed_dest;

            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_read_timeout  1200s;

            access_log      /var/log/nginx/seafdav.access.log;
            error_log       /var/log/nginx/seafdav.error.log;

    }

I hope this will help other people!

2 Likes

Just had the same issue. Downloading via a webdav client is no problem, but upload + rename doesn’t work with spaces in the file path… very unlucky.

I added an issue for this bug (issue 2619 in github).

After upgrading to the latest version of Seafile Community (10), removing all changes I made to the config myself (including the “Destionation” https fix) fixed all issues I had with SeafDav, including this one.

The command tshark -i lo -O http -f "tcp port 8080" -Y 'http.request.method == "MOVE"' helped me debug this issue.

Thanks for the news, I did a quick try, but I still have an error when moving a file to a directory with a space in its name. I’m keeping my nginx hack :slight_smile: