Skip to content

fix: restrict federated address book sync to the trusted server - #41869

Merged
oc-tmueller merged 3 commits into
masterfrom
fix/carddav-sync-trusted-server-scope
Sep 25, 2026
Merged

oc-tmueller merged 3 commits into
masterfrom
fix/carddav-sync-trusted-server-scope

Conversation

@oc-tmueller

Copy link
Copy Markdown
Contributor

What

The federated system address book sync acted on the resource references a trusted server reported without checking that they belong to that server, and followed redirects that led away from it. Both are now refused.

TrustedServerClient is a Sabre\DAV\Client that only ever talks to the one trusted server it was constructed for. SyncService uses it for both requestSyncReport() and download().

Where the check lives, and why there

Screening the reported reference on its own is not sufficient, because it is not the only thing that decides which url is finally requested: Sabre\HTTP\Client resolves a Location header and re-issues the request itself.

createCurlSettingsArray() is the one method every url passes through before it reaches curl. It is called from doRequest() — which send()'s redirect loop re-enters once per hop — and from sendAsyncInternal(), which bypasses doRequest() entirely. Putting the rule there covers all of them at once, which is worth keeping in mind: the // TODO: use multi-get for download directly above the sync loop invites exactly the change that would otherwise slip past a doRequest()-only guard.

It throws \RuntimeException deliberately, and not a Sabre\HTTP\ClientException — send() catches those and hands them to exception handlers that are allowed to retry.

Reported references are still screened in the sync loop as well, so the ordinary case skips a single card and logs it instead of failing that server's whole sync.

Origin comparison

  • resolved with Sabre\Uri\resolve() first, so this check and the request that follows it cannot disagree about the target;
  • scheme and host compared case-insensitively (RFC 3986), and the http/https default port normalised, so an explicit :443 is not mistaken for a different origin;
  • fails closed when the base url has no readable scheme or host — including a triple-slash url, which parses to an empty host rather than a null one;
  • one scheme change is allowed: a trusted server stored as plain http redirecting to its own https site on the default ports. Without it, peers registered as http:// that 301 to https would stop syncing permanently.

Two further constraints on a reported reference:

  • control characters are rejected. They have no place in a reference, and sanitising for the log is not enough — the raw value is what reaches curl, and what basename() would store as the card uri we serve back to our own clients.
  • a reference naming no card is skipped ('', ., .. — all of which survive the origin check, because resolve() normalises them away). Storing one leaves a row our own clients resolve to the collection itself, never to be addressed or deleted again.

Compatibility

A well behaved peer is unaffected: an ownCloud peer reports paths on its own host and does not redirect away from it. Subfolder installs are covered, since they report paths from the server root.

A skipped resource is skipped for good — the sync token still advances, and sync-collection only reports a resource once per token. That is the right outcome for a resource that does not belong to the server reporting it; for a false positive it shows up as a warning in the log.

Tests

  • apps/dav/tests/unit/CardDAV/ — 160 tests / 403 assertions green on PHP 8.3. apps/federation/tests/ — 101 tests / 279 assertions green.
  • Every negative test asserts that download() is never called, since that is the method which issues the request; each one fails on that line if the corresponding guard is removed.
  • php-cs-fixer clean.

🤖 Generated with Claude Code

oc-tmueller and others added 2 commits September 25, 2026 09:55
The federated system address book sync acted on the resource references a
trusted server reported without checking that they belong to that server,
and followed redirects that led away from it.

Screening the reported reference alone is not sufficient, because it is not
the only thing that decides which url is finally requested: Sabre's http
client resolves a Location header and re-issues the request itself. Every
url the client is about to hand to curl passes through
createCurlSettingsArray() though, redirect hops and async requests
included, so the rule lives there - TrustedServerClient refuses to send a
request which is not on the trusted server it was built for. Reported
references are still screened in the sync loop as well, so the ordinary
case skips a single card instead of failing the whole sync.

Two further constraints on a reported reference. It is rejected if it
carries control characters, which have no place in one and would otherwise
reach curl and be stored as the card uri we serve back to our own clients.
And a reference naming no card - empty, '.' or '..', all of which survive
the origin check because resolve() normalises them away - is skipped,
because storing it would leave a row our own clients resolve to the
collection itself, never to be addressed or deleted again.

A well behaved peer is unaffected: it reports paths on its own host and
does not redirect away from it. A trusted server stored as plain http may
still redirect to its own https site, which is the one scheme change worth
following - same host, better transport - and a base url whose own origin
cannot be read is refused rather than matching everything.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Thomas Müller <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Thomas Müller <[email protected]>
@oc-tmueller
oc-tmueller marked this pull request as ready for review September 25, 2026 08:33
@oc-tmueller
oc-tmueller requested a review from a team as a code owner September 25, 2026 08:33
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Thomas Müller <[email protected]>

@jvillafanez jvillafanez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor thing, but it looks good.

Comment on lines +108 to +122
if (($base['scheme'] ?? '') === '' || ($base['host'] ?? '') === '') {
return false;
}

// host is case insensitive, see RFC 3986
if (\strcasecmp($base['host'], (string)$target['host']) !== 0) {
return false;
}

// so is scheme
$baseScheme = \strtolower($base['scheme']);
$targetScheme = \strtolower((string)$target['scheme']);
if ($baseScheme === $targetScheme) {
return self::getPort($base) === self::getPort($target);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather use the same comparison in all the cases.

$baseScheme = \strtolower($base['scheme']);
$baseHost = \strotolower($base['host']);
$targetScheme = \strtolower($target['scheme']);
...
if ($baseScheme === '' || $baseHost === '') {
  return false;
}
if ($baseHost !== $targetHost) {
  return false;
}
....

@phil-davis phil-davis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@oc-tmueller
oc-tmueller merged commit 04fa66a into master Sep 25, 2026
31 checks passed
@oc-tmueller
oc-tmueller deleted the fix/carddav-sync-trusted-server-scope branch September 25, 2026 09:32
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]>
This was referenced Sep 25, 2026
@kw-fscheuer

Copy link
Copy Markdown
Member

Approved from security.

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants