summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorStefan <[email protected]>2023-04-23 00:44:57 +0200
committerStefan <[email protected]>2023-04-23 00:47:29 +0200
commitfa2fefd762061481db0206a7f7131c2dae327cb9 (patch)
tree160ded2157ecdd2ea08da0ef42304bf259a83a74 /test
parent615d814ffb740d11f60764cbceb52a12277304ad (diff)
downloadcaxlsx-fa2fefd762061481db0206a7f7131c2dae327cb9.tar.gz
caxlsx-fa2fefd762061481db0206a7f7131c2dae327cb9.zip
Add test to ensure various OWASP prefixes are never parsed as formula
Diffstat (limited to 'test')
-rw-r--r--test/workbook/worksheet/tc_cell.rb30
1 files changed, 29 insertions, 1 deletions
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index cb878c12..907ce97e 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -405,7 +405,35 @@ class TestCell < Test::Unit::TestCase
assert(doc.xpath("//t[text()='+2']").any?)
end
- def test_to_xml_string_other_owasp_escaped
+ def test_to_xml_string_owasp_prefixes_that_are_no_excel_formulas
+ # OWASP mentions various prefixes that might designate formulas when data is read as CSV:
+ # https://owasp.org/www-community/attacks/CSV_Injection
+ # Except for `=` none of these prefixes are valid prefixes for formulas in Excel however,
+ # so they should never be interpreted / serialized as formulas by Caxlsx.
+ p = Axlsx::Package.new
+ ws = p.workbook.add_worksheet do |sheet|
+ sheet.add_row [
+ "@1",
+ "%2",
+ "|3",
+ "\rfoo",
+ "\tbar"
+ ], escape_formulas: false
+ end
+ doc = Nokogiri::XML(ws.to_xml_string)
+ doc.remove_namespaces!
+ assert(doc.xpath("//t[text()='@1']").any?)
+ assert(doc.xpath("//t[text()='%2']").any?)
+ assert(doc.xpath("//t[text()='|3']").any?)
+ assert(doc.xpath("//t[text()='\nfoo']").any?)
+ assert(doc.xpath("//t[text()='\tbar']").any?)
+ end
+
+ def test_to_xml_string_owasp_prefixes_that_are_no_excel_formulas_with_escape_formulas
+ # OWASP mentions various prefixes that might designate formulas when data is read as CSV:
+ # https://owasp.org/www-community/attacks/CSV_Injection
+ # Except for `=` none of these prefixes are valid prefixes for formulas in Excel however,
+ # so they should never be interpreted / serialized as formulas by Caxlsx.
p = Axlsx::Package.new
ws = p.workbook.add_worksheet do |sheet|
sheet.add_row [