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

未关闭 适合新手
#66,928 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php
领域
backend

调研方向

故障始于 core/Controller/JsController.php 第 56 行附近的 getJs(),此处用用户提供的 appName 调用 AppData::getFolder()。该方法只捕获 NotFoundException,因此来自 .. 路径的 NotPermittedException 会以 500 形式逸出。可以在旁边捕获 NotPermittedException 并返回 NotFoundResponse,也可以在查找前拒绝包含 .. 的 appName 和 fileName。完成标准是 curl --path-as-is https://<host>/js/../.htpasswd 返回 404 且没有记录 level-3 条目,同时现有的 JsController 测试全部通过。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
PHP
星标
37.6k
派生
5.4k
平均合并
1 天 16 小时
30 天内合并 PR
660

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nextcloud/server 的其他 Issue

查看 nextcloud/server 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。