View Issue Details

This bug affects 1 person(s).
 260
IDProjectCategoryView StatusLast Update
19253Bug reportsSecuritypublic2024-02-05 11:32
ReporterDenisChenu Assigned Totibor.pacalat  
PrioritynoneSeverityminor 
Status closedResolutionfixed 
Product Version6.3.x 
Summary19253: CSV injection in export quota
Description

When using a spreadsheet program like Microsoft Excel or LibreOffice Calc to open a CSV file, the software interprets any cell that begins with "=" as a formula. CSV injection, also known as formula injection, occurs when websites incorporate user-supplied data into CSV files without proper validation.

Steps To Reproduce

Steps to reproduce

(Replace this text with detailed step-by-step instructions on how to reproduce the issue)

Expected result

(Write here what you expected to happen)

Actual result

(Write here what happened instead)

TagsNo tags attached.
Bug heat260
Complete LimeSurvey version number (& build)6.3.1+231023
I will donate to the project if issue is resolvedNo
Browsernot relevant
Database type & versionnot relevant
Server OS (if known)not relevant
Webserver software & version (if known)not relevant
PHP Versionnot relevant

Users monitoring this issue

There are no users monitoring this issue.

Activities

DenisChenu

DenisChenu

2023-11-20 12:15

developer   ~78530

https://bugs.limesurvey.org/view.php?id=19252

========
When using a spreadsheet program like Microsoft Excel or LibreOffice Calc to open a CSV file, the software interprets any cell that begins with "=" as a formula. CSV injection, also known as formula injection, occurs when websites incorporate user-supplied data into CSV files without proper validation.

It has been detected the possibility of injecting CSV formulas into the titles of survey quotas, which can subsequently be exported to CSV.

To mitigate this vulnerability, it is recommended to validate the input entered by a user to ensure that no cell begins with any of the following characters:

Equal to ("=")
Plus ("+")
Minus ("-")
At ("@")"

On its own, this functionality would not have a high impact, as the CSV quotas can only be exported by the same user. However, considering the vulnerability which allows the editing of quotas belonging to others, an attacker could add malicious formulas to another user, which would be executed when that user exports their quotas.

5.png (90,281 bytes)   
5.png (90,281 bytes)   
6.png (118,467 bytes)
gabrieljenik

gabrieljenik

2023-12-15 15:34

manager   ~79014

@DenisChenu Shall I take this?

DenisChenu

DenisChenu

2023-12-15 15:53

developer   ~79015

You can.
I just copy/paste from another report.

gabrieljenik

gabrieljenik

2023-12-15 16:15

manager   ~79017

I just copy/paste from another report.

You mean the details of the ticket?

gabrieljenik

gabrieljenik

2023-12-23 14:54

manager   ~79066

Master PR: https://github.com/LimeSurvey/LimeSurvey/pull/3677
WIP.

Implemented the filter over the input as suggested on the ticket.
Still, not sure that's the best.
This could happen on a million other screens, can't sanitize all.
Also, at development time, you don't know if an input will be exported or not.

My call would be to create some kind of lib that escapes cell contents when exported.
Ex:

  • CsvEncoder from symfony/serializer.
  • EscapeFormula from league/csv.
    Or custom one with a function: EscapeCell
DenisChenu

DenisChenu

2023-12-23 18:50

developer   ~79067

You mean the details of the ticket?

Yes , see https://bugs.limesurvey.org/view.php?id=19252#c78528

Comment on a different issue.

My opinion : we must allow it in DB, no reason to disallow it.

But we must encode when export

Strangely : we don't encode = on CsvExprt ? https://github.com/LimeSurvey/LimeSurvey/blob/8c332cc638306875f965ccd347ef5e5573f27ed0/application/helpers/admin/export/CsvWriter.php#L102

We have to add a ' if string start with = https://github.com/symfony/symfony/blob/1934b2ec33ffc44e456fbde9737c8d9c6173a629/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php#L217

Or custom one with a function: EscapeCell

Maybe most simple here.

gabrieljenik

gabrieljenik

2023-12-26 18:16

manager   ~79069

You say

My opinion : we must allow it in DB, no reason to disallow it.

But you said this before

To mitigate this vulnerability, it is recommended to validate the input entered by a user to ensure that no cell begins with any of the following characters:

I believe it is no harm to apply in input (optionally) and mandatory on export.
We will work on an escape function

DenisChenu

DenisChenu

2023-12-27 14:16

developer   ~79071

But you said this before

No : i copy/paste https://bugs.limesurvey.org/view.php?id=19252#c78528

I believe it is no harm to apply in input (optionally) and mandatory on export.

If it's in model : it's not optionnal.
We just need in for CSV : the do it when doing a CSV export …

gabrieljenik

gabrieljenik

2023-12-29 20:41

manager   ~79075

@tibor.pacalat: I think we should create a new story for reviewing all csv exports, right?

DenisChenu

DenisChenu

2024-01-08 11:00

developer   ~79098

I think we should create a new story for reviewing all csv exports, right?

Yes : i think we have same issue on Export Response

tibor.pacalat

tibor.pacalat

2024-01-31 15:21

administrator   ~79369

I'll create a story in our JIRA regarding

| @tibor.pacalat: I think we should create a new story for reviewing all csv exports, right?

This particular issue has been resolved.

DenisChenu

DenisChenu

2024-01-31 15:28

developer   ~79371

… arg , still not reported on my part …

guest

guest

2024-01-31 15:29

viewer   ~79372

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=36021

guest

guest

2024-01-31 15:29

viewer   ~79373

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=36022

LimeBot

LimeBot

2024-02-05 11:32

administrator   ~79413

Fixed in Release 6.4.5+240205

Related Changesets

LimeSurvey: master 41993c4a

2024-01-31 15:19:50

Gabriel Jenik


Committer: GitHub Details Diff
Fixed issue 19253: CSV injection in export quota (03677)

Co-authored-by: lapiudevgit <devgit@lapiu.biz>
Affected Issues
19253
mod - application/controllers/QuotasController.php Diff File
add - application/core/LSYii_NonFormulaValidator.php Diff File
mod - application/helpers/common_helper.php Diff File
mod - application/models/Quota.php Diff File

LimeSurvey: master 41993c4a

2024-01-31 15:19:50

Gabriel Jenik


Committer: GitHub Details Diff
Fixed issue 19253: CSV injection in export quota (03677)

Co-authored-by: lapiudevgit <devgit@lapiu.biz>
Affected Issues
19253
mod - application/controllers/QuotasController.php Diff File
add - application/core/LSYii_NonFormulaValidator.php Diff File
mod - application/helpers/common_helper.php Diff File
mod - application/models/Quota.php Diff File

Issue History

Date Modified Username Field Change
2023-11-20 12:15 DenisChenu New Issue
2023-11-20 12:15 DenisChenu Note Added: 78530
2023-11-20 12:15 DenisChenu File Added: 5.png
2023-11-20 12:15 DenisChenu File Added: 6.png
2023-11-20 12:15 DenisChenu Bug heat 250 => 252
2023-12-15 15:34 gabrieljenik Note Added: 79014
2023-12-15 15:34 gabrieljenik Bug heat 252 => 254
2023-12-15 15:53 DenisChenu Note Added: 79015
2023-12-15 16:15 gabrieljenik Note Added: 79017
2023-12-15 16:15 gabrieljenik Assigned To => gabrieljenik
2023-12-15 16:15 gabrieljenik Status new => assigned
2023-12-23 14:54 gabrieljenik Note Added: 79066
2023-12-23 18:50 DenisChenu Note Added: 79067
2023-12-26 18:16 gabrieljenik Note Added: 79069
2023-12-27 14:16 DenisChenu Note Added: 79071
2023-12-29 20:40 gabrieljenik Assigned To gabrieljenik => DenisChenu
2023-12-29 20:40 gabrieljenik Status assigned => ready for code review
2023-12-29 20:41 gabrieljenik Note Added: 79075
2024-01-08 11:00 DenisChenu Note Added: 79098
2024-01-08 11:02 DenisChenu Assigned To DenisChenu => gabrieljenik
2024-01-08 11:02 DenisChenu Status ready for code review => ready for testing
2024-01-08 14:14 gabrieljenik Assigned To gabrieljenik => tibor.pacalat
2024-01-31 15:21 tibor.pacalat Note Added: 79369
2024-01-31 15:21 tibor.pacalat Bug heat 254 => 256
2024-01-31 15:24 tibor.pacalat Status ready for testing => resolved
2024-01-31 15:24 tibor.pacalat Resolution open => fixed
2024-01-31 15:28 DenisChenu Note Added: 79371
2024-01-31 15:29 Changeset attached => LimeSurvey master 41993c4a
2024-01-31 15:29 Changeset attached => LimeSurvey master 41993c4a
2024-01-31 15:29 guest Note Added: 79372
2024-01-31 15:29 guest Note Added: 79373
2024-01-31 15:29 guest Bug heat 256 => 258
2024-01-31 15:29 guest Bug heat 256 => 258
2024-02-05 11:32 LimeBot Note Added: 79413
2024-02-05 11:32 LimeBot Status resolved => closed
2024-02-05 11:32 LimeBot Bug heat 258 => 260