Breaking Change T822459
Visible to All Users

Export to CSV format - Executable content can be automatically encoded

Exported data can contain executable content (for example, =cmd|' /C calc'!'!A1'). Such content makes it possible to execute malicious commands, provided that a user opens a file in Microsoft Excel and confirms that the file can be loaded and commands executed.

Applies to: 19.1.7, 19.1.8, 19.2.2, 19.2.3, 19.2.4

To prevent possible security vulnerabilities, we automatically encode potentially dangerous content prior to exporting it to the CSV format. For example, formulas are encoded into simple data to prevent command execution when the exported file is opened in a different location.

This behavior is controlled by the following properties:

If you want to revert to the previous behavior, refer to the code samples below:

C#
// ASP.NET Web Forms GridView protected void ExportToCSVButton_Click(object sender, EventArgs e){ var options = new CsvExportOptionsEx(); options.EncodeExecutableContent = DefaultBoolean.False; Grid.ExportCsvToResponse(options); }
Visual Basic
' ASP.NET Web Forms GridView Protected Sub ExportToCSVButton_Click(ByVal sender As Object, ByVal e As EventArgs) Dim options = New CsvExportOptionsEx() options.EncodeExecutableContent = DefaultBoolean.[False] Grid.ExportCsvToResponse(options) End Sub
C#
// ASP.NET void Application_Start(object sender, EventArgs e) { DevExpress.Export.ExportSettings.EncodeCsvExecutableContent = DevExpress.Utils.DefaultBoolean.False; }
Visual Basic
' ASP.NET Private Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) DevExpress.Export.ExportSettings.EncodeCsvExecutableContent = DevExpress.Utils.DefaultBoolean.[False] End Sub

Applies to: 19.1.9 and higher, 19.2.5 and higher

We disabled automatic encoding in these versions, because it sometimes resulted in undesired data modification. Our controls regarded all values that start with “=”, “-”, “+”, “@”, or “” as potentially unsafe. This means that our algorithm transformed a string cell value [-20%] into ["""-20%"""] (added unnecessary characters).

Note that Microsoft Excel implements their own sophisticated algorithm for unsafe content detection. The application will warn you if it finds values with malicious commands within the document.

To enable encoding, set the following properties to true:

C#
// ASP.NET Web Forms GridView protected void ExportToCSVButton_Click(object sender, EventArgs e){ var options = new CsvExportOptionsEx(); options.EncodeExecutableContent = DefaultBoolean.True; Grid.ExportCsvToResponse(options); }
Visual Basic
' ASP.NET Web Forms GridView Protected Sub ExportToCSVButton_Click(ByVal sender As Object, ByVal e As EventArgs) Dim options = New CsvExportOptionsEx() options.EncodeExecutableContent = DefaultBoolean.[True] Grid.ExportCsvToResponse(options) End Sub
C#
// ASP.NET void Application_Start(object sender, EventArgs e) { DevExpress.Export.ExportSettings.EncodeCsvExecutableContent = DevExpress.Utils.DefaultBoolean.True; }
Visual Basic
' ASP.NET Private Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) DevExpress.Export.ExportSettings.EncodeCsvExecutableContent = DevExpress.Utils.DefaultBoolean.[True] End Sub

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.