Thread: Check Code

Results 1 to 4 of 4
  1. #1
    Join Date
    May 2008
    Posts
    442
    Plugin Contributions
    1

    Default Check Code

    I'm getting the following error in the debug logs:

    PHP Code:
    [19-Jan-2016 10:59:49 America/New_YorkPHP Fatal error:  1064:You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near ''A=0                 
                 ORDER BY products_name asc
    ' at line 8 :: SELECT * 
                   FROM products p, 
                        products_to_categories t1, 
                        products_description t2  
                  WHERE p.products_id = t1.products_id
                    AND t1.products_id = t2.products_id
                    AND p.products_status = 1
                    AND t1.categories_id = 22'
    A=0                 
                 ORDER BY products_name asc 
    ==> (as called by) /var/www/zencart/includes/modules/pages/quick_order/header_php.php on line 30 <== in /var/www/zencart/includes/classes/db/mysql/query_factory.php on line 155 
    Here is the code from the header file it is referencing:

    PHP Code:
      if (isset($_REQUEST['catid'])){
         
    $_SESSION['navigation']->add_current_page();
           
    $catid zen_sanitize_string($_REQUEST['catid']);
         
    $sql "SELECT * 
                   FROM "
    .TABLE_PRODUCTS." p, ".TABLE_PRODUCTS_TO_CATEGORIES." t1, ".TABLE_PRODUCTS_DESCRIPTION." t2  
                  WHERE p.products_id = t1.products_id
                    AND t1.products_id = t2.products_id
                    AND p.products_status = 1
                    AND t1.categories_id = "
    .$catid "                 
                 ORDER BY products_name asc"
    ;
         
    $rs $db->Execute($sql);
         
    $i=0
    Can anyone see anything wrong with the code above?

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

    Default Re: Check Code

    1. There is no "quick_order" file like that built-in to Zen Cart. So that means this code is from some plugin you've added.

    2. It's using the $_REQUEST superglobal, instead of specifying $_GET or $_POST. In that case it needs to be more aggressive about analyzing the input data.

    3. Since it's expecting an integer value for the lookup, it shouldn't be using only zen_sanitize_string(). It should just be casting it to (int), or at least using zen_

    4. Thus, the problem you're seeing is a result of someone attempting to hack your site by probing for problems using malformed URLs to seek for MySQL blind SQL Injection vulnerabilities. They're trying to close the quotes of your query and add malicious parameters by passing quotes and extra query data in the URL.


    So, I'd stop using that plugin, or at the very least clean up the query data by casting to integer:
    Code:
           $catid = (int)$_REQUEST['catid'];
    or by specifically protecting the query by escaping it according to the database's own internal sanitization rules:
    Code:
           $catid = $db->prepareInput($_REQUEST['catid']);
    Or even better, use both.
    .

    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 2008
    Posts
    442
    Plugin Contributions
    1

    Default Re: Check Code

    Thanks DrByte,

    I changed the code as you suggested, as well as a another small change:

    Code:
      if (isset($_REQUEST['catid'])){
         $_SESSION['navigation']->add_current_page();
         $catid = $db->prepareInput($_REQUEST['catid']);
         $sql = "SELECT * 
                   FROM ".TABLE_PRODUCTS." p, 
                        ".TABLE_PRODUCTS_TO_CATEGORIES." t1, 
                        ".TABLE_PRODUCTS_DESCRIPTION." t2  
                  WHERE p.products_id = t1.products_id
                    AND t1.products_id = t2.products_id
                    AND p.products_status = 1
                    AND t1.categories_id = ". (int)$catid . "                
                 ORDER BY products_name asc";
         $rs = $db->Execute($sql);
         $i=0;

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

    Default Re: Check Code

    Thumbs up for using both. ;)
    .

    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. v154 Code check on a product page?
    By Feznizzle in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 1 Jul 2015, 06:29 PM
  2. Replies: 2
    Last Post: 21 Oct 2012, 09:56 PM
  3. Need code to check if sale is active
    By kwright in forum Setting Up Specials and SaleMaker
    Replies: 2
    Last Post: 23 Nov 2011, 10:54 PM
  4. USPS Check Code
    By Marco B in forum Upgrading to 1.5.x
    Replies: 2
    Last Post: 4 Sep 2011, 05:41 AM
  5. Zip Code Error Check?
    By powrwrap in forum Built-in Shipping and Payment Modules
    Replies: 7
    Last Post: 1 Apr 2011, 12:33 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