Forums / Bug Reports / [Done 1.3.7.1] Cross-Site Scripting in 1.3.7

[Done 1.3.7.1] Cross-Site Scripting in 1.3.7

Locked

Started by avansant on 18 Apr 2007, 4:23 PM · Views: 2,156

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
18 Apr 2007, 4:23 PM
#1
avansant avatar

avansant

Zen Follower

Join Date:
Aug 2004
Posts:
122
Plugin Contributions:
0

[Done 1.3.7.1] Cross-Site Scripting in 1.3.7

One of my clients has the latest zen but failed hackersafe's test regarding Cross-Site Scripting. On a few of her pages she has a text box for an attribute (customize your custom painted sign)
and apparently that is failing. They say we have to filter out the usual suspects (<>) etc.

Can anyone provide a easy way to do this for text attributes so she can get her official "please come and hack me, I dare you" symbol?

20 Apr 2007, 3:59 PM
#2
rmullaney77 avatar

rmullaney77

New Zenner

Join Date:
Mar 2007
Location:
Lakeland, FL, US
Posts:
44
Plugin Contributions:
1

Re: [Done 1.3.7.1] Cross-Site Scripting in 1.3.7

One solution would be to pass every field's value through htmlentities on before handling the form data.

This is an untested example. I just wrote if off the top of my head.

foreach ($_POST as $key => $val) {
    if (is_array($val)) {
        foreach($val as $sub_key => $sub_val) {
            $_POST[$key][$sub_key] = htmlentities($sub_val, ENT_QUOTES);
        }
    } else {
        $_POST[$key] = htmlentities($val, ENT_QUOTES);
    }
}
21 Apr 2007, 6:37 PM
#3
theoracle avatar

theoracle

Suspended

Join Date:
Aug 2004
Posts:
3,180
Plugin Contributions:
1

Re: [Done 1.3.7.1] Cross-Site Scripting in 1.3.7

The example above is still a great one. However, to make sure you wish to remain between a-z and 0-9 characters, you could always replace the above with this one:

foreach ($_POST as $key => $val) {
  if (preg_match("/[a-z0-9\-\_\s]/i", $val)) {
    if (is_array($val)) {
        foreach($val as $sub_key => $sub_val) {
            $_POST[$key][$sub_key] = htmlentities($sub_val, ENT_QUOTES);
        }
    } else {
        $_POST[$key] = htmlentities($val, ENT_QUOTES);
    }
  } else {
  $messageStack->add('your_page_name_here', YOUR_TEXT_DEFINITION_NAME_HERE');
  }

:wink2:

24 Apr 2007, 12:21 PM
#4
avansant avatar

avansant

Zen Follower

Join Date:
Aug 2004
Posts:
122
Plugin Contributions:
0

Re: [Done 1.3.7.1] Cross-Site Scripting in 1.3.7

My programmer did the fix for me - added four lines to

index.php (in the main directory)

that seems to have done the trick:

HackerSafe hack - Removes "WebApp Cross Site Scripting - 2" vulnerability

foreach($_POST as $var => $val) {
$_POST[$var]=preg_replace("/</",".", $val);
$_POST[$var]=preg_replace("/>/",".", $val);
}

hope that helps someone!

A

24 Apr 2007, 6:50 PM
#5
theoracle avatar

theoracle

Suspended

Join Date:
Aug 2004
Posts:
3,180
Plugin Contributions:
1

Re: [Done 1.3.7.1] Cross-Site Scripting in 1.3.7

This could be done with:

$_POST[$var]=str_replace("<",".", $val);
$_POST[$var]=str_replace(">",".", $val);

instead of preg_replace. :wink2:

24 Apr 2007, 8:55 PM
#6
drbyte avatar

drbyte

Sensei

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

Re: [Done 1.3.7.1] Cross-Site Scripting in 1.3.7

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