VAITP Dataset

← Back to the dataset

CVE-2022-36099

Arbitrary script injection in XWiki Platform Wiki

  • CVSS 8.8
  • CWE-116
  • Input Validation and Sanitization
  • Remote

XWiki Platform Wiki UI Main Wiki is software for managing subwikis on XWiki Platform, a generic wiki platform. Starting with version 5.3-milestone-2 and prior to versions 13.10.6 and 14.4, it's possible to inject arbitrary wiki syntax including Groovy, Python and Velocity script macros via the request (URL parameter) using the `XWikiServerClassSheet` if the user has view access to this sheet and another page that has been saved with programming rights, a standard condition on a public read-only XWiki installation or a private XWiki installation where the user has an account. This allows arbitrary Groovy/Python/Velocity code execution which allows bypassing all rights checks and thus both modification and disclosure of all content stored in the XWiki installation. Also, this could be used to impact the availability of the wiki. This has been patched in versions 13.10.6 and 14.4. As a workaround, edit the affected document `XWiki.XWikiServerClassSheet` or `WikiManager.XWikiServerClassSheet` and manually perform the changes from the patch fixing the issue. On XWiki versions 12.0 and later, it is also possible to import the document `XWiki.XWikiServerClassSheet` from the xwiki-platform-wiki-ui-mainwiki package version 14.4 using the import feature of the administration application as there have been no other changes to this document since XWiki 12.0.

CVSS base score
8.8
Published
2022-09-08
OWASP
A01 Broken Access Control
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Insecure Direct Object References (IDOR)
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Fixed by upgrading
Yes

Solution

Upgrade to XWiki versions 13.10.6 or 14.4 to patch the vulnerability.

Vulnerable code sample

from flask import Flask, request

app = Flask(__name__)

def render_wiki_content(wiki_code):
    """Vulnerable function that demonstrates the security issue."""
    exec(wiki_code)

@app.route('/execute', methods=['GET'])
def execute_code():
    """Vulnerable function that demonstrates the security issue."""
    user_input = request.args.get('code')
    if user_has_view_access():
        render_wiki_content(user_input)
        return "Code executed!"
    else:
        return "Access denied!", 403

def user_has_view_access():
    """Vulnerable function that demonstrates the security issue."""
    return True

if __name__ == '__main__':
    app.run(debug=False)

Patched code sample

from flask import Flask, request

app = Flask(__name__)

def render_wiki_content(user, script, allowed_scripts):
    """Secure function that fixes the vulnerability."""
    # SECURE: This version prevents command injection
    if not user.has_permission('execute_scripts'):
        raise PermissionError("User  does not have permission to execute scripts.")

    if script not in allowed_scripts:
        raise ValueError("Script execution is not allowed.")

    try:
        exec(script)
    except Exception as e:
        raise RuntimeError(f"Script execution failed: {e}")

allowed_scripts = [
    'print("Hello, world!")',
    'x = 5\nprint(x * 2)'
]

@app.route('/execute', methods=['GET'])
def execute_code():
    """Secure function that fixes the vulnerability."""
    user_input = request.args.get('code')
    if user_has_view_access():
        render_wiki_content(user_input)
        return "Code executed!"
    else:
        return "Access denied!", 403

def user_has_view_access():
    """Secure function that fixes the vulnerability."""
    return True


if __name__ == '__main__':
    app.run(debug=False)

Cite this entry

@misc{vaitp:cve202236099,
  title        = {{Arbitrary script injection in XWiki Platform Wiki}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-36099},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-36099/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::