fix: prevent appconfig path traversal to RCE via public_/remote_ keys (OC10-146) - #41804
Open
oc-tmueller wants to merge 1 commit into
Open
fix: prevent appconfig path traversal to RCE via public_/remote_ keys (OC10-146)#41804oc-tmueller wants to merge 1 commit into
oc-tmueller wants to merge 1 commit into
Conversation
… (OC10-146) An authenticated admin could set the core appconfig key `public_webdav` (or any `public_`/`remote_` key) to a path-traversal value and have it `require_once`'d by public.php on the next `GET /public.php/webdav`, achieving remote code execution. Two independent defects made this possible: 1. Sink: public.php included the stored handler path relative to the app directory with no traversal check, unlike remote.php which already rejects `../`. This is the essential, DB-independent gate: add the same guard so a traversal path can never be included. 2. Guard bypass: AppConfigController used a strict `$app === 'core'` compare to block admins from setting `public_`/`remote_` keys on core. A mangled app id such as `"core "` (trailing space) is not equal to `"core"` in PHP yet the database folds it back to the core row, defeating the guard. This is the same defeat mechanism as OC10-5 (`core%81` truncation). Normalize the app id (cleanAppId + trim + strtolower) before the check, in both the controller (getValue/setValue/deleteKey) and the legacy core/ajax/appconfig.php endpoint, and block deleting the whole core appconfig via deleteApp. Adds regression tests covering the mangled `core` spellings and the allowed near-misses. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Thomas Müller <323649642+oc-tmueller@users.noreply.github.com>
oc-tmueller
force-pushed
the
fix/oc10-146-appconfig-path-traversal-master
branch
from
September 3, 2026 11:04
a47964f to
dd2f58a
Compare
phil-davis
approved these changes
Sep 4, 2026
| // mangled spellings which the database folds back to the "core" row | ||
| // (e.g. "core " with a trailing space) cannot slip past the guard. See OC10-146. | ||
| $normalizedApp = isset($app) ? \strtolower(\trim((string)$app)) : $app; | ||
| if ($normalizedApp === 'core' && isset($_POST['key']) &&(\substr((string)$_POST['key'], 0, 7) === 'remote_' || \substr((string)$_POST['key'], 0, 7) === 'public_')) { |
Contributor
There was a problem hiding this comment.
I thought that code-style would complain about &&( (no space), but that was already in the previous code anyway.
| ['CORE', 'public_key1', 'foo'], | ||
| ['Core', 'remote_key1', 'foo'], | ||
| ['core/', 'public_key1', 'foo'], | ||
| ['core..', 'remote_key1', 'foo'], |
Contributor
There was a problem hiding this comment.
Note: OC_App::cleanAppId removes junk like .. so this test case is also equivalent to trying to set a key for "core".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An authenticated admin could set the
coreappconfig keypublic_webdav(or anypublic_/remote_key) to a path-traversal value and have itrequire_once'd bypublic.phpon the nextGET /public.php/webdav, achieving remote code execution.Two independent defects made this possible; both are fixed here (defense in depth).
1. Sink —
public.phphad no traversal check (essential fix)public.phpincluded the stored handler path relative to the app directory with no traversal guard, unlikeremote.phpwhich already rejects../. Added the same guard so a traversal path can never be included — this is the DB- and endpoint-independent gate.2. Guard bypass — strict
$app === 'core'compareAppConfigControllerblocked admins from settingpublic_/remote_keys oncorewith a strict$app === 'core'compare. A mangled app id such as"core "(trailing space) is not equal to"core"in PHP, yet the database folds it back to thecorerow — defeating the guard. This is the same defeat mechanism as the earliercore%81truncation bypass. The app id is now normalized (cleanAppId+trim+strtolower) before the check, in:AppConfigController::getValue/setValue/deleteKeycore/ajax/appconfig.phpendpointdeleteAppnow refuses to wipe the wholecoreappconfig.Tests
Adds regression tests covering the mangled
corespellings ("core "," core","CORE","core/","core..") and allowed near-misses (encore, non-service keys oncore).Verified locally in
owncloudci/php:8.3on sqlite, mirroring thephp-unitworkflow (freshmaintenance:installper run, thentests/drone/test-phpunit.sh's phpunit invocation):tests/Settings/Controller/AppConfigControllerTest.php: OK — 40 tests, 105 assertions.$app === 'core'compare makes 17 of the new cases fail, confirming they catch the bypass.calensrenders the changelog entry as aSecurityitem and exits 0.Note the
public.phpsink fix has no unit-test coverage —public.phpis a top-level entry script with no unit tests. It mirrors the existing, reviewed guard inremote.phpverbatim.Forward-port of #41803 to
master. That PR targets the10.16release branch;mastercarries the identical vulnerable code. Cherry-picked with no adaptation — the code diff is byte-identical to the reviewed one (only the changelog entry is renumbered to this PR). The onemaster-side difference inpublic.php, an addedOC_Util::tearDownFS()line, sits below the guard's insertion point and did not conflict.