[Bug]: GET /js/../<anything> returns 500 (NotPermittedException from JsController::getJs) instead of 404

Ouverte Adaptée aux débutants
#66,928 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
72/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
php
Domaine
backend

Piste de recherche

La défaillance commence dans getJs() dans core/Controller/JsController.php, vers la ligne 56, où AppData::getFolder() est appelée avec l'appName fourni par l'utilisateur. Cette méthode n'intercepte que NotFoundException, donc la NotPermittedException provenant d'un chemin contenant .. remonte en 500. Soit on intercepte NotPermittedException à côté et on renvoie une NotFoundResponse, soit on rejette les appName et fileName contenant .. avant la recherche. C'est terminé lorsque curl --path-as-is https://<host>/js/../.htpasswd renvoie 404, qu'aucune entrée de niveau 3 n'est journalisée et que les tests existants de JsController passent toujours.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

35-feedback
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
  1. curl --path-as-is -s -o /dev/null -w '%{http_code}\n' 'https://<nextcloud>/js/../.htpasswd'
    (--path-as-is stops curl from collapsing the ..; scanners send it raw.)
  2. 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.

Langage dominant
PHP
Étoiles
37.6k
Forks
5.4k
Merge moyen
1 j 16 h
PR mergées (30 j)
660

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de nextcloud/server

Toutes les issues de nextcloud/server

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.