nextcloud / nextcloud/server

[Bug]: Impossible to rename or delete files with invalid characters in their names

Open
#49,754 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage 30-feedback 31-feedback bug feature: files hotspot: filename handling
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ This issue respects the following points: ⚠️
Bug description

With the latest stable29, after setting some forbidden characters for file names, the existing files/directories that have those characters in their names can't be renamed at all anymore.
Sabre complains that there is at least one invalid char in the name even if there is no invalid char in the target name but only in the current name.

Steps to reproduce
  1. Create a file named a%b.txt
  2. Add 'forbidden_chars' => ['%'], to config.php
  3. Try to rename the file to ab.txt
  4. The MOVE request fails.
    MOVE /remote.php/dav/files/admin/specialchars/a%25b.md
    with the Destination header being /remote.php/dav/files/admin/specialchars/ab.md
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
	<s:exception>Internal Server Error</s:exception>
	<s:message>
		The server was unable to complete your request.		If this happens again, please send the technical details below to the server administrator.		More details can be found in the server log.			</s:message>

	<s:technical-details>
		<s:remote-address>192.168.21.3</s:remote-address>
		<s:request-id>tEi9t7j2C4ZKeEsBblSc</s:request-id>

			<s:type>OCA\DAV\Connector\Sabre\Exception\InvalidPath</s:type>
		<s:code>0</s:code>
		<s:message>File name contains at least one invalid character</s:message>
		<s:file>/var/www/html/apps/dav/lib/Connector/Sabre/Directory.php</s:file>
		<s:line>219</s:line>

		<s:stacktrace>
			#0 /var/www/html/3rdparty/sabre/dav/lib/DAV/Tree.php(95): OCA\DAV\Connector\Sabre\Directory-&gt;getChild(&#039;a%b.md&#039;)
#1 /var/www/html/apps/dav/lib/DAV/ViewOnlyPlugin.php(76): Sabre\DAV\Tree-&gt;getNodeForPath(&#039;files/admin/spe...&#039;)
#2 /var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php(89): OCA\DAV\DAV\ViewOnlyPlugin-&gt;checkViewOnly(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))
#3 /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php(472): Sabre\DAV\Server-&gt;emit(&#039;method:MOVE&#039;, Array)
#4 /var/www/html/apps/dav/lib/Connector/Sabre/Server.php(61): Sabre\DAV\Server-&gt;invokeMethod(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))
#5 /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php(321): OCA\DAV\Connector\Sabre\Server-&gt;start()
#6 /var/www/html/apps/dav/lib/Server.php(393): Sabre\DAV\Server-&gt;exec()
#7 /var/www/html/apps/dav/appinfo/v2/remote.php(35): OCA\DAV\Server-&gt;exec()
#8 /var/www/html/remote.php(172): require_once(&#039;/var/www/html/a...&#039;)
#9 {main}		</s:stacktrace>
		</s:technical-details>
</d:error>

Expected behavior

In NC >= 30, those files can be renamed to a valid name even if the current name is invalid.

Nextcloud Server version

29

Operating system

None

PHP engine version

None

Web server

None

Database engine version

None

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report

List of activated Apps

Nextcloud Signing status

Nextcloud Logs

Additional info

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in apps/dav/lib/Connector/Sabre/Directory.php around line 219 and trace the MOVE request shown in the stack trace. Reproduce the configured forbidden character case, then verify that an existing file with an invalid current name can be renamed to a valid target name without triggering InvalidPath.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.