Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: WebDAV SEARCH on custom metadata doesn't work #50302

Open
5 of 8 tasks
StCyr opened this issue Jan 21, 2025 · 1 comment
Open
5 of 8 tasks

[Bug]: WebDAV SEARCH on custom metadata doesn't work #50302

StCyr opened this issue Jan 21, 2025 · 1 comment
Assignees
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 29-feedback bug

Comments

@StCyr
Copy link
Contributor

StCyr commented Jan 21, 2025

⚠️ This issue respects the following points: ⚠️

Bug description

Hello,

According to the documentation (https://docs.nextcloud.com/server/latest/developer_manual/digging_deeper/files-metadata.html#webdav-search-based-on-metadata) it should be possible to search on custom metadata, but according to my investigation and the code at https://raw.githubusercontent.com/nextcloud/server/refs/heads/master/lib/private/Files/Cache/SearchBuilder.php this is not the case.

IINM, the $fieldTypes property is never updated with new metadata created. And, this prevents the SearchBuilder::getExtraOperatorField() function to work for custom metadata.

Here's a comparaison of 2 webDAV searches, one made on an unmodified server, and the second one with a small change:

webDAV SEARCH with unmodified code (Result = Internale Server Error)

root@2408LC07E43:/home/cybo# curl --noproxy 127.0.0.1 -X SEARCH http://127.0.0.1/nc29/remote.php/dav/ -H "OCS-APIRequest: true" -H "Content-Type: application/xml" -H "Authorization: Bearer Kgpk8-wfaCe-YcYNe-em57q-SxW7Q" -d @search.xml -b "XDEBUG_TRIGGER=TRUE"
<?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>127.0.0.1</s:remote-address>
                <s:request-id>wuB9fQJtrhIkHbecYM14</s:request-id>

                </s:technical-details>
</d:error>

And I find the following line in the log:

{"reqId":"YaJRZO52krqTmEcbbOOZ","level":3,"time":"2025-01-21T19:08:28+00:00","remoteAddr":"127.0.0.1","user":"admin","app":"webdav","method":"SEARCH","url":"/nc29/remote.php/dav/","message":"OC\\Files\\Cache\\SearchBuilder::getParameterForValue(): Argument #3 ($paramType) must be of type string, null given, called in /var/www/nc29/lib/private/Files/Cache/SearchBuilder.php on line 190","userAgent":"curl/7.88.1","version":"29.0.7.1","exception":{"Exception":"TypeError","Message":"OC\\Files\\Cache\\SearchBuilder::getParameterForValue(): Argument #3 ($paramType) must be of type string, null given, called in /var/www/nc29/lib/private/Files/Cache/SearchBuilder.php on line 190","Code":0,"Trace":[{"file":"/var/www/nc29/lib/private/Files/Cache/SearchBuilder.php","line":190,"function":"getParameterForValue","class":"OC\\Files\\Cache\\SearchBuilder","type":"->"},{"file":"/var/www/nc29/lib/private/Files/Cache/SearchBuilder.php","line":170,"function":"searchComparisonToDBExpr","class":"OC\\Files\\Cache\\SearchBuilder","type":"->"},{"file":"/var/www/nc29/lib/private/Files/Cache/SearchBuilder.php","line":137,"function":"searchOperatorToDBExpr","class":"OC\\Files\\Cache\\SearchBuilder","type":"->"},{"function":"OC\\Files\\Cache\\{closure}","class":"OC\\Files\\Cache\\SearchBuilder","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/nc29/lib/private/Files/Cache/SearchBuilder.php","line":136,"function":"array_map"},{"file":"/var/www/nc29/lib/private/Files/Cache/SearchBuilder.php","line":163,"function":"searchOperatorArrayToDBExprArray","class":"OC\\Files\\Cache\\SearchBuilder","type":"->"},{"file":"/var/www/nc29/lib/private/Files/Cache/QuerySearchHelper.php","line":89,"function":"searchOperatorToDBExpr","class":"OC\\Files\\Cache\\SearchBuilder","type":"->"},{"file":"/var/www/nc29/lib/private/Files/Cache/QuerySearchHelper.php","line":192,"function":"applySearchConstraints","class":"OC\\Files\\Cache\\QuerySearchHelper","type":"->"},{"file":"/var/www/nc29/lib/private/Files/Node/Folder.php","line":239,"function":"searchInCaches","class":"OC\\Files\\Cache\\QuerySearchHelper","type":"->"},{"file":"/var/www/nc29/apps/dav/lib/Files/FileSearchBackend.php","line":188,"function":"search","class":"OC\\Files\\Node\\Folder","type":"->"},{"file":"/var/www/nc29/apps/dav/lib/Files/LazySearchBackend.php","line":62,"function":"search","class":"OCA\\DAV\\Files\\FileSearchBackend","type":"->"},{"file":"/var/www/nc29/3rdparty/icewind/searchdav/src/DAV/SearchHandler.php","line":82,"function":"search","class":"OCA\\DAV\\Files\\LazySearchBackend","type":"->"},{"file":"/var/www/nc29/3rdparty/icewind/searchdav/src/DAV/SearchPlugin.php","line":119,"function":"handleSearchRequest","class":"SearchDAV\\DAV\\SearchHandler","type":"->"},{"file":"/var/www/nc29/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"searchHandler","class":"SearchDAV\\DAV\\SearchPlugin","type":"->"},{"file":"/var/www/nc29/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nc29/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nc29/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nc29/apps/dav/lib/Server.php","line":383,"function":"exec","class":"Sabre\\DAV\\Server","type":"->"},{"file":"/var/www/nc29/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->"},{"file":"/var/www/nc29/remote.php","line":172,"args":["/var/www/nc29/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/nc29/lib/private/Files/Cache/SearchBuilder.php","Line":326,"message":"OC\\Files\\Cache\\SearchBuilder::getParameterForValue(): Argument #3 ($paramType) must be of type string, null given, called in /var/www/nc29/lib/private/Files/Cache/SearchBuilder.php on line 190","exception":{},"CustomMessage":"OC\\Files\\Cache\\SearchBuilder::getParameterForValue(): Argument #3 ($paramType) must be of type string, null given, called in /var/www/nc29/lib/private/Files/Cache/SearchBuilder.php on line 190"}}

webDAV SEARCH with modified code (Result = Search successfull)

root@2408LC07E43:/home/cybo# curl --noproxy 127.0.0.1 -X SEARCH http://127.0.0.1/nc29/remote.php/dav/ -H "OCS-APIRequest: true" -H "Content-Type: application/xml" -H "Authorization: Bearer Kgpk8-wfaCe-YcYNe-em57q-SxW7Q" -d @search.xml -b "XDEBUG_TRIGGER=TRUE"
<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"><d:response><d:href>/nc29/remote.php/dav/files/admin/cv_en.pdf</d:href><d:propstat><d:prop><oc:fileid>542</oc:fileid><d:displayname>cv_en.pdf</d:displayname></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response></d:multistatus>
root@2408LC07E43:/home/cybo#

Here's what I've changed to the SearchBuilder class to make the call work:

	/** @var array<string, string> */
	protected static $fieldTypes = [
		'mimetype' => 'string',
		'mtime' => 'integer',
		'name' => 'string',
		'path' => 'string',
		'size' => 'integer',
		'tagname' => 'string',
		'systemtag' => 'string',
		'favorite' => 'boolean',
		'fileid' => 'integer',
		'storage' => 'integer',
		'share_with' => 'string',
		'share_type' => 'integer',
		'owner' => 'string',
+++		"X_SENDENT_MS_TEAMS_CHANNEL_ID" => 'string',
	];

Body of the webDAV SEARCH request

For the record, here's the body of the webDAV SEARCH request:

<?xml version="1.0" encoding="UTF-8"?>
        <d:searchrequest xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
            <d:basicsearch>
                <d:select>
                    <d:prop>
                        <oc:fileid/>
                        <d:displayname/>
                    </d:prop>
                </d:select>
                <d:from>
                    <d:scope>
                        <d:href>/files/admin</d:href>
                        <d:depth>infinity</d:depth>
                    </d:scope>
                </d:from>
                <d:where>
                        <d:eq>
                            <d:prop>
                                <nc:metadata-X_SENDENT_MS_TEAMS_CHANNEL_ID/>
                            </d:prop>
                            <d:literal>Xyz123</d:literal>
                        </d:eq>
                </d:where>
                <d:limit>
                    <d:nresults>200</d:nresults>
                </d:limit>
            </d:basicsearch>
        </d:searchrequest>

Steps to reproduce

The full reproduction scenario is quite big since it requires to create an app that initializes our new metadata, issue a PROPPATCH to a file to add it the metadata, and eventually perform the SEARCH, but I believe the bug description should be enough for you to validate the bug (or not if my assumption that the $fieldTypes property is never changed is false).

Unfortunately, I don't have a solution on hand to offer you: It seems a bit complicated to fix at first sight.

Expected behavior

User should be able to search on custom metadata

Nextcloud Server version

29

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.2

Web server

Apache (supported)

Database engine version

MariaDB

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

None

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

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

@StCyr StCyr added 0. Needs triage Pending check for reproducibility or if it fits our roadmap bug labels Jan 21, 2025
@StCyr
Copy link
Contributor Author

StCyr commented Jan 21, 2025

@ChristophWurst, assigning to you because you know me ;-)

Please feel free to assign to anyone else if needed, or engage discussion with me if you think I could fix it with a little help from you ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 29-feedback bug
Projects
None yet
Development

No branches or pull requests

3 participants