Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2015
    Posts
    423
    Plugin Contributions
    0

    Default Flexible Return Authorization (RMA)

    I use the zencart module Flexible Return Authorization (RMA)
    https://www.zen-cart.com/downloads.php?do=file&id=1692


    The form seems to be working fine. Every once in awhile I get a syntax error. Not sure How to go about and fix this. If a customer puts a special characteristics in the form do i need to block that?

    this is what the customer put in the form.
    HTML Code:
    Incorrect item from order 52394: ME-ARTR, Magnum Energy ME-ARTR, Magnum Advacnced Router. Quantity:1
    
    Would like to exchange for correct item: ME-ARC50, MAGNUM ENERGY ME-ARC50, ADVANCED REMOTE DIGITAL LCD DISPLAY REMOTE PANEL WITH 50' CABLE. Quantity: 2
    
    Please advise if this is possible.
    error
    HTML Code:
    [08-Jan-2020 20:12:02 America/New_York] PHP Fatal error:  1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CABLE. Quantity: 2
    
    
    
    Please advise if this is possible.', '7', '12345678', now(' at line 1 :: insert into orders_status_history (comments, orders_status_id, orders_id, date_added, rma_number, action) values ('Incorrect item from order 52394: ME-ARTR, Magnum Energy ME-ARTR, Magnum Advacnced Router. Quantity:1
    
    
    
    Would like to exchange for correct item: ME-ARC50, MAGNUM ENERGY ME-ARC50, ADVANCED REMOTE DIGITAL LCD DISPLAY REMOTE PANEL WITH 50' CABLE. Quantity: 2
    
    
    
    Please advise if this is possible.', '7', '12345678', now(), '1234567801082020', 'Get a Refund') ==> (as called by) /home/inverter/public_html/includes/templates/theme871/templates/tpl_returns_default.php on line 85 <== in /home/inverter/public_html/includes/classes/db/mysql/query_factory.php on line 171


    I found where the issue is coming from in templates\tpl_returns_default.php on line 83


    Code:
    if (ORDER_COMMENTS_RMA_OPTION == 'true') {
    $returnRMA = $orderID . $rma_number;
    $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_status_id, orders_id, date_added, rma_number, action) values ('" . $reason ."', '" . $autoRMA ."', '" . (int)$orderID ."', now(), '" . $returnRMA ."', '" . $action ."')");
    }
    Last edited by chadlly2003; 9 Jan 2020 at 02:13 AM.

  2. #2
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Default Re: Flexible Return Authorization (RMA)

    What are the properties of the comments field in your database? The ' will stop the code as special characters likely aren't permitted in that field.
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

  3. #3
    Join Date
    Jan 2015
    Posts
    423
    Plugin Contributions
    0

    Default Re: Flexible Return Authorization (RMA)

    This is a snapshot of the database field.....

    Name:  Untitled-2.jpg
