Skip to content

fix: only navigate to a validated absolute http(s) return URL [4.2] - #621

Open
oc-tmueller wants to merge 1 commit into
4.2from
fix/validated-return-to-server-url-4.2
Open

fix: only navigate to a validated absolute http(s) return URL [4.2]#621
oc-tmueller wants to merge 1 commit into
4.2from
fix/validated-return-to-server-url-4.2

Conversation

@oc-tmueller

Copy link
Copy Markdown
Contributor

Backport of #620 to the 4.2 (ownCloud 10) line.

The four touched files are byte-identical between 4.2 and master, so this is
a clean cherry-pick of the same commit — no adaptation was needed.

Summary

The value that tells the editor where to navigate when it is closed is now
supplied by the server side and validated, instead of being taken from the
server URL parameter in documents.js.

  • DocumentController::federated() validates server as an absolute http(s)
    URL with a non-empty host and returns the usual responseError() otherwise,
    alongside the existing request guards. The validated value is handed to the
    template as return_to_server.
  • index() and public() emit an empty return_to_server — only a federated
    share ever returns to a remote server. All three methods render the same
    template, so all three set the key.
  • templates/documents.php emits it as a hidden input, following the existing
    #wopi-url idiom.
  • documents.js reads that hidden input rather than the URL parameter, and
    re-checks the value with new URL() before using it as a navigation target,
    falling back to the document list if it does not parse. A path component is
    accepted, so subdirectory installs keep working.

Separately, the WOPI postMessage target origin is narrowed from '*' to the
Collabora Online origin derived from the discovery urlsrc, and both message
listeners now ignore events that do not come from that origin.

Core's shared getURLParameter() is deliberately untouched — it is a global
also used by apps/files.

Testing

Re-verified on this branch against ownCloud 10.16.4 / PHP 7.4, not just
copied from #620:

  • Full unit suite: 78 tests, 199 assertions, green (23 in
    DocumentControllerTest, 20 of them new).
  • php-cs-fixer (ownCloud coding standard): clean, 0 of 44 files.
  • phpstan level 5 on appinfo lib: no errors.

The JS side is verified manually — this repo has no JS test harness.

🤖 Generated with Claude Code

The return-to-server value is now supplied by the server side through a
hidden input instead of being read from the URL. federated() validates it
as an absolute http(s) URL with a non-empty host and rejects anything
else the same way the other request guards do; index() and public() emit
an empty value, since only a federated share ever returns to a remote
server. documents.js re-checks the value before using it as a navigation
target and falls back to the document list if it does not parse.

A path is accepted, installations can live in a subdirectory.

Also narrows the WOPI postMessage target origin from '*' to the Collabora
Online origin derived from the discovery urlsrc, and ignores incoming
messages that do not come from that origin. That origin has to fail
closed, and new URL() throws for neither of the two ways it can be
missing: an empty urlsrc - which is what discovery returns when it cannot
be read - resolves against the base URL and would make this server its
own Collabora Online origin, and a urlsrc that is not http(s) has the
opaque origin 'null', which is also what a sandboxed frame reports as
its own origin. Both now yield no origin at all, so messages are neither
accepted nor sent.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Thomas Müller <323649642+oc-tmueller@users.noreply.github.com>
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.

2 participants