Forums / Bug Reports / [Done v1.3.8] Apostrophes in product names

[Done v1.3.8] Apostrophes in product names

Locked

Views: 5,117

Results 1 to 12 of 12
This thread is locked. New replies are disabled.
17 Jul 2007, 2:44 PM
#1
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

[Done v1.3.8] Apostrophes in product names

Warning: This bug and associated fixes are pretty in-depth. Not for the faint-of-heart. :flex:

We recently had an authorize.net credit card charge without an accompanying Zen Cart order. I put authorize.net into test mode and recreated the customer's order. When I submitted the order for final processing, I got this nasty SQL 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 'Fun: Ultimate Improv(qty: 1) [Date] => July 17, 2007, 9:20 in:

[insert into authorizenet (id, customer_id,order_id, response_code,
response_text, authorization_type, transaction_id, sent, received, time, 
session_id) values ('', '1', '12451', '1', '(TESTMODE) This transaction has been 
approved.', 'auth_capture', '0', 'Array ( [x_login] => ******* [x_tran_key] => 
******* [x_relay_response] => FALSE [x_delim_data] => TRUE [x_version] 
=> 3.1 [x_type] => AUTH_CAPTURE [x_method] => CC [x_amount] => 70.00 
[x_card_num] => *******0015 [x_exp_date] => 0110 [x_card_code] => 
******* [x_email_customer] => FALSE [x_email_merchant] => TRUE 
[x_cust_id] => 1 [x_invoice_num] => TEST-12451 [x_first_name] => Frank 
[x_last_name] => Smith [x_company] => Personal [x_address] => 123 My 
Street [x_city] => Town [x_state] => New Jersey [x_zip] => 00000 [x_country] 
=> United States [x_phone] => 111-222-3333 [x_email] => 
[email protected] [x_ship_to_first_name] => Frank [x_ship_to_last_name] 
=> Smith [x_ship_to_address] => 123 My Street [x_ship_to_city] => Town 
[x_ship_to_state] => New Jersey [x_ship_to_zip] => 00000 [x_ship_to_country] 
=> United States [x_description] => Bucket O' Fun: Ultimate Improv(qty: 1) 
[Date] => July 17, 2007, 9:20 am [IP] => 68.37.226.107 [Session] => 
REMOVED [x_test_request] => TRUE [url] => 
https://secure.authorize.net/gateway/transact.dll ) ', 'REMOVED', 'July 17, 2007, 
9:20 am', 'REMOVED')]

In case the issue is not jumping out at you, the problem rests with the value in the [x_description] key, namely that apostrophe in "Bucket O' Fun."

I backtracked this value to see how and where it's created, ultimately ending up in the catalog's order class and the value placed in $order->products[$i]['name']. However, everywhere I looked this value was coming directly from the DB, so it should already have been clean.

So I went further, and looked directly at the DB entry for this product. I drew up a small script that I then ran in my admin:

$apos_check = $db->Execute("select * from products_description where products_id = 349");
echo 'Name is: ' . $apos_check->fields['products_name'] . '<br/>--END';
exit;

Note that I am not doing any scrubbing of the value. I am also not using $db->bindVars(), so nothing is being scrubbed by the $db class directly. Here's the output:

Name is: Bucket O' Fun: Ultimate Improv
--END

It appears that there's absolutely no initial scrub-in for the product name. This means that the admin pages where products are edited/created are at least not prepping the input of the product name. Off to the Admin!

This product uses the Zen Cart default product type, so I didn't make the mess (good news), but everyone else is vulnerable too (bad news). I went through the entire process of creating and editing a product, and found that the product name is not being correctly scrubbed in.

Here's the offending line, 117 in admin/includes/modules/update_product.php:

$sql_data_array = array('products_name' => zen_db_prepare_input($_POST['products_name'][$language_id]),

Looks okay, right? Unfortunately, zen_db_prepare_input() does not actually prep input for safe database inserts, it only cleans it up. For proper inserts, you also need to use zen_db_input(). Here's those two functions for reference:

  function zen_db_input($string) {
    return addslashes($string);
  }

  function zen_db_prepare_input($string) {
    if (is_string($string)) {
      return trim(stripslashes($string));
    } elseif (is_array($string)) {
      reset($string);
      while (list($key, $value) = each($string)) {
        $string[$key] = zen_db_prepare_input($value);
      }
      return $string;
    } else {
      return $string;
    }
  }

addslashes() is only present in zen_db_input().

I could simply add zen_db_input here, however given the number of places that a product name is called, there's no guarantee that they all properly scrub the name out, meaning it could display with slashes. It could even create the compound slash effect, where slashes are added to slash out existing slashes.

So, for the time being at least, I decided to nip this problem at the final source of contention. I opened includes/modules/payment/authorizenet_aim.php and found line 305:

$description .= $order->products[$i]['name'] . '(qty: ' . $order->products[$i]['qty'] . ') + ';

...and edited to appear as follows:

$description .= [B]addslashes(stripslashes([/B]$order->products[$i]['name'][B]))[/B] . '(qty: ' . $order->products[$i]['qty'] . ') + ';

The stripslashes() call ensures that we don't get compounding slashes as described above.

I actually believe that, even if the source of the problem is fixed, this correction should stay in place, since it's a reasonable failsafe without any negative consequences.

Frank Koehl
"Cleverly Disguised as a Responsible Adult"

frankkoehl.com

17 Jul 2007, 3:01 PM
#2
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,684
Plugin Contributions:
0

Re: [Done v1.3.8] Apostrophes in product names

Thanks Frank!

Please do not PM for support issues: a private solution doesn't benefit the community.

Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

17 Jul 2007, 9:30 PM
#3
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: [Done v1.3.8] Apostrophes in product names

Nice catch :thumbsup:

Some notes though:

I think the $sql_data_array is being fed to the database using zen_db_perform() in admin/includes/modules/update_product.php And I am quite sure zen_db_perform() uses the zen_db_input() function. If not an error would show when entering products with apostrophes in the admin.

Also it's logical that the added slashes won't show after:

$apos_check = $db->Execute("select * from products_description where products_id = 349");
echo 'Name is: ' . $apos_check->fields['products_name'] . '<br/>--END';
exit;
```because the slashes are not (and should not) be added to the database. But it's very possible I just don't understand what you were trying to do here.

hth
17 Jul 2007, 10:02 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: [Done v1.3.8] Apostrophes in product names

In terms of authorize.net ... While the addslashes(stripslashes()) approach may suffice, there are some other characters to protect against as well ... namely & and & etc.

I had been contemplating using this instead:```
'x_description' => str_replace(array('"',"'",'&','&'), '', $description),

While missing those in product names etc might be a little less friendly in appearance, it's probably the safest.

The entire string being submitted is then url_encoded already ... so any other characters shouldn't be an issue. The only one I was contemplating bothering about would be %

Probably should do the str_replace on the entire string though ... because customer and company name/address info could contain similarly unacceptable characters, which might cause similar problems.


The updated module posted here should help work around these issues, as it does the data-type conversion before writing to the database now:  <http://www.zen-cart.com/forum/showthread.php?p=354897#post354897>

.
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.

18 Jul 2007, 4:41 AM
#5
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: [Done v1.3.8] Apostrophes in product names

DrByte:

which just removes any " or ' or & or & While missing those in product names etc might be a little less friendly in appearance, it's probably the safest.

Not discounting the security issue discussed above, from a merchants perspective I am not fully comprehending the "customer service" implications resulting from ZC no longer supporting an apostrophe or ampersand in a product name.

I support a ZC shop with a number of book titles containing an apostrophe, and the apostrophe is VERY significant. If the apostrophe cannot be included in the title (ZC product name) this may become troubling. Not supporting ampersands would be less of an issue, but still an issue.

We have done much work in obtaining quality positioning/indexing for our book products on Google and elsewhere. In this regards I suspect no longer supporting apostrophes could be a step back.

For instance if ZC search index and search engines index the ZC product page with "Rons Whitehouse" product name (sample title), then those searching on the real product name "Ron's Whitehouse" would no longer observe high quality search results.

Maybe there are some specific SEO recommends (besides metatags) which I could employ in ZC (or elsewhere) to help offset the negative impacts of ZC no longer supporting apostrophes in ZC product names?

I am only referring here to the 'customer service' perspective of suggested changes, not to the technical/security merits of such porposed changes.

So how do other e-commerce applications support apostrophe's in product names...securely? Or do they?

Woody

18 Jul 2007, 7:35 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: [Done v1.3.8] Apostrophes in product names

Woodymon:

I am not fully comprehending the "customer service" implications resulting from ZC no longer supporting an apostrophe or ampersand in a product name.Missing your coffee this morning, Woody? True -- You're clearly "not fully comprehending" something.

Please go and re-read not only the context, but also what was said ... specifically the first line of my post that refers to the fact that I was talking entirely about sanitizing the data sent to authorize.net so that the transmission doesn't result in errors due to the use of reserved characters, etc, as well as for inserting response data into Zen Cart debug logging tables. It has nothing to do with security or with dropping support of quotes or ampersands.

Or ... maybe you'd be happier if we didn't even bother sending product details to the customer on receipts.

If you have something constructive to add with respect to a technical solution (this is a thread referring to a possible code bug after all), feel free to add it. Otherwise pay more attention to context before misquoting and getting your shirt in a knot and jumping to conclusions as you often do.

.
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.

19 Jul 2007, 9:04 AM
#7
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: [Done v1.3.8] Apostrophes in product names

DrByte:

Missing your coffee this morning, Woody?

Missing the Diet Pepsi for sure.

Apologies, as I completely missed your initial reference: "In terms of authorize.net ... ". I read your post as this would be a global change. Now I understand and appreciate the explanation.

However there was ABSOLUTELY no need for you to rake me over the coals for my missing that point. As you have never done such? I certainly appreciate your feedback but I also think I deserve an apology.

Woody

19 Jul 2007, 10:31 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: [Done v1.3.8] Apostrophes in product names

Fair enough - apology extended.

:bangin:
I should have simply said "You missed the point".

.
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.

19 Jul 2007, 10:37 AM
#9
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: [Done v1.3.8] Apostrophes in product names

DrByte:

I should have simply said "You missed the point".:laugh:

I was just about to post a defense for your reaction DrByte (which I thought was completey understandable). But you are right, simply "You missed the point" would indeed have been a much better reply after all :-)

15 Oct 2007, 3:07 PM
#10
alext avatar

alext

New Zenner

Join Date:
May 2007
Location:
Perth, Australia
Posts:
54
Plugin Contributions:
0

Re: [Done v1.3.8] Apostrophes in product names

I am not sure if the suggested fix also works on customer's email addresses, but a single quote in a email address generates similar SQL 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 '[email protected]'' at line 1 in:
[select customers_email_format from zen_customers where customers_email_address= 'xxxxxxx.o'[email protected]']
If you were entering information, press the BACK button in your browser and re-check the information you had entered to be sure you left no blank fields.

This happens when trying to update an order with notify customer box ticked. ZC 1.3.7

Learning the hard way -
Matryoshka Dolls

17 Dec 2007, 5:23 PM
#11
joeob avatar

joeob

New Zenner

Join Date:
Nov 2007
Posts:
1
Plugin Contributions:
0

Re: [Done v1.3.8] Apostrophes in product names

Frank,

Joe O'Brien here. Is it possible that other characters are also causing the same issue? We had a credit card approved only to have the order be dropped. On the AuthNet report, the order had two items. The first one looks ok. The second item had a * symbol and a # symbol. Thanks.

18 Dec 2007, 1:57 AM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: [Done v1.3.8] Apostrophes in product names

Certain characters/symbols are stripped out of the data sent to Authorize.net, to protect against transmission errors. Some are considered invalid as part of transaction submission.

&   |  *  "  '  &  =  

NOTE: Latest version for v1.3.7.x posted here: http://www.zen-cart.com/forum/showthread.php?p=441023#post441023

Or, better yet, upgrade to v1.3.8a or newer for even more improvements.

.
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.