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!

1 Like