kd2org / karadav

Lightweight NextCloud compatible WebDAV server
https://fossil.kd2.org/karadav/
GNU Affero General Public License v3.0
154 stars 13 forks source link

Missing WebDAV::hash causing 500 #21

Closed theo546 closed 1 year ago

theo546 commented 1 year ago

Hi,

When trying to open a file that sends you to a Collabora or OnlyOffice instance, it throw a 500 error because the Storage.php script is trying to call an undefined hash function.

I tried to find to search for such a function in all the files inside this project, without any result.

Please find the error logs below :

[8] [Tue Nov 22 22:53:21 2022] =========== Error ref. 38r5nis6 ===========

Error: Call to undefined method KaraDAV\WebDAV::hash() in /var/karadav/lib/KaraDAV/Storage.php:518
Stack trace:
#0 /var/karadav/lib/KaraDAV/Storage.php(225): KaraDAV\Storage->createWopiToken('...')
#1 /var/karadav/lib/KD2/WebDAV/Server.php(711): KaraDAV\Storage->properties('...', Array, 0)
#2 /var/karadav/lib/KD2/WebDAV/Server.php(1267): KD2\WebDAV\Server->http_propfind('...')
#3 /var/karadav/lib/KaraDAV/Server.php(68): KD2\WebDAV\Server->route('...')
#4 /var/karadav/www/_router.php(47): KaraDAV\Server->route('...')
#5 {main}

