Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,489
    Plugin Contributions
    88

    Default Checkout: Comments with htmlspecialchars handling

    I've searched a while and haven't seen a previous report of this issue.

    In a vanilla 1.5.5a Zen Cart with the demo products loaded, add a product to your cart and start the checkout process.

    On the checkout_shipping page, enter the following comments:
    Code:
    Here's some "comments" & other stuff
    Continue to checkout_payment, see that the comments are carried over from the previous page and continue to the checkout_confirmation page.

    See now that your comments are displayed as:
    Code:
    Here's some "comments" & other stuff
    which, unfortunately, is also how those comments get stored to the order in the database.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,489
    Plugin Contributions
    88

    Default Re: Checkout: Comments with htmlspecialchars handling

    That processing is the result of line #49 (ZC 1.5.5a) in /includes/modules/pages/checkout_confirmation/header_php.php
    Code:
    $_SESSION['comments'] = zen_output_string_protected($_POST['comments']);
    The code was changed based on the Trustwave Security Patch. My initial thought is to change that to call zen_clean_html instead, since it's a <script></script> injection that the code's looking to prevent.
    Last edited by lat9; 23 Jul 2016 at 01:05 PM. Reason: Correct grammer

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,489
    Plugin Contributions
    88

    Default Re: Checkout: Comments with htmlspecialchars handling

    If anyone else has run into this issue, here's a teeny script that will turn those &amp; and &quot; items back to their & and " values:
    Code:
    <?php
    require ('includes/application_top.php');
    
    $status_records = $db->Execute (
        "SELECT orders_status_history_id, comments FROM " . TABLE_ORDERS_STATUS_HISTORY . "
          WHERE comments LIKE '%&amp;%'
             OR comments LIKE '%&quot;%'"
    );
    
    while (!$status_records->EOF) {
        $comments = $db->prepare_input (str_replace (array ('&amp;', '&quot;'), array ('&', '"'), $status_records->fields['comments']));
        $db->Execute ("UPDATE " . TABLE_ORDERS_STATUS_HISTORY . " SET comments = '$comments' WHERE orders_status_history_id = " . $status_records->fields['orders_status_history_id'] . " LIMIT 1");
        $status_records->MoveNext ();
    }
    
    echo "Processing completed. " . $status_records->RecordCount () . " records were updated."; 
    
    require ('includes/application_bottom.php');
    Just create a file containing the code above, place the file in the root of your store's file system, run it and then delete the file.

    For example, if you name the file fix_orders_status.php, you'll run it as www.example.com/fix_orders_status.php.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,489
    Plugin Contributions
    88

    Default Re: Checkout: Comments with htmlspecialchars handling

    Quote Originally Posted by lat9 View Post
    That processing is the result of line #49 (ZC 1.5.5a) in /includes/modules/pages/checkout_confirmation/header_php.php
    Code:
    $_SESSION['comments'] = zen_output_string_protected($_POST['comments']);
    The code was changed based on the Trustwave Security Patch. My initial thought is to change that to call zen_clean_html instead, since it's a <script></script> injection that the code's looking to prevent.
    Unfortunately, the zen_clean_html function's "over-achieving", too, since it's stripping all the CR/LF sequences from the comments, rendering:
    Code:
    Here's some "comments" &
    other stuff
    into
    Code:
    Here's some "comments" & other stuff
    Perhaps, it would be appropriate to add another input to the function (present in /includes/functions/functions_general.php) to specify that CR, LF and TAB characters should remain:
    Code:
    function zen_clean_html($clean_it, $extraTags = '', $keep_new_lines = false) {
        if (!is_array($extraTags)) $extraTags = array($extraTags);
    
        // remove any embedded javascript
        $clean_it = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $clean_it);
    
        if (!$keep_new_lines) {
            $clean_it = preg_replace('/\r/', ' ', $clean_it);
            $clean_it = preg_replace('/\t/', ' ', $clean_it);
            $clean_it = preg_replace('/\n/', ' ', $clean_it);
    
            $clean_it= nl2br($clean_it);
    
            // update breaks with a space for text displays in all listings with descriptions
            $clean_it = preg_replace('~(<br ?/?>|</?p>)~', ' ', $clean_it);
        }
    
    // temporary fix more for reviews than anything else
        $clean_it = str_replace('<span class="smallText">', ' ', $clean_it);
        $clean_it = str_replace('</span>', ' ', $clean_it);
    
    // clean general and specific tags:
        $taglist = array('strong','b','u','i','em');
        $taglist = array_merge($taglist, (is_array($extraTags) ? $extraTags : array($extraTags)));
        foreach ($taglist as $tofind) {
          if ($tofind != '') $clean_it = preg_replace("/<[\/\!]*?" . $tofind . "[^<>]*?>/si", ' ', $clean_it);
        }
    
    // remove any double-spaces created by cleanups:
        $clean_it = preg_replace('/[ ]+/', ' ', $clean_it);
    
    // remove other html code to prevent problems on display of text
        $clean_it = strip_tags($clean_it);
        return $clean_it;
      }
    Once that function's been updated, that line in the checkout_confirmation header file would be changed to:
    Code:
    $_SESSION['comments'] = zen_clean_html($_POST['comments'], '', true);

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Checkout: Comments with htmlspecialchars handling

    What if we just run strip_tags() on it? ... since that removes all html chars, but doesn't mess with line-breaks.
    .

    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
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,489
    Plugin Contributions
    88

    Default Re: Checkout: Comments with htmlspecialchars handling

    That was my first thought, but I was unsure if the zen_clean_html function didn't "do more".

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Checkout: Comments with htmlspecialchars handling

    It seems that the zen_clean_html is indeed doing more than it needs to. So, if you're regularly running into this, using strip_tags would do it.

    But it's likely that the zen_output_string_protected should not be run against the variable, which gets stored to db, but rather within the template upon output, for display purposes.


    Additionally, it seems this is fine in v160.
    .

    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.

 

 

Similar Threads

  1. v139h Add comments at checkout
    By jgold723 in forum All Other Contributions/Addons
    Replies: 8
    Last Post: 18 Sep 2012, 11:11 PM
  2. Checkout process - error handling
    By Chronikle in forum All Other Contributions/Addons
    Replies: 7
    Last Post: 21 Oct 2011, 08:03 AM
  3. Appending Comments at Checkout
    By akabin in forum General Questions
    Replies: 4
    Last Post: 10 May 2010, 11:06 PM
  4. Appending to Comments at Checkout
    By akabin in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 6 May 2010, 12:22 AM

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