Post by tmcguire » Sat Nov 17, 2007 1:33 am

I found a mildly annoying bug in the admin > catalog > product panel.

If I create a product and give it the name Bamboo 12" Handle and save it, when I return to edit the product the name get's cut of at the quote. So the title now reads Bamboo 12.

I understand the logic of why you would trim the input but is there anyway to work around it without compromising security?

New member

Posts

Joined
Mon Nov 12, 2007 3:56 am
Location - Across from the Kitchen

Post by bruce » Sat Jun 07, 2008 5:59 am

Its a bug.

This and other problems occur when the value of  html page elements are set programmatically and that value contains html markup. In the case of text input fields, quotes as well. You need to change the template code to something like the following where ever you want to protect your pages from this. The htmlentities function performs the magic required.

Code: Select all

<input name="name[<?php echo $product['language_id']; ?>]" value="<?php echo htmlentities($product['name'], ENT_QUOTES); ?>" />

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by barns101 » Mon Jun 09, 2008 11:02 pm

Wouldn't it be better to simply encode the details before inserting them into the database?  :)

To encode product titles with HTML entitles before inserting them into the database you need to modify /admin/controller/product.php as follows:

Change line 48 from

Code: Select all

$database->query($database->parse($sql, $insert_id, $key, $name[$key], $description[$key]));
to

Code: Select all

$database->query($database->parse($sql, $insert_id, $key, htmlentitles($name[$key], ENT_QUOTES), $description[$key]));
and line 111 from

Code: Select all

$database->query($database->parse($sql, $request->get('product_id'), $key, $value, $description[$key]));
to

Code: Select all

$database->query($database->parse($sql, $request->get('product_id'), $key, htmlentities($value, ENT_QUOTES), $description[$key]));
Last edited by barns101 on Mon Jun 09, 2008 11:28 pm, edited 1 time in total.

Newbie

Posts

Joined
Fri Jun 06, 2008 8:27 pm

Post by bruce » Tue Jun 10, 2008 9:16 am

Not in this case. The problem is not with the data. You can already insert these characters into the database. The problem occurs when the characters become part of the html to be displayed.

As per the example given if you enter the value "Shovel, 6' handle and 16" blade." as the description for a product. The data goes into the database correctly. However, it does not display correctly in an input field.

Your approach presumes that the data will only be used to display on an html page. However, if for example it was sent to a payment gateway or an rss feed, you would not want the html entities replaced with their html codes. The target audience in this case would receive what looked like rubbish.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by barns101 » Tue Jun 10, 2008 7:45 pm

Good point, bruce!

Newbie

Posts

Joined
Fri Jun 06, 2008 8:27 pm
Who is online

Users browsing this forum: No registered users and 6 guests