<errorReport>
{
    "errors": [
        {
            "message": "Call to undefined method KaraDAV\\WebDAV::hash()",
            "errorCode": 0,
            "type": "PHP error",
            "backtrace": [
                {
                    "file": "\/var\/karadav\/lib\/KaraDAV\/Storage.php",
                    "line": 518,
                    "code": {
                        "514": "\t\t$user = $this->users->current();",
                        "515": "\t\t$ttl = time()+(3600*10);",
                        "516": "",
                        "517": "\t\t\/\/ Use the user password as a server secret",
                        "518": "\t\t$check = WebDAV::hash(compact('ttl', 'uri'), $user->password);",
                        "519": "\t\t$data = sprintf('%s_%s_%s', $check, $ttl, $user->login);",
                        "520": "",
                        "521": "\t\treturn [",
                        "522": "\t\t\tWOPI::PROP_TOKEN => WOPI::base64_encode_url_safe($data),"
                    }
                },
                {
                    "function": "KaraDAV\\Storage->createWopiToken",
                    "file": "\/var\/karadav\/lib\/KaraDAV\/Storage.php",
                    "line": 225,
                    "args": {
                        "$uri": "string(25) \"Excel_File.xlsx\""
                    },
                    "code": {
                        "221": "\t\t$out = [];",
                        "222": "",
                        "223": "\t\t\/\/ Generate a new token for WOPI, and provide also TTL",
                        "224": "\t\tif (in_array(WOPI::PROP_TOKEN, $properties)) {",
                        "225": "\t\t\t$out = $this->createWopiToken($uri);",
                        "226": "\t\t\tunset($properties[WOPI::PROP_TOKEN], $properties[WOPI::PROP_TOKEN_TTL]);",
                        "227": "\t\t}",
                        "228": "",
                        "229": "\t\tforeach ($properties as $name) {"
                    }
                },
                {
                    "function": "KaraDAV\\Storage->properties",
                    "file": "\/var\/karadav\/lib\/KD2\/WebDAV\/Server.php",
                    "line": 711,
                    "args": {
                        "$uri": "string(25) \"Excel_File.xlsx\"",
                        "$properties": "array(3) {\n  [0]=> string(70) \"https:\/\/interoperability.blob.core.windows.net\/files\/MS-WOPI\/:file-url\"\n  [1]=> string(67) \"https:\/\/interoperability.blob.core.windows.net\/files\/MS-WOPI\/:token\"\n  [2]=> string(71) \"https:\/\/interoperability.blob.core.windows.net\/files\/MS-WOPI\/:token-ttl\"\n}",
                        "$depth": "int(0)"
                    },
                    "code": {
                        "707": "\t\t$requested = $this->extractRequestedProperties($body);",
                        "708": "\t\t$requested_keys = $requested ? array_keys($requested) : null;",
                        "709": "",
                        "710": "\t\t\/\/ Find root element properties",
                        "711": "\t\t$properties = $this->storage->properties($uri, $requested_keys, $depth);",
                        "712": "",
                        "713": "\t\tif (null === $properties) {",
                        "714": "\t\t\tthrow new Exception('This does not exist', 404);",
                        "715": "\t\t}"
                    }
                },
                {
                    "function": "KD2\\WebDAV\\Server->http_propfind",
                    "file": "\/var\/karadav\/lib\/KD2\/WebDAV\/Server.php",
                    "line": 1267,
                    "args": {
                        "$uri": "string(25) \"Excel_File.xlsx\""
                    },
                    "code": {
                        "1263": "\t\t\tif (!method_exists($this, $method)) {",
                        "1264": "\t\t\t\tthrow new Exception('Invalid request method', 405);",
                        "1265": "\t\t\t}",
                        "1266": "",
                        "1267": "\t\t\t$out = $this->$method($uri);",
                        "1268": "",
                        "1269": "\t\t\t$this->log('=> %d', http_response_code());",
                        "1270": "",
                        "1271": "\t\t\tif (null !== $out) {"
                    }
                },
                {
                    "function": "KD2\\WebDAV\\Server->route",
                    "file": "\/var\/karadav\/lib\/KaraDAV\/Server.php",
                    "line": 68,
                    "args": {
                        "$uri": "string(25) \"Excel_File.xlsx\""
                    },
                    "code": {
                        "64": "\t\t}",
                        "65": "",
                        "66": "\t\t$this->dav->setBaseURI('\/files\/' . $user->login . '\/');",
                        "67": "",
                        "68": "\t\treturn $this->dav->route($uri);",
                        "69": "\t}",
                        "70": "}",
                        "71": ""
                    }
                },
                {
                    "function": "KaraDAV\\Server->route",
                    "file": "...\/_router.php",
                    "line": 47,
                    "args": {
                        "$uri": "string(40) \"\/files\/theo546\/Excel_File.xlsx\""
                    },
                    "code": {
                        "43": "if (isset($_SERVER['REDIRECT_REQUEST_METHOD'])) {",
                        "44": "\t$_SERVER['REQUEST_METHOD'] = $_SERVER['REDIRECT_REQUEST_METHOD'];",
                        "45": "}",
                        "46": "",
                        "47": "if (!$s->route($uri)) {",
                        "48": "\tif (PHP_SAPI == 'cli-server') {",
                        "49": "\t\t$s->dav->log(\"ROUTER: => Route is not managed: 404\");",
                        "50": "\t}",
                        "51": ""
                    }
                }
            ]
        }
    ],
    "context": {
        "date": "2022-11-22T22:53:21+00:00",
        "duration": 0.5710124969482422,
        "environment": "development",
        "hostname": "0.0.0.0",
        "http_files": "array(0) {\n}",
        "http_method": "PROPFIND",
        "http_post": "array(0) {\n}",
        "http_referrer": "https:\/\/karadav.redacted.com\/files\/theo546\/",
        "http_user_agent": "Mozilla\/5.0 (X11; Linux x86_64; rv:107.0) Gecko\/20100101 Firefox\/107.0",
        "id": "38r5nis6",
        "language": "PHP 8.1.12",
        "memory_peak": 2097152,
        "memory_used": 2097152,
        "os": "Linux",
        "php_sapi": "cli-server",
        "remote_ip": "172.19.0.3",
        "root_directory": "\/var\/karadav\/www",
        "user_addr": "172.19.0.3",
        "url": "http:\/\/karadav:8080\/files\/theo546\/Excel_File.xlsx"
    }
}
</errorReport>
bohwaz commented 1 year ago

Thanks for your report, yes that was a typo on my part, thank you, it is fixed :)