View Issue Details

IDProjectCategoryView StatusLast Update
0029130mantisbtsecuritypublic2023-09-26 12:04
ReporterDevendra Bhatla Assigned Todregad  
PriorityhighSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version2.25.2 
Target Version2.25.3Fixed in Version2.25.3 
Summary0029130: CVE-2021-43257: CSV Injection with CSV Export Feature
Description

Application is vulnerable on Viewing issues page. If a User reports an issue to the bug tracker list with a command and later another user who have an access to the bug tracker list export the csv will be affected by csv Injection as the application is not escaping or handling the input.

Steps To Reproduce

Step 1: Login into the application with any user.
Step 2: Navigate to Report Issue, fill in all the required details with =cmd|'/c calc.exe'!A1 in Summary field and report the issue.
Step 3: Now Login with another user who will later work on the particular bug and export the csv from export feature.
Step 4: Once the export is done, open the csv file which pops up a calculator and results in execution of summary column of the csv.

TagsNo tags attached.
Attached Files
CSV-POC.pdf (435,271 bytes)

Relationships

has duplicate 0032931 closeddregad Formula Injection via the Report Issue functionality 

Activities

Devendra Bhatla

Devendra Bhatla

2021-10-06 04:02

reporter   ~0065886

Any update on this ?

Devendra Bhatla

Devendra Bhatla

2021-10-15 01:43

reporter   ~0065915

Any progress on this ?

dregad

dregad

2021-10-29 13:12

developer   ~0065968

Sorry for the delay in responding. I confirm the problem.

I am however not sure about what the best way to fix this is.

It is easy enough when exporting data to prefix any text starting with =, @, - or + with a ', which will effectively disable the interpretation of a formula when the generated CSV is opened with Excel.

The problem is if the CSV needs to be consumed programmatically, then the added ' will "corrupt" the data. And MantisBT has no way to know how the exported file will be used.

dregad

dregad

2021-10-31 05:30

developer   ~0065971

CVE request 1166047 sent.

Base of proposed fix:

diff --git a/core/csv_api.php b/core/csv_api.php
index 795f9dc9b..0149e37b5 100644
--- a/core/csv_api.php
+++ b/core/csv_api.php
@@ -111,6 +111,13 @@ function csv_get_default_filename() {
  * @access public
  */
 function csv_escape_string( $p_string ) {
+   # Prevent CSV injection by escaping text that could be interpreted as a formula
+   if( $p_string && strpos( '=-+@', $p_string[0] ) !== false ) {
+       # Prefixing with a tab rather than single quote, as Excel does not show
+       # the tab visually in the cell.
+       $p_string = "\t" . $p_string;
+   }
+
        $t_escaped = str_split( '"' . csv_get_separator() . csv_get_newline() );
        $t_must_escape = false;
        while( ( $t_char = current( $t_escaped ) ) !== false && !$t_must_escape ) {

I'm considering adding a config option, to let users decide whether they want to prefix formulas to avoid CSV injection or not.

dregad

dregad

2021-11-03 04:24

developer   ~0065981

CVE-2021-43257 assigned.

@Devendra Bhatla any feedback ?

Devendra Bhatla

Devendra Bhatla

2021-11-03 05:35

reporter   ~0065982

Hi @dregad

Thanks for the heads up.
The fix seems fine to me. I request you to deploy the fix in the upcoming version of the product.

Also, thanks for assigning a CVE-ID for the same, it can be observed that the CVE-ID is marked as RESERVED. I would like to request you to make this publicly once the fix/patch is deployed.

Thanks and regards
Devendra Bhatla

dregad

dregad

2021-11-03 10:55

developer   ~0065983

I request you to deploy the fix in the upcoming version of the product

Yes this is the plan, as you can see I have set target version to 2.25.3.

it can be observed that the CVE-ID is marked as RESERVED.

Indeed. This is normal, as CVE-ID publication is delayed until the patch is out.
https://cve.mitre.org/about/faqs.html#reserved_signify_in_cve_record

I would like to request you to make this publicly once the fix/patch is deployed.

Of course, once 2.25.3 gets released, I'll notify MITRE and the CVE-ID will become public.

Devendra Bhatla

Devendra Bhatla

2021-11-08 07:56

reporter   ~0065992

Great. Would you please let me know by when i can expect the version 2.25.3 in order to validate the closure of the reported issue.

Thanks and regards
Devendra Bhatla

dregad

dregad

2021-11-08 09:04

developer   ~0065993

Soon, but I can't commit on a date - depends on my (lack of) spare time.

Devendra Bhatla

Devendra Bhatla

2021-12-22 13:28

reporter   ~0066094

Hi @dregad,
Hope you are doing good amid pandemic.
It would be great if you can share some progress.
Thanks

dregad

dregad

2021-12-23 04:15

developer   ~0066099

Sorry this is not forgotten, but I unfortunately do not have time to spend on Mantis at the moment.

dregad

dregad

2022-01-22 19:51

developer   ~0066184

Sorry that was resolved by mistake, due to inadvertantly pushing a work-in-progress branch.

dregad

dregad

2022-04-13 11:21

developer   ~0066420

@Devendra Bhatla apologies for taking so long to merge this, many thanks for your report and your patience.

I will ask MITRE to release the CVE.

Related Changesets

MantisBT: master-2.25 7f4534c7

2021-10-29 06:33

dregad


Details Diff
Escape strings to prevent CSV injection

Prefixing the string with a tab when it starts with =, -, + or @.

Thanks to Devendra Bhatla for reporting the issue.

Fixes 0029130, CVE-2021-43257
Affected Issues
0029130
mod - core/csv_api.php Diff File

MantisBT: master-2.25 99eb8d41

2021-10-29 13:23

dregad


Details Diff
New config $g_csv_injection_protection

Lets the user decide whether they want to prefix formulas to avoid CSV
injection or not.

Fixes 0029130
Affected Issues
0029130
mod - config_defaults_inc.php Diff File
mod - core/csv_api.php Diff File
mod - docbook/Admin_Guide/en-US/config/misc.xml Diff File