Kayako logo
Feature Requests Have a feature request for SupportSuite, eSupport and LiveResponse? Post in here.

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  (#1) Old
Jamie Edwards Offline
Operations Manager
 
Jamie Edwards's Avatar
 
Posts: 5,443
Join Date: Jan 2006
Location: United Kingdom
Code -> Automatic POST and GET data sanitization - 16-12-2007, 06:59 PM

I propose a set-it-and-forget-it sanitization technique for POST and GET data.

While not suggesting the exact code, class structure or even use of classes I have used to describe the feature, something along the same lines may be useful.

The idea is best suggested in code:

PHP Code:
<?php

    
require_once("UserDataObject.class.php");

    
// We want to get some post data.
    // Create our UserDataObject and pass it $_POST
    
$postdata = new UserDataObject$_POST );

    
// Get something out of it with the knowledge that it is safe
    
$kbid $postdata->get_var("id");        // Effectivley gets sanitzed $_POST['id']
       
?>
And the contents of UserDataObject.class.php:
PHP Code:
<?php

    
class UserDataObject
    
{
       
        private 
$data;

        
__construct$d )
        {
            
$this->data $d;
        }

        public function 
get_var$key )
        {
            return 
$this->sanitize$this->postdata[$key] );
        }

        private function 
sanitize$data )
        {
            
// data to sanitize here.. remove quotes, add slashes, whatever
        
}

        private 
__set() { }
        private 
__get() { }
       
    }
       
?>


Jamie Edwards (jamie.edwards ]at[ kayako.com)
----------------------------------------------------------------
---

Last edited by Jamie Edwards; 16-12-2007 at 07:02 PM.
   
Reply With Quote
Reply

Tags
>, automatic, code, data, sanitization

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vBulletin Skin developed by: vBStyles.com


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47