[Bug]: GET /js/../<anything> returns 500 (NotPermittedException from JsController::getJs) instead of 404
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
Rechercherichtung
Der Fehler beginnt in getJs() in core/Controller/JsController.php, etwa in Zeile 56, wo AppData::getFolder() mit dem vom Benutzer gelieferten appName aufgerufen wird. Diese Methode fängt nur NotFoundException ab, daher entweicht die NotPermittedException von einem ..-Pfad als 500. Entweder fängt man NotPermittedException daneben ab und gibt eine NotFoundResponse zurück, oder man weist appName und fileName, die .. enthalten, vor der Suche ab. Fertig ist es, wenn curl --path-as-is https://<host>/js/../.htpasswd 404 zurückgibt, kein Eintrag der Stufe 3 protokolliert wird und die bestehenden JsController-Tests weiterhin bestehen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Bug description
A request whose path is /js/../<something> reaches OC\Core\Controller\JsController::getJs() with appName = "..". AppData::getFolder('..') throws OCP\Files\NotPermittedException: Invalid path "/appdata_<instanceid>/js/..". getJs() only catches NotFoundException, so the exception isn't handled and the client gets HTTP 500 (logged at level 3) instead of a 404.
The path check itself works (nothing outside the js app-data folder is read), so this isn't a security problem. The only issue is the status code and the error-level log entry. Vulnerability scanners send paths like this all the time (ours did: GET /js/../.htpasswd), so every scan leaves 500s and errors in nextcloud.log. That looks like a server fault and sets off "5xx from the web server" alerts.
The same code is still on master (core/Controller/JsController.php, getJs(): catch (NotFoundException $e) only).
Steps to reproduce
curl --path-as-is -s -o /dev/null -w '%{http_code}\n' 'https://<nextcloud>/js/../.htpasswd'
(--path-as-isstops curl from collapsing the..; scanners send it raw.)- See
500, and in nextcloud.log an error at level 3 with url/js/../.htpasswd.
In our case Apache first refused /.htpasswd itself (the stock <FilesMatch "^\.ht"> deny), and the ErrorDocument 403 /index.php/error/403 from Nextcloud's .htaccess handed the request to Nextcloud with the original request URI. So Nextcloud's router matched /js/{appName}/{fileName} with appName = "..". Any other /js/../<x> that ends up in index.php should take the same path.
Expected behavior
404 (NotFoundResponse), as for any other missing js file, with no error in the log. For example, also catch NotPermittedException in getJs() (the getFolder() call and getFile()), or reject appName / fileName values containing .. before touching app data.
Nextcloud Server version
35 (35.0.3)
Operating system
Other (Ubuntu 26.04.1 LTS)
PHP engine version
PHP 8.4 (8.4.28, php-fpm)
Web server
Apache (supported)
Database engine version
MySQL (9.7.4)
Nextcloud Logs
{"level":3,"app":"index","method":"GET","url":"/js/../.htpasswd","version":"35.0.3.2",
"message":"Invalid path \"/appdata_<instanceid>/js/..\"",
"exception":{"Exception":"OCP\\Files\\NotPermittedException","Message":"Invalid path \"/appdata_<instanceid>/js/..\"",
"File":"lib/private/Files/Node/Folder.php","Line":62,
"Trace":[
"OC\\Files\\Node\\Folder->getFullPath",
"OC\\Files\\Node\\LazyFolder->__call lib/private/Files/Node/LazyFolder.php:67",
"OC\\Files\\Node\\LazyFolder->getFullPath lib/private/Files/Node/LazyFolder.php:419",
"OC\\Files\\Node\\LazyFolder->get lib/private/Files/Node/LazyFolder.php:121",
"OC\\Files\\AppData\\AppData->getFolder lib/private/Files/AppData/AppData.php:105",
"OC\\Core\\Controller\\JsController->getJs core/Controller/JsController.php:56",
"OC\\AppFramework\\Http\\Dispatcher->executeController lib/private/AppFramework/Http/Dispatcher.php:198",
"OC\\AppFramework\\Http\\Dispatcher->dispatch lib/private/AppFramework/Http/Dispatcher.php:86",
"OC\\AppFramework\\App::main lib/private/AppFramework/App.php:138",
"OC\\Route\\Router->match lib/private/Route/Router.php:324",
"OC::handleRequest lib/OC.php:1235"]}}
(trimmed: trace shortened, instance id, host and addresses removed)
Additional info
Found by a scheduled outside-in vulnerability scan of our own instance.
- Vorherrschende Sprache
- PHP
- Sterne
- 37.6k
- Forks
- 5.4k
- Ø Merge
- 1 T. 16 Std.
- Gemergte PRs (30 T.)
- 660
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nextcloud/server
-
35-feedback
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]:Evtl. vergeben @lazerg hat das heute übernommen. Offen0. Needs triage 35-feedback bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Link share editor: "Custom permissions" is checked for a new link shareEvtl. vergeben @lazerg hat das heute übernommen. Offen0. Needs triage bug feature: sharing regression
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
0. Needs triage 35-feedback bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in nextcloud/server
Ähnliche Issues
-
bug good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
quantum-php/framework#692 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 70/100
ajeetraina/awesome-docker-sbx#559 ·
-
PHP 8.6 supportOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Saisie des adressesOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
pantaflex44/Tiquettes#116 · 1 Kommentar ·
-
dependencies enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
novalo-dev/Prestashop-MCP-Server#329 ·
Maintainer antworten meist innerhalb von 1 Tag