Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security fix: Introduce file type check for tax rate importer #222

Merged
merged 1 commit into from
May 4, 2020
Merged

Security fix: Introduce file type check for tax rate importer #222

merged 1 commit into from
May 4, 2020

Conversation

timbocode
Copy link
Contributor

Backport for woocommerce/woocommerce@737f6af

See also #214

Files affected:
includes/admin/importers/class-wc-product-csv-importer-controller.php
includes/admin/importers/class-wc-tax-rate-importer.php
includes/wc-conditional-functions.php

Files not included:

tests/unit-tests/util/conditional-functions.php

@timbocode timbocode added the Security Security fixes including WC backports label Feb 23, 2020
@timbocode timbocode added this to the 1.0.0-beta1 milestone Feb 23, 2020
@codecov-io
Copy link

codecov-io commented Feb 23, 2020

Codecov Report

Merging #222 into master will decrease coverage by 0.01%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #222      +/-   ##
============================================
- Coverage     40.83%   40.81%   -0.02%     
- Complexity    13447    13449       +2     
============================================
  Files           367      367              
  Lines         51275    51292      +17     
============================================
- Hits          20938    20936       -2     
- Misses        30337    30356      +19
Impacted Files Coverage Δ Complexity Δ
...rters/class-wc-product-csv-importer-controller.php 12.69% <ø> (ø) 69 <0> (ø) ⬇️
includes/wc-conditional-functions.php 7.86% <0%> (-1%) 0 <0> (ø)
...des/admin/importers/class-wc-tax-rate-importer.php 40.7% <0%> (-1.89%) 34 <0> (+2)
includes/class-wc-tax.php 79.4% <0%> (-0.55%) 130% <0%> (ø)
includes/class-wc-update-client.php 0% <0%> (ø) 64% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6180699...41ba9c0. Read the comment docs.

Copy link
Collaborator

@bahiirwa bahiirwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change 3c35038 doesn’t belong here. Please remove it, it’s already handled in another PR #220

EDIT - this was addressed in a later commit.

@timbocode timbocode requested a review from nylen February 24, 2020 15:55
@timbocode
Copy link
Contributor Author

Testing

  • Manually tested the CSV import using a badly formatted CSV file. It successfully rejected the file.

@bahiirwa
Copy link
Collaborator

bahiirwa commented Mar 6, 2020

On manual test of this file. I tried to add a .jpeg file and received the message below.

Upload jpeg
Screenshot 2020-03-06 at 19 52 51

Message below.

Screenshot 2020-03-06 at 19 52 58

Message expected: "Invalid file type. The importer supports CSV and TXT file formats."

The change itself has no problem the expected changes for the user reflect otherwise in messaging.

Uploading a CSV and txt allows for full upload as expected.

We might have to re-fix this as CC.

And also fix this issue in classic-commerce/includes/admin/importers/class-wc-product-csv-importer-controller.phpon line 89 where

/**
 * Check whether a file is a valid CSV file.
 *
 * @todo Replace this method with wc_is_file_valid_csv() function.
 * @param string $file File path.
 * @param bool   $check_path Whether to also check the file is located in a valid location (Default: true).
 * @return bool
 */
public static function is_file_valid_csv( $file, $check_path = true ) {

If this change is adopted, we need to introduce the new file checker for csv and txt from includes/wc-conditional-functions.php in to classic-commerce/includes/admin/importers/class-wc-product-csv-importer-controller.php

@bahiirwa bahiirwa self-requested a review March 6, 2020 17:05
Copy link
Contributor

@nylen nylen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why was tests/unit-tests/util/conditional-functions.php excluded from this change?

  2. I see the same behavior as @bahiirwa (the message is not the expected one), but otherwise the diff looks the same as woocommerce/woocommerce@737f6af. It's probably a good idea to test the same action using WooCommerce. If it behaves the same way then we should merge this and investigate separately.

@timbocode
Copy link
Contributor Author

  1. Yes, sorry. I meant to leave a note about that. The reason I left the test file out is because the new test appears to be looking for assets on a local c: drive and on other servers I'm not sure we have access to:
public function test_wc_is_file_valid_csv() {
  $this->assertTrue( wc_is_file_valid_csv( 'C:/wamp64/www/test.local/wp-content/uploads/2018/10/products_all_gg-1.csv' ) );
  $this->assertTrue( wc_is_file_valid_csv( '/srv/www/woodev/wp-content/uploads/2018/10/1098488_single.csv' ) );
  $this->assertFalse( wc_is_file_valid_csv( '/srv/www/woodev/wp-content/uploads/2018/10/img.jpg' ) );
  $this->assertFalse( wc_is_file_valid_csv( 'file:///srv/www/woodev/wp-content/uploads/2018/10/1098488_single.csv' ) );
}
  1. I did compare the operation of CC with WC 3.9.2 at the time, with a variety of file types (not just malformed CSV). WC gives the same message:

image

@bahiirwa
Copy link
Collaborator

bahiirwa commented May 4, 2020

I agree on the decision @timbocode took here. However, there a sample files in the repo that can be tested on the fly. This could be its on implementation.

Copy link
Collaborator

@bahiirwa bahiirwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside this #222 (comment) which we should consider seperately as well as add better message for the invalid file types

Manual tests passed:

  • Add taxes manually ne by one
  • Upload a csv and txt file with tax rates passes adding new tax rates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Security Security fixes including WC backports
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants