VAITP Dataset

← Back to the dataset

CVE-2019-9854

LibreOffice macro execution bypass vulnerability

  • CVSS 7.8
  • CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
  • Input Validation and Sanitization
  • Remote

LibreOffice has a feature where documents can specify that pre-installed macros can be executed on various script events such as mouse-over, document-open etc. Access is intended to be restricted to scripts under the share/Scripts/python, user/Scripts/python sub-directories of the LibreOffice install. Protection was added, to address CVE-2019-9852, to avoid a directory traversal attack where scripts in arbitrary locations on the file system could be executed by employing a URL encoding attack to defeat the path verification step. However this protection could be bypassed by taking advantage of a flaw in how LibreOffice assembled the final script URL location directly from components of the passed in path as opposed to solely from the sanitized output of the path verification step. This issue affects: Document Foundation LibreOffice 6.2 versions prior to 6.2.7; 6.3 versions prior to 6.3.1.

CVSS base score
7.8
Published
2019-09-06
OWASP
A01 Broken Access Control
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Unauthorized Access
Fixed by upgrading
Yes

Solution

Update LibreOffice to version 6.2.7 or 6.3.1 or higher.

Vulnerable code sample

import os
from urllib.parse import unquote

def load_script(script_path):
    """Vulnerable function that demonstrates the security issue."""
    decoded_path = unquote(script_path)

    script_file_path = decoded_path

    with open(script_file_path, 'r') as script_file:
        exec(script_file.read())


load_script('/path/to/libreoffice/share/Scripts/python/my_script.py')

Patched code sample

import os
from urllib.parse import unquote

def load_script(script_path):
    """Secure function that fixes the vulnerability."""
    # SECURE: This version prevents command injection
    base_directory = '/path/to/libreoffice/share/Scripts/python'
    user_directory = '/path/to/libreoffice/user/Scripts/python'

    decoded_path = unquote(script_path)

    if not (decoded_path.startswith(base_directory) or decoded_path.startswith(user_directory)):
        raise ValueError("Access denied: Invalid script path")

    normalized_path = os.path.normpath(decoded_path)

    if not (normalized_path.startswith(base_directory) or normalized_path.startswith(user_directory)):
        raise ValueError("Access denied: Invalid script path after normalization")

    with open(normalized_path, 'r') as script_file:
        exec(script_file.read())

try:
    load_script('/path/to/libreoffice/share/Scripts/python/my_script.py')
except ValueError as e:
    print(e)

Cite this entry

@misc{vaitp:cve20199854,
  title        = {{LibreOffice macro execution bypass vulnerability}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2019},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2019-9854},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2019-9854/}}
}
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 ::