fix: encode search highlights returned as a DAV property - #41760
Merged
Conversation
The search-highlights property of the files search REPORT returned the elasticsearch highlight fragment unencoded. That fragment is built from file content, so a user who shared a crafted file could place arbitrary markup in the property value. The property deliberately carries HTML - line breaks are substituted with <br/> - so a client rendering it as HTML would execute the injected markup. The fragment is now encoded before the line break substitution. The order matters: encoding afterwards would also escape the <br/> injected here on purpose. search_elastic additionally sets 'encoder' => 'html' on the highlight query, so the value arrives encoded already. This change keeps the property safe independently of which search backend produced it. Fixes OC10-124 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
5 tasks
phil-davis
approved these changes
Jul 29, 2026
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.
Description
The
search-highlightsproperty of the files searchREPORTreturned the elasticsearch highlight fragment unencoded. That fragment is built from file content, so a user who shared a crafted file could place arbitrary markup into the property value. The property deliberately carries HTML — line breaks are substituted with<br/>— so a client rendering it as HTML would execute the injected markup.The fragment is now encoded before the line break substitution. The order matters: encoding afterwards would also escape the
<br/>injected here on purpose.Related Issue
Motivation and Context
This is the second egress channel for the same fragment. owncloud/search_elastic#348 sets
'encoder' => 'html'on the highlight query, so with that PR in place the value already arrives encoded — but this change keeps the property safe independently of which search backend produced it, and independently of that app's version.Scope, stated precisely rather than overclaimed: I verified with a live
XMLWriterrun that Sabre already XML-escapes property text, so this was not an exploitable XML-transport hole. The value semantically carries HTML, so this is hardening of an HTML-bearing property, not a second active XSS.How Has This Been Tested?
testOnReportEscapesHighlights, a 4-case data provider covering<script>,<img onerror>, a payload combined with a newline (asserting the intended<br/>still comes through as real markup), and an already-encoded fragment (asserting single encoding only). Written test-first — all 4 cases failed before the fix.apps/dav/tests/unit/Connector/→ OK, 466 tests / 1720 assertions.FilesSearchReportPluginTestalone → OK, 22 tests / 208 assertions; the pre-existing highlight assertion still passes because its fixture has nothing to escape.php-cs-fixeron both changed files → 0 of 2 files to fix.Types of changes
Checklist:
changelog/unreleased/41760)🤖 Generated with Claude Code