CVE-2023-29512
XWiki Platform Code Execution Vulnerability
- CVSS 8.8
- CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
- Input Validation and Sanitization
- Remote
XWiki Platform is a generic wiki platform offering runtime services for applications built on top of it. Any user with edit rights on a page (e.g., it's own user page), can execute arbitrary Groovy, Python or Velocity code in XWiki leading to full access to the XWiki installation. The root cause is improper escaping of the information loaded from attachments in `imported.vm`, `importinline.vm`, and `packagelist.vm`. This page is installed by default. This vulnerability has been patched in XWiki 15.0-rc-1, 14.10.1, 14.4.8, and 13.10.11. Users are advised to upgrade. There are no known workarounds for this vulnerability.
- CVSS base score
- 8.8
- Published
- 2023-04-19
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update XWiki to version 15.0-rc-1, 14.10.1, 14.4.8, or 13.10.11.
Vulnerable code sample
def import_attachment(attachment_content):
"""Vulnerable function that demonstrates the security issue."""
execute_code(attachment_content)
def execute_code(code):
"""Vulnerable function that demonstrates the security issue."""
exec(code)
attachment_content = "print('This is a test');"
import_attachment(attachment_content)Patched code sample
import ast
def import_attachment(attachment_content):
"""Secure function that fixes the vulnerability."""
content = escape_user_input(attachment_content)
if check_code(content) and not contains_blacklisted_keywords(content):
execute_code(content)
else:
print("Rejected unsafe code.")
def escape_user_input(user_input):
"""Secure function that fixes the vulnerability."""
escape_mapping = {
'<': '<',
'>': '>',
'{': '{',
'}': '}',
'$': '$',
'#': '#',
'%': '%',
'&': '&',
}
for char, escaped in escape_mapping.items():
user_input = user_input.replace(char, escaped)
return user_input
def contains_blacklisted_keywords(code):
"""Secure function that fixes the vulnerability."""
blacklist = ['import', 'exec', 'eval', 'open', 'os', 'subprocess', '__', 'globals', 'locals', 'input', 'compile', 'system']
return any(word in code for word in blacklist)
def check_code(code):
"""Secure function that fixes the vulnerability."""
try:
tree = ast.parse(code, mode='exec')
for node in ast.walk(tree):
if isinstance(node, ast.Name) and node.id not in {"print"}:
return False
if not isinstance(node, (
ast.Module, ast.Expr, ast.Call, ast.Name, ast.Load,
ast.Constant, ast.BinOp, ast.Add
)):
return False
return True
except Exception:
return False
def execute_code(code):
"""Secure function that fixes the vulnerability."""
safe_globals = {"__builtins__": {"print": print}}
exec(code, safe_globals)
attachment_content = "print('This is safe')"
import_attachment(attachment_content)Cite this entry
@misc{vaitp:cve202329512,
title = {{XWiki Platform Code Execution Vulnerability}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-29512},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-29512/}}
}
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 ::
