Forums / Installing on a Linux/Unix Server / AdminRequestSanitizer Error Log

AdminRequestSanitizer Error Log

Views: 82,959

Results 1 to 20 of 78
18 Mar 2016, 7:10 PM
#1
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

AdminRequestSanitizer Error Log

When using edit orders Zen Cart v1.5.4
I'm getting the following error, edit orders does not save properly so not sure is this something edit orders needs to address or is this an issue with the AdminRequestSanitizer.php file?

[18-Mar-2016 09:23:18 America/New_York] PHP Warning: htmlspecialchars() expects parameter 1 to be string, array given in /var/admin/includes/classes/AdminRequestSanitizer.php on line 319

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

18 Mar 2016, 7:25 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: AdminRequestSanitizer Error Log

For capacity reasons the sanitizer could not be tested with all plugins. So, this needs investigation, and probably an update to Edit Orders to address it.
Which feature of Edit Orders were you using to trigger this? It appears to be a problem with something that would have multiple level depths, such as checkboxes or multiple levels of languages within groups.

.
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 Mar 2016, 7:33 PM
#3
drbyte avatar

drbyte

Sensei

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

Re: AdminRequestSanitizer Error Log

In addition to describing which feature of EO you were using, you could also obtain more info about what data needs parsing differently by making a small TEMPORARY code change:

In that Admin Sanitizer class file, insert a new line around line 330, as shown here:```
foreach ($_GET as $key => $value) {
if (!in_array($key, $getToIgnore)) {
if (is_array($value)) {
foreach($value as $key2 => $val2){
[B]if (is_array($val2)) die('Value of ['.$key2.'] found to be array: <pre>' . print_r($value, true));[/B]
$_GET[$key][$key2] = htmlspecialchars($val2);
}
} else {


And then it should dump out to your admin screen the values it's trying to process.

.
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 Mar 2016, 7:34 PM
#4
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

Hello DrByte,

I tried to edit an order using edit orders and the onetime discount mod to show a a refund that I issued to a customer. Once I saved it, the product on the order for whatever reason was deleted and the refund that was entered was not saved. I then tried to add the product that was deleted back and save it and it would not save it just kept generating that error. I had to remove the AdminRequestSanitizer.php and revert back to the original init_sanitize.php file for edit orders to start working again.

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

18 Mar 2016, 7:35 PM
#5
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

Ok will do it now and report back.

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

18 Mar 2016, 7:45 PM
#7
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

Ok DrByte,

I applied your code change, but it did not display anything to me. Something happens when I edited the the order and tried to give a discount using edit orders/onetime discount it says "Success: Order has been successfully updated" however the discount does not save and it removes the product that was purchased on the order leaving only the shipping.

Same error log is generated:

[18-Mar-2016 15:42:36 America/New_York] PHP Warning: htmlspecialchars() expects parameter 1 to be string, array given in /var/admin/includes/classes/AdminRequestSanitizer.php on line 319

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

18 Mar 2016, 7:50 PM
#8
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

wilt just tried your temp solution and it does work.

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

18 Mar 2016, 8:15 PM
#9
drbyte avatar

drbyte

Sensei

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

Re: AdminRequestSanitizer Error Log

marcopolo:

Ok DrByte,

I applied your code change, but it did not display anything to me.
Argh, cuz I gave you the wrong lines :(

At line 319 insert the new line shown:```
foreach ($_POST as $key => $value) {
if (!in_array($key, $postToIgnore)) {
if (is_array($value)) {
foreach($value as $key2 => $val2){
[B]if (is_array($val2)) die('Value of ['.$key2.'] found to be array: <pre>' . print_r($value, true));[/B]
$_POST[$key][$key2] = htmlspecialchars($val2);
}
} else {
$_POST[$key] = htmlspecialchars($value);
}
}
}
foreach ($_GET as $key => $value) {

.
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 Mar 2016, 8:30 PM
#10
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

Below is the output however I do not think it's executing all the way as nothing is saving.

Value of [127213] found to be array:

Array
(
    [127213] => Array
        (
            [qty] => 1
            [name] => Test Item
            [model] => G10
            [tax] => 2
            [final_price] => 12.00
        )

)

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

18 Mar 2016, 8:31 PM
#11
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

also not error logs are being generated.

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

18 Mar 2016, 8:58 PM
#12
drbyte avatar

drbyte

Sensei

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

Re: AdminRequestSanitizer Error Log

marcopolo:

Below is the output however I do not think it's executing all the way as nothing is saving.
Right. It's just to get an idea of what data needs treatment.

Thanks, that info is helpful.
Remove those lines I suggested, as they're just for collecting data. Use wilt's temporary suggestion until a proper fix is determined.

.
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 Mar 2016, 8:59 PM
#13
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

Ok thanks

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

28 Mar 2016, 10:47 PM
#14
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: AdminRequestSanitizer Error Log

Does it make sense just to add a third layer?

        foreach ($_POST as $key => $value) {
            if (!in_array($key, $postToIgnore)) {
                if (is_array($value)) {
                    foreach($value as $key2 => $val2){
                        if (is_array($val2)) {
                           foreach($val2 as $key3 => $val3){
                              $_POST[$key][$key2][$key3] = htmlspecialchars($val3);
                           }
                        } else {
                           $_POST[$key][$key2] = htmlspecialchars($val2);
                        }
                    }
                } else {
                    $_POST[$key] = htmlspecialchars($value);
                }
            }
        }

As far as I can tell this fixes the log.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

28 Mar 2016, 11:03 PM
#15
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: AdminRequestSanitizer Error Log

Edit orders fabricates the order totals in a multilayered structure. It probably does other things like this too.

[noparse]
Array
(
    [0] => Array
        (
            [code] => ot_combination_discounts
            [title] => Combination Discounts :
            [value] => 3.0000
        )

    [1] => Array
        (
            [code] => ot_fuelsurcharge
            [title] => Fuel Surcharge:
            [value] => 8.5753
        )

    [2] => Array
        (
            [code] => ot_shipping
            [shipping_module] => flat
            [title] => Regular Shipping (Basic shipping included):
            [value] => 0.0000
        )

    [3] => Array
        (
            [code] => ot_snqd
            [title] =>
            [value] =>
            [shipping_module] =>
        )

)[/noparse]

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

29 Mar 2016, 3:22 AM
#16
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

A recursive approach could be taken instead of "planning" for depth... Also, it seems that since ZC 1.5.1 the use of htmlspecialchars has been expanded to include other "directives", should those not be added to that code instead of letting things go as defaulted?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

29 Mar 2016, 6:27 PM
#18
drbyte avatar

drbyte

Sensei

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

Re: AdminRequestSanitizer Error Log

Wilt's fix has been merged into the v155 branch on github ... and is now part of core code since the 03-29-2016 zip of v155.

Please run it with Edit Orders. I think the only potential "issue" with it is that it might mangle any HTML in product names when editing one of those in an order.

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

31 Mar 2016, 6:30 AM
#19
cvhainb avatar

cvhainb

Zen Follower

Join Date:
Sep 2008
Posts:
212
Plugin Contributions:
19

Re: AdminRequestSanitizer Error Log

marcopolo:

When using edit orders Zen Cart v1.5.4
I'm getting the following error, edit orders does not save properly so not sure is this something edit orders needs to address or is this an issue with the AdminRequestSanitizer.php file?

[18-Mar-2016 09:23:18 America/New_York] PHP Warning: htmlspecialchars() expects parameter 1 to be string, array given in /var/admin/includes/classes/AdminRequestSanitizer.php on line 319

Add this code on top of edit_order.php

define('DO_STRICT_SANITIZATION', false);

Our Site: http://zucando.com
Marketing Plugins: Marketing Modules
Free Response Templates: Responsive Templates

31 Mar 2016, 6:50 AM
#20
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: AdminRequestSanitizer Error Log

cvhainb:

Add this code on top of edit_order.php

define('DO_STRICT_SANITIZATION', false);


This is a poor coding recommendation at this point especially with an overall fix provided, further it goes against the information provided at the [Developer's Documentation area](http://docs.zen-cart.com/Developer_Documentation/v1.5.5/code_docs/admin_sanitization) specifically on the use of this define.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...