Views: 54
Size:  61.9 KB

  4. #4
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Flexible Return Authorization (RMA)

    Quote Originally Posted by chadlly2003 View Post
    I use the zencart module Flexible Return Authorization (RMA)
    https://www.zen-cart.com/downloads.php?do=file&id=1692


    The form seems to be working fine. Every once in awhile I get a syntax error. Not sure How to go about and fix this. If a customer puts a special characteristics in the form do i need to block that?

    this is what the customer put in the form.
    HTML Code:
    Incorrect item from order 52394: ME-ARTR, Magnum Energy ME-ARTR, Magnum Advacnced Router. Quantity:1
    
    Would like to exchange for correct item: ME-ARC50, MAGNUM ENERGY ME-ARC50, ADVANCED REMOTE DIGITAL LCD DISPLAY REMOTE PANEL WITH 50' CABLE. Quantity: 2
    
    Please advise if this is possible.
    error
    HTML Code:
    [08-Jan-2020 20:12:02 America/New_York] PHP Fatal error:  1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CABLE. Quantity: 2
    
    
    
    Please advise if this is possible.', '7', '12345678', now(' at line 1 :: insert into orders_status_history (comments, orders_status_id, orders_id, date_added, rma_number, action) values ('Incorrect item from order 52394: ME-ARTR, Magnum Energy ME-ARTR, Magnum Advacnced Router. Quantity:1
    
    
    
    Would like to exchange for correct item: ME-ARC50, MAGNUM ENERGY ME-ARC50, ADVANCED REMOTE DIGITAL LCD DISPLAY REMOTE PANEL WITH 50' CABLE. Quantity: 2
    
    
    
    Please advise if this is possible.', '7', '12345678', now(), '1234567801082020', 'Get a Refund') ==> (as called by) /home/inverter/public_html/includes/templates/theme871/templates/tpl_returns_default.php on line 85 <== in /home/inverter/public_html/includes/classes/db/mysql/query_factory.php on line 171


    I found where the issue is coming from in templates\tpl_returns_default.php on line 83


    Code:
    if (ORDER_COMMENTS_RMA_OPTION == 'true') {
    $returnRMA = $orderID . $rma_number;
    $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_status_id, orders_id, date_added, rma_number, action) values ('" . $reason ."', '" . $autoRMA ."', '" . (int)$orderID ."', now(), '" . $returnRMA ."', '" . $action ."')");
    }
    The problem is clearly coming from the sql statement construction:
    Code:
    $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_status_id, orders_id, date_added, rma_number, action) values ('" . $reason ."', '" . $autoRMA ."', '" . (int)$orderID ."', now(), '" . $returnRMA ."', '" . $action ."')");
    Where the data being inserted is not escaped/prepared for database inserting. In this case, the single quote within the field causes an imbalance of quotes in the sql statement and could lead to security issues.

    Data that is to be inserted into the database needs to be properly prepared either in statements leading to this query or within the query itself. Something like this would address that issue and allow addition of the associated comment. Personally I don't know how the "properties of the comments field" have anything to do with this simple statement that was entered as it wasn't an extended code such as might be seen in foreign languages that would use utf8mb4 type content.

    Code:
    $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_status_id, orders_id, date_added, rma_number, action) values ('" . zen_db_input(zen_db_prepare_input($reason)) ."', '" . zen_db_input(zen_db_prepare_input($autoRMA)) ."', '" . (int)$orderID ."', now(), '" . zen_db_input(zen_db_prepare_input($returnRMA)) ."', '" . zen_db_input(zen_db_prepare_input($action)) ."')");
    May have overdone one or the other prepare statements; however, it is unclear about the origin/need for sanitization for some of the values. If it is user enterable, then likely needs to be prepared to prevent malicious action.

    There is another way to do something like this also:
    Generate the sql statement and then bind the variable to the statement in the type the variable is expected:
    Code:
    $sql = $db->bindvars($sql, ':reason:', $reason, 'string');
    Where the sql satatemnt would have:
    Code:
    (:reason:, :autoRMA:, etc...
    And similar replacement done for each.
    Last edited by mc12345678; 9 Jan 2020 at 03:05 AM.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Jan 2015
    Posts
    423
    Plugin Contributions
    0

    Default Re: Flexible Return Authorization (RMA)

    This seems to solve the issue. My question is which is a better option to protect myself against malice actions

    the first example or second

    Code:
    $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_status_id, orders_id, date_added, rma_number, action) values ('" . zen_db_input(zen_db_prepare_input($reason)) ."', '" . zen_db_input(zen_db_prepare_input($autoRMA)) ."', '" . (int)$orderID ."', now(), '" . zen_db_input(zen_db_prepare_input($returnRMA)) ."', '" . zen_db_input(zen_db_prepare_input($action)) ."')");

  6. #6
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Flexible Return Authorization (RMA)

    Quote Originally Posted by chadlly2003 View Post
    This seems to solve the issue. My question is which is a better option to protect myself against malice actions

    the first example or second

    Code:
    $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_status_id, orders_id, date_added, rma_number, action) values ('" . zen_db_input(zen_db_prepare_input($reason)) ."', '" . zen_db_input(zen_db_prepare_input($autoRMA)) ."', '" . (int)$orderID ."', now(), '" . zen_db_input(zen_db_prepare_input($returnRMA)) ."', '" . zen_db_input(zen_db_prepare_input($action)) ."')");
    Well, for readability a little of a combination of both seems "better". Looking at the code that is called by the first option, it appears that the following would be a better choice:
    Code:
    $sql = "insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_status_id, orders_id, date_added, rma_number, action) values (:reason:, :autoRMA:, " . (int)$orderID .", now(), :returnRMA:, :action:)";
    
    $sql = $db->bindVars($sql, ':reason:', zen_db_prepare_input($reason), 'string');
    $sql = $db->bindVars($sql, ':autoRMA:', zen_db_prepare_input($autoRMA), 'string');
    $sql = $db->bindVars($sql, ':returnRMA:', zen_prepare_input($returnRMA), 'string');
    $sql = $db->bindVars($sql, ':action:', zen_db_prepare_input($action), 'string');
     
    $db->Execute($sql);
    My previous recommendation skipped the zen_db_prepare_input portion which strips slashes, then converts certain space characters to a space and replaces < and > (I think) with an underscore to prevent the inclusion of html type tags and then removes opening and closing spaces. After that the db->bindVars escapes characters to support insertion as a string. But, if there is a need for html tags to be included (or simple characters such as greater than and/or less than), then may need to remove the zen_db_prepare_input portion...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v151 Flexible Return Authorization (RMA) for ZC v1.5.x [Support Thread]
    By DivaVocals in forum All Other Contributions/Addons
    Replies: 167
    Last Post: 11 Apr 2021, 08:56 PM
  2. Return Authorization Module (RMA)
    By voltage in forum All Other Contributions/Addons
    Replies: 648
    Last Post: 3 Jun 2015, 09:37 PM
  3. Return Merchandise Authorization (RMA) Module Follow-up
    By killertofu in forum Managing Customers and Orders
    Replies: 1
    Last Post: 11 Aug 2008, 11:13 PM
  4. Return Authorization Module (RMA)
    By dscott1966 in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 11 Nov 2006, 08:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR