Repository navigation
fix: contain appconfig public_/remote_ handler includes to the app directory - #41856
Merged
oc-tmueller merged 3 commits intoSep 23, 2026
Merged
Conversation
…rectory 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. ## The sink public.php and remote.php resolved the stored `<appId>/<path>` value by concatenating `OC_App::getAppPath($app)`, which is not a containment check. getAppPath() returns false for an app id that has no directory on disk, and `false . '/'` is `'/'`, so the include path becomes absolute - and an absolute path contains no traversal sequence, which is why a `../` substring test does not close this. `isInstalled()` does not stop it either, because it only tests for an appconfig `enabled` row, not for a directory, and an admin can create such a row for any app id. Verified on a live instance: a stored value of `<dirless app>//etc/passwd` returned the contents of /etc/passwd. The stored value now resolves through `OC_App::getServiceHandlerPath()`, which requires the target to realpath() inside the app's own directory (with a trailing separator, so `…/apps/files` does not accept `…/apps/files_sharing`) and to be an existing `.php` file. That also covers a symlink out of the app tree, and the `is_file()` test matters because `require_once` on a directory named `x.php` is an E_COMPILE_ERROR the callers' `catch (\Throwable)` cannot handle. A NUL byte in either argument is refused before either is used as a path: realpath(), and is_dir() inside getAppPath(), warn on PHP 7 and throw on PHP 8 rather than returning the documented false, and cleanAppId() does not help because its '\0' is a literal backslash-zero. remote.php builds its include path the same way in the default branch of its service switch, so it gets the same treatment. Its `core` branch is the one include site left without containment and is unreachable by contradiction - getting there needs a stored `remote_<service>` value starting `core/`, which means `$service` was not hardcoded, which the `in_array()` above then rejects - so that reasoning is recorded next to it rather than the branch being changed. Every programmatic writer stores `<appId>/<path from info.xml>`, which always resolves inside the app directory, and a test pins all six shipped handlers. ## The guards on the way in Enumerating mangled spellings of "core" cannot be complete: the only requirement for a bypass is that the written app id compares equal to "core" under the database collation, which is an open set. Blank padding into the varchar(32) appid column, an accent-insensitive collation and a trailing invalid byte all survive normalization. Any app id outside the canonical charset is therefore refused outright on setValue and deleteApp, in the controller and in the legacy endpoint. The charset is anchored with `\z` rather than `$`, because `$` also matches before a trailing newline, which would let a 33-byte id truncate onto an existing row. The legacy endpoint additionally requires cleanAppId() to be a no-op, so that it agrees with the controller, which validates and writes the raw value: the charset permits `.`, so `co..re` would otherwise pass validation and be written as `core`, and `..` as the empty app id. deleteKey deliberately does not demand a canonical app id outright, or a row written under one before this guard existed - through this endpoint, occ, or an app calling setAppValue() - would be undeletable through both admin paths. Such a row may only be removed key by key and only for a canonical, non-handler key, because isCoreApp() compares a normalized string and cannot see a spelling that only the collation folds onto "core": on utf8mb4_general_ci or utf8mb4_0900_ai_ci - the MySQL default whenever the database is pre-created rather than created by ownCloud - deleting "córe"/"public_webdav" would otherwise remove core's registered handler, which is only re-registered on an app version bump. Blank padding plus varchar(32) truncation gets there with no exotic collation at all. deleteApp keeps the blanket check, since dropping the whole core appconfig is not recoverable. The same reasoning applies to the key, which was compared case sensitively: under a case-insensitive collation `PUBLIC_webdav` folds onto the stored `public_webdav` row, so an admin could overwrite or delete a registered handler. The prefix test is case-insensitive now, and a key that is not canonical is refused outright on core, because an accent-insensitive collation folds `públic_webdav` onto it as well. Only the core rows are read as handlers, so both key checks are gated on the app: files_sharing keeps its legitimate `public_share_*` keys. Reads are refused too, or the endpoints would hand back the handler path they refuse to let an admin set. The legacy endpoint had no read guard at all; the controller refused the exact lowercase prefix but not a mangled spelling of it, and was missing the key charset check. The endpoint's guard checks the key in every source the dispatch might read it from rather than the first one it finds - the write actions take `$_POST['key']` while getValue/hasKey take `$_GET['key']`, and both are attacker-controlled independently, so validating one source alone lets a harmless decoy in the other satisfy the guard while the action consumes the real key. (A read cannot fold onto a stored row: OC\AppConfig's getValue()/hasKey() are exact lookups in the preloaded cache, so the collation never sees the key. It is the prefix match that mattered.) `app[]=core` stringified to "Array", passed the charset test and landed a row under the app id `Array`, because the endpoint cast before validating. A non-string app id is refused now, and so is a non-string key on a write: it reaches OC\AppConfig as an array subscript, an "Illegal offset type" warning on PHP 7 and a TypeError on PHP 8. To stop the two endpoints drifting apart - which is what let the legacy one ship without the deleteApp guard in an earlier revision - isCoreApp(), isCanonicalAppId(), isCanonicalConfigKey(), isServiceHandlerKey() and isProtectedCoreServiceKey() are OC_App statics that both call, with their own tests. All five compare `preg_match()` against the failing value, so a PCRE error refuses the request rather than passing it. ## Two pre-existing bugs in the reworked flow getAppValue() returns '' for an unregistered service rather than null, so the `$file === null` test never fired and the request fell through to "App not installed: " - a logged 500 on public.php and, on remote.php, a RemoteException with getCode() 0, which OC_Response::setStatus() turns into a bogus `HTTP/1.1 0` that caches, monitoring and sync clients read as a success. Both answer 404 now, and every RemoteException carries an explicit status. The refusals get 503 rather than 404, because that is what handleException() already answered on a WebDAV request (code 0 matches no case in its switch and falls through to ServiceUnavailable), and a sync client must not be told the root is gone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The entry was written before the pull request number was known. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
getValue() checked is_string() on the app id but not on the key, unlike
setValue() and deleteKey(), while its comment claimed the three entry
points share one predicate. Both core predicates short-circuit on a
non-core app, so for any other app an array key fell through to
OC\AppConfig as a subscript: an "Illegal offset type" warning on PHP 7
and a TypeError on PHP 8, i.e. a logged 500 where the two write paths
answer 400.
The route parameter is not a guarantee. Request::decodeContent() decodes
an application/json body and merges it over items["parameters"] for a GET
as well, i.e. after setUrlParameters() merged the url params, so a body
of {"key":["x"]} overrides the {key} taken from the path.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
jvillafanez
approved these changes
Sep 23, 2026
oc-tmueller
deleted the
fix/appconfig-service-handler-containment-master
branch
September 23, 2026 16:49
oc-tmueller
added a commit
that referenced
this pull request
Sep 25, 2026
Bump version.php to 11.0.1 and materialize the changelog fragments for the first patch release of the 11.0 line. $OC_Version becomes [11, 0, 1, 0]: the 4th digit is the internal DB-upgrade patch level, not the public patch number, and nothing in this release needs it moved. The 15 fragments in changelog/unreleased/ move into changelog/11.0.1_2026-09-25/ (git mv, so the renames stay tracked) and CHANGELOG.md is regenerated with calens. unreleased/ keeps its .gitkeep and is now empty, ready for the next cycle. Security: - #41827 reject SVG/script content before it reaches ImageMagick bitmap previews - #41834 pin the Imagick coder for each preview provider - #41856 prevent path traversal via appconfig public_/remote_ keys Bugfixes: - #41676 reduce priority of checkPropFind event - #41779 do not echo secrets when setting config values via occ - #41782 restore index usage for filecache writes on Oracle - #41807 show federated users in the share dialog when local users also match - #41808 avoid a deprecation notice when hashing the file cache path on Oracle - #41824 ship only the app payload in the release tarballs - #41835 release the file handle when a bitmap preview cannot be decoded - #41855 show a media type icon when a preview file cannot be opened - #41869 restrict federated address book sync to the trusted server Changes: - #41775 update PHP dependencies - #41785 require rhukster/dom-sanitizer as a tagged release - #41808 restore Oracle database support in the command line installer The #41824 fragment is carried over from #41825, which prepared this release on a release/v11.0.1 branch that the org maintenance ruleset freezes after its first push; that branch cannot take the changelog commit, so this supersedes it. Once merged, v11.0.1 gets tagged on the merged commit and the release bundles are built and published from owncloud/server-release. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Thomas Müller <[email protected]>
oc-tmueller
added a commit
that referenced
this pull request
Sep 25, 2026
* feat: release 11.0.1 Bump version.php to 11.0.1 and materialize the changelog fragments for the first patch release of the 11.0 line. $OC_Version becomes [11, 0, 1, 0]: the 4th digit is the internal DB-upgrade patch level, not the public patch number, and nothing in this release needs it moved. The 15 fragments in changelog/unreleased/ move into changelog/11.0.1_2026-09-25/ (git mv, so the renames stay tracked) and CHANGELOG.md is regenerated with calens. unreleased/ keeps its .gitkeep and is now empty, ready for the next cycle. Security: - #41827 reject SVG/script content before it reaches ImageMagick bitmap previews - #41834 pin the Imagick coder for each preview provider - #41856 prevent path traversal via appconfig public_/remote_ keys Bugfixes: - #41676 reduce priority of checkPropFind event - #41779 do not echo secrets when setting config values via occ - #41782 restore index usage for filecache writes on Oracle - #41807 show federated users in the share dialog when local users also match - #41808 avoid a deprecation notice when hashing the file cache path on Oracle - #41824 ship only the app payload in the release tarballs - #41835 release the file handle when a bitmap preview cannot be decoded - #41855 show a media type icon when a preview file cannot be opened - #41869 restrict federated address book sync to the trusted server Changes: - #41775 update PHP dependencies - #41785 require rhukster/dom-sanitizer as a tagged release - #41808 restore Oracle database support in the command line installer The #41824 fragment is carried over from #41825, which prepared this release on a release/v11.0.1 branch that the org maintenance ruleset freezes after its first push; that branch cannot take the changelog commit, so this supersedes it. Once merged, v11.0.1 gets tagged on the merged commit and the release bundles are built and published from owncloud/server-release. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Thomas Müller <[email protected]> * fix: name every updated PHP dependency in the 11.0.1 changelog composer/semver (3.4.4 to 3.5.0) and nikic/php-parser (v5.8.0 to v5.9.0) both moved since v11.0.0, both are direct entries in composer.json's require, and neither was named in the fragment. Diffing composer.lock at v11.0.0 against this branch gives 26 changed production packages; the fragment listed 24. Each was missed by the pass that bumped it: #41864 edited this fragment in the same commit that raised composer/semver, and #41829 did the same for nikic/php-parser. The list is not direct-only either — it already names transitive dependencies such as guzzlehttp/psr7 and symfony/mime — so both are omissions, not a scoping decision. An administrator reconciling the 11.0.1 notes against advisory ranges would read both as unchanged. The four remaining differences are require-dev only (myclabs/deep-copy, phpunit/phpunit, sebastian/exporter, sebastian/recursion-context) and stay out, matching the fragment's existing production-only scope; the tarball installs --no-dev. Also restores CHANGELOG.md's trailing newline. `ocrelease changelog` writes calens' stdout as captured by execa, which strips it; the last six "chore: update changelog" revisions of the file all end in one, and so does calens' own output, so the next regeneration would have put it back as a one-line no-op diff. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Thomas Müller <[email protected]> --------- Signed-off-by: Thomas Müller <[email protected]> Co-authored-by: Thomas Müller <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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
Front-port of #41803, which landed on
10.16asb46c15d76.mastercarries the same defect.The first commit is byte-identical to what merged: all 874 changed code lines match the merged
10.16squash commit, verified by diffing the two net diffs, where only blob hashes and hunk offsets differ. The full discussion, including three rounds of review, is on #41803; this description summarises the result.One commit on top of that is not in
10.16— see "Delta against 10.16" at the end.An authenticated admin could set the
coreappconfig keypublic_webdav(or anypublic_/remote_key) to a path-traversal value thatpublic.phpthenrequire_once'd on the nextGET /public.php/<service>, achieving remote code execution.1. Sink — the handler include is contained to the app directory
public.phpandremote.phpresolved the stored<appId>/<path>value by concatenatingOC_App::getAppPath($app), which is not a containment check.getAppPath()returnsfalsefor an app id with no directory on disk, andfalse . '/'is'/', so the include path becomes absolute — and an absolute path contains no traversal sequence, which is whyremote.php's pre-existing../substring test did not close this.isInstalled()does not help either: it only tests for an appconfigenabledrow, not for a directory, and an admin can create such a row for any app id.The stored value now resolves through a new
OC_App::getServiceHandlerPath(), which requires the target torealpath()inside the app's own directory (with a trailing separator, so…/apps/filesdoes not accept…/apps/files_sharing) and to be an existing.phpfile. That also covers a symlink out of the app tree. Theis_file()half matters on its own:require_onceon a directory namedx.phpis anE_COMPILE_ERRORthe callers'catch (\Throwable)cannot handle. A NUL byte in either argument is refused before either is used as a path.No legitimate value is affected — every programmatic writer stores
<appId>/<path from info.xml>, and a test pins all six shipped handlers.2. Guards on the way in — non-canonical ids and keys are refused, not enumerated
Enumerating mangled spellings of
corecannot be complete: the only requirement for a bypass is that the written app id compare equal tocoreunder the database collation, which is an open set. Blank padding into thevarchar(32)appidcolumn, an accent-insensitive collation, and a trailing invalid byte all survive normalisation. So any app id outside[a-zA-Z0-9_.-]{1,32}is refused outright onsetValueanddeleteApp, in both the controller and the legacy endpoint. The charset is anchored with\zrather than$, because$also matches before a trailing newline, which would let a 33-byte id truncate onto an existing row.The same reasoning applies to the key, which was compared case-sensitively: under a case-insensitive collation
PUBLIC_webdavfolds onto the storedpublic_webdavrow. The prefix test is case-insensitive now, and a non-canonical key is refused outright oncoreonly, sofiles_sharingkeeps its legitimatepublic_share_*keys.deleteKeydeliberately does not demand a canonical app id — a row written under one before this guard existed (viaoccorsetAppValue()) would otherwise be undeletable through both admin paths. Such a row may only be removed key by key, and only for a canonical, non-handler key, becauseisCoreApp()compares a normalised string and cannot see a spelling only the collation folds. A deleted handler row is not self-healing: only an app version bump re-registers it.3. Reads are refused too
Otherwise the endpoints hand back the handler path they refuse to let an admin set. The legacy endpoint had no read guard at all. Its guard checks the key in every source the dispatch might read it from rather than the first one it finds — the write actions take
$_POST['key']whilegetValue/hasKeytake$_GET['key'], and both are attacker-controlled independently, so validating one source alone lets a harmless decoy in the other satisfy the guard while the action consumes the real key.To stop the two endpoints drifting apart,
isCoreApp(),isCanonicalAppId(),isCanonicalConfigKey(),isServiceHandlerKey()andisProtectedCoreServiceKey()areOC_Appstatics that both call, with their own tests.4. Two pre-existing bugs in the reworked flow
getAppValue()returns''for an unregistered service rather thannull, so the$file === nulltest never fired and the request fell through to "App not installed" — a logged 500 onpublic.phpand, onremote.php, aRemoteExceptionwithgetCode()0, whichOC_Response::setStatus()turns into a bogusHTTP/1.1 0that caches, monitoring and sync clients read as success. Both answer 404 now, and everyRemoteExceptioncarries an explicit status. Refusals answer 503, because that is whathandleException()already produced on a WebDAV request, and a sync client must not be told the root is gone.Tests
tests/lib/legacy/AppTest.phpcovers the containment helper (file inside the app, traversal that stays inside, traversal out, an app id with no directory on disk, the sibling-directory boundary, a directory namedhandler.php, a non-.phptarget, a missing file, NUL bytes, empty arguments) and all five new statics, and pins the six shipped handler values.tests/Settings/Controller/AppConfigControllerTest.phpcovers the mangledcorespellings, the non-canonical ids and keys, the read guards, the narroweddeleteKeygate, and the allowed near-misses includingfiles_sharing/public_share_*.core/ajax/appconfig.phpcannot be covered by an API test — it callsOCP\JSON::callCheck()→passesCSRFCheck(), which needs a browser session, and there is no harness forcore/ajax/*. That is exactly why the logic lives in unit-testableOC_Appstatics; the wiring was verified by hand.Verified locally
In
owncloudci/php:8.3on sqlite, matching this branch's CI matrix:tests/lib/legacy/AppTest.php— OK (89 tests, 107 assertions)tests/Settings/Controller/AppConfigControllerTest.php— OK (83 tests, 235 assertions)php-cs-fixer --dry-runover the seven changed PHP files — 0 of 7 need changescalens— exit 0, entry renders as expectedThe end-to-end live-instance checks (the three attack values refused;
public.php/webdav,public.php/files,remote.php/webdav,remote.php/davall still serving) were done on the10.16change this is identical to — see #41803.Delta against 10.16
1f37060is an extra fix found while reviewing this front-port. It is deliberately master-only — see "Why this one is not backported" below.getValue()checkedis_string()on the app id but not on the key, unlikesetValue()anddeleteKey(), while its comment claimed the three entry points share one predicate. Both core predicates short-circuit on a non-core app, so for any other app an array key fell through toOC\AppConfigas a subscript — an "Illegal offset type" warning on PHP 7, aTypeErroron PHP 8, i.e. a logged 500 where the two write paths answer 400.The route's
{key}is not a guarantee:Request::decodeContent()decodes anapplication/jsonbody and merges it overitems['parameters']for a GET as well — i.e. aftersetUrlParameters()merged the url params — so a body of{"key":["x"]}overrides the{key}taken from the path. Admin-only and no security consequence (a read cannot fold onto a stored row), but it is the exact failure mode the rest of the diff sets out to close. The new test was confirmed red before the fix.Why this one is not backported
The 500 is unreachable on
10.16, because the runtime that produces it cannot run10.16:lib/base.phpthere exits with "This version of ownCloud is not compatible with PHP 8.0" forPHP_VERSION_ID >= 80000, andcomposer.jsonpinsplatform.php: 7.4. Probed on both images rather than inferred —isset($cache['app'][['k']])raises anIllegal offset type in isset or emptywarning and returnsfalseonowncloudci/php:7.4, but aTypeErroronowncloudci/php:8.3. SinceOC\AppConfig::getValue()→hasKey()→isset()applies no string cast,10.16answers 200 with thedefaultand logs one warning where this branch answers 400.So on
10.16the difference is cosmetic, with no security consequence — the guards that protect the handler path eachis_string()-check and fail closed on their own. Not worth a backport PR and a second full CI matrix; the cost is a small context difference for any future cherry-pick touchinggetValue().Deliberately left for follow-ups
OC\AppConfig::setValue(). That would coveroccand every app, but it changesIConfig::setAppValue()for all writers, so it belongs in a major release.public.phpstill answers a logged 500 whereremote.phpnow answers 503.getKeys($app)is the one appconfig entry point still without anis_string()guard, so{"app":["core"]}in a JSON body gives the same admin-triggerable 500 as above. Left out deliberately: it is pre-existing, untouched by this diff, and reading key names cannot disclose a handler path, since the path is the value. Notecore/ajax/appconfig.phpalready refuses a non-string app id for every action, so the two endpoints disagree on this one point.getServiceHandlerPath()returns a barefalsefor six distinct reasons and logs none of them. Two are environmental rather than malicious — a handler file that is a symlink out of the app directory, and an app directory outsideopen_basedir, whererealpath()returnsfalse— and both turn a working service into a generic 500/503 with only "Path not allowed" to go on. Adebug-level line naming the reason would make that diagnosable without weakening the check.