Results 1 to 10 of 10
  1. #1
    Join Date
    May 2006
    Posts
    13
    Plugin Contributions
    0

    Default [Done 1.3.8] Apostrophes in any order data w/ authorize.net database logging on

    I have experienced other errors related to this bug (http://www.zen-cart.com/forum/showthread.php?p=404423) while using 1.3.7 (and just finished upgrading to 1.3.8a which doesn't appear to fix it). Some of the discussion has centered around what is sent to authorize.net, but the other issue is invalid database update statements due to unmatched apostrophes.

    If any field in the order data contains an apostrophe -- whether in product names, customer name, customer address, etc -- and if "Enable Database Storage" is set to TRUE in the AIM module configuration, then the customer will receive a hard SQL error message when attempting to complete their order.

    This is the fix that has worked for me (recently updated for 1.3.8a):

    In authorizenet_aim.php, replace line 619:

    $sql = $db->bindVars($sql, ':sentData', print_r($this->reportable_submit_data, true), 'string');

    with:

    $reportable_submit_data_text = print_r($this->reportable_submit_data, true);
    $reportable_submit_data_text = str_replace("'", "''", $reportable_submit_data_text);
    $sql = $db->bindVars($sql, ':sentData', $reportable_submit_data_text, 'string');

    This effectively replaces single ' characters in the string to be saved with '' which works correctly. However, I am new to PHP, so there is probably a more elegant way to handle this.

    Bjornar

  2. #2
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Apostrophes in any order data w/ authorize.net database logging on -> hard error

    Quote Originally Posted by bjornarl View Post
    This effectively replaces single ' characters in the string to be saved with '' which works correctly. However, I am new to PHP, so there is probably a more elegant way to handle this.
    The 'string' parameter in the bindVars() function also transforms single ' characters with an appropriate character to allow insertion, and considers which database engine is in use to ensure it selects the appropriate character-escaping method to be used.

    If that's not working on your server, then, while I have no idea what your server specs and PHP configuration, version, etc details are, I'm inclined to suspect that you have something odd with magic_quotes or magic_quotes_sybase settings.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    May 2006
    Posts
    13
    Plugin Contributions
    0

    Default Re: Apostrophes in any order data w/ authorize.net database logging on -> hard error

    Ah, 1.3.7 didn't have the bindVars() call and this bug was definitely a problem then (at least on my server). I must have failed to test this properly in 1.3.8 (and when I looked at the 1.3.8 code I did not spot the transformation you mention).

    Sorry for the false report but thanks for the detailed response!

    Bjornar

  4. #4
    Join Date
    Sep 2007
    Posts
    9
    Plugin Contributions
    0

    Default Re: [Done 1.3.8] Apostrophes in any order data w/ authorize.net database logging on

    Any way to fix this in 1.3.7 ? I'm not looking forward to doing an upgrade at this point, as I simply don't have the time or enough bugs to justify it yet.

  5. #5
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: [Done 1.3.8] Apostrophes in any order data w/ authorize.net database logging on

    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    May 2006
    Posts
    13
    Plugin Contributions
    0

    Default Re: [Done 1.3.8] Apostrophes in any order data w/ authorize.net database logging on

    Quote Originally Posted by standpipe View Post
    Any way to fix this in 1.3.7 ? I'm not looking forward to doing an upgrade at this point, as I simply don't have the time or enough bugs to justify it yet.
    Looking in my version history, here's what I did to fix mine in 1.3.7:

    In authorizenet_aim.php, replaced:

    Code:
          // Insert the data into the database
          $db->Execute("insert into " . TABLE_AUTHORIZENET . "  (id, customer_id,order_id, response_code, response_text, authorization_type, transaction_id, sent, received, time, session_id) values ('', '" . $_SESSION['customer_id'] . "', '" . $new_order_id . "', '" . $db_response_code . "', '" . $db_response_text . "', '" . $db_authorization_type . "', '" . $db_transaction_id . "', '" . print_r($reportable_submit_data, true) . "', '" . $response_list . "', '" . $order_time . "', '" . $db_session_id . "')");
    with

    Code:
          // Insert the data into the database
    	  // BUGFIX: Added escaping of apostrophes used in addresses and other info
          $reportable_submit_data_text = print_r($reportable_submit_data, true);
          $reportable_submit_data_text = str_replace("'", "''", $reportable_submit_data_text);
    
          $db->Execute("insert into " . TABLE_AUTHORIZENET . "  (id, customer_id,order_id, response_code, response_text, authorization_type, transaction_id, sent, received, time, session_id) values ('', '" . $_SESSION['customer_id'] . "', '" . $new_order_id . "', '" . $db_response_code . "', '" . $db_response_text . "', '" . $db_authorization_type . "', '" . $db_transaction_id . "', '" . $reportable_submit_data_text . "', '" . $response_list . "', '" . $order_time . "', '" . $db_session_id . "')");
    Use at your own risk :)

  7. #7
    Join Date
    Nov 2003
    Posts
    1,155
    Plugin Contributions
    0

    Default Re: [Done 1.3.8] Apostrophes in any order data w/ authorize.net database logging on

    Quote Originally Posted by bjornarl View Post
    Looking in my version history, here's what I did to fix mine in 1.3.7:

    In authorizenet_aim.php, replaced:

    Code:
          // Insert the data into the database
          $db->Execute("insert into " . TABLE_AUTHORIZENET . "  (id, customer_id,order_id, response_code, response_text, authorization_type, transaction_id, sent, received, time, session_id) values ('', '" . $_SESSION['customer_id'] . "', '" . $new_order_id . "', '" . $db_response_code . "', '" . $db_response_text . "', '" . $db_authorization_type . "', '" . $db_transaction_id . "', '" . print_r($reportable_submit_data, true) . "', '" . $response_list . "', '" . $order_time . "', '" . $db_session_id . "')");
    with

    Code:
          // Insert the data into the database
    	  // BUGFIX: Added escaping of apostrophes used in addresses and other info
          $reportable_submit_data_text = print_r($reportable_submit_data, true);
          $reportable_submit_data_text = str_replace("'", "''", $reportable_submit_data_text);
    
          $db->Execute("insert into " . TABLE_AUTHORIZENET . "  (id, customer_id,order_id, response_code, response_text, authorization_type, transaction_id, sent, received, time, session_id) values ('', '" . $_SESSION['customer_id'] . "', '" . $new_order_id . "', '" . $db_response_code . "', '" . $db_response_text . "', '" . $db_authorization_type . "', '" . $db_transaction_id . "', '" . $reportable_submit_data_text . "', '" . $response_list . "', '" . $order_time . "', '" . $db_session_id . "')");
    Use at your own risk :)
    What if someone uses a double quote in their account info?

    Is there a way to add the double quote character to the list of escaped characters in the mini fix above?

    Many thanks

  8. #8
    Join Date
    May 2006
    Posts
    13
    Plugin Contributions
    0

    Default Re: [Done 1.3.8] Apostrophes in any order data w/ authorize.net database logging on

    Quote Originally Posted by DogTags View Post
    What if someone uses a double quote in their account info?

    Is there a way to add the double quote character to the list of escaped characters in the mini fix above?

    Many thanks
    I wouldn't have thought double quotes (") would cause a problem, so without knowing what the problem is I'm not sure what you would want to replace them with. But you could certainly add a second str_replace line to do additional replacements...

  9. #9
    Join Date
    Nov 2003
    Posts
    1,155
    Plugin Contributions
    0

    Default Re: [Done 1.3.8] Apostrophes in any order data w/ authorize.net database logging on

    I'd want to just strip the double quotes (and other unallowed characters) totally

  10. #10
    Join Date
    May 2006
    Posts
    13
    Plugin Contributions
    0

    Default Re: [Done 1.3.8] Apostrophes in any order data w/ authorize.net database logging on

    Well I don't think anything other than apostrophes (') are "unallowed" in the database SQL that gets used. (It's possible I'm wrong).

    However if you really want to strip out double quotes you can probably just add another str_replace line along these lines:

    $reportable_submit_data_text = str_replace("\"", "", $reportable_submit_data_text);

    I'm not sure whether that will have unintended consequences though so you'd have to test well.

 

 

Similar Threads

  1. Not passing data to Authorize.net?
    By mel150 in forum Built-in Shipping and Payment Modules
    Replies: 5
    Last Post: 7 Dec 2010, 08:23 PM
  2. Replies: 3
    Last Post: 15 Sep 2010, 12:26 AM
  3. Authorize.Net error logging
    By blackc2004 in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 19 Jun 2008, 07:01 PM
  4. [Done v1.3.8] Authorize.net Bug in 1.37?
    By phnord in forum Bug Reports
    Replies: 4
    Last Post: 17 Aug 2007, 05:40 AM
  5. Authorize.Net AIM Logging
    By Butta in forum Addon Payment Modules
    Replies: 4
    Last Post: 5 Sep 2006, 07:11 PM

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