SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Security issue...

    Hi...

    I have a page that uses "id" in GET method. Is this check enough to provide a solid security...

    PHP Code:
     function securityCheck($id)
      {
          if(
    $id != "")
          {
              
    $id = (int) $id;
              if(
    is_numeric($id))
                  return 
    true;
          }
         return 
    false;
      } 
    exit(0);

  2. #2

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is_numeric($id) is enough in this context. However for a more detailed answer you would need to post more of your code.

  3. #3
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I may be wrong as I haven't taken the extra time to double check this, but you are casting the variable to an int with the line:

    Code:
    $id = (int) $id;
    have you tried passing a non-numeric item through $_GET? I don't think this will fail as you are casting it to int. I have to double check though. Give it a whirl, just a thought.

    Brett

  4. #4
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try with this sentence...but u have to rewrite some steps.....
    PHP Code:
    function check_user_class$attr )
    {
       if( !isset(
    $_SESSION["wt"]) || !$_SESSION["wt"]["logged"] ) return false;
        if( 
    $_SESSION["wt"]["class"] == "admin" ) return true;
        if( 
    $attr == "admin" ) return false;
        if( isset(
    $_SESSION["wt"]["access"][$attr]) && $_SESSION["wt"]["access"][$attr] == true ) return true;
        else return 
    false;

    i forgot...this script use sessions!!!
    pozdrav sloveniji iz pule

  5. #5
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    drzoid> well the code is just plain link index.php?page=ecard&pic=12

    and at the beginning of index.php I'm using

    PHP Code:
      if(isset($_GET['pic']))
         if(!
    securityCheck($_GET['pic']))
             goto(
    'index.php'); 
    and that's it....I don't think that other code wil be usefull here.....
    goto is just plain header("Location: $location") function with exit;

    bret>
    it fails....why is that...if I enter a string like pic=sdsds it doesn't redirects.....hm....I'l try some variations...

    update: just removed the type casting part and it works....I did the casting because I read in one article that GET is passing strings even if it consist of numbers...what a dumb advice....

    hyperimage> odzdrav Puli od zagrepčanina u Sloveniji
    exit(0);

  6. #6

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by abstraktmedia
    drzoid> well the code is just plain link index.php?page=ecard&pic=12

    and at the beginning of index.php I'm using

    PHP Code:
     if(isset($_GET['pic']))
        if(!
    securityCheck($_GET['pic']))
            goto(
    'index.php'); 
    and that's it....I don't think that other code wil be usefull here.....
    goto is just plain header("Location: $location") function with exit;[b]
    In this case, this should be sufficient
    PHP Code:
    if (isset($_GET['pic']) && is_numeric($_GET['pic'])==false) goto('index.php'); 

  7. #7
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this one....
    PHP Code:
    if( !check_user_class"admin" ) ) {
        
    Header"Location: index.php" );
        exit;

    calls this one....
    PHP Code:
    function check_user_class$attr 

       if( !isset(
    $_SESSION["wt"]) || !$_SESSION["wt"]["logged"] ) return false
        if( 
    $_SESSION["wt"]["class"] == "admin" ) return true
        if( 
    $attr == "admin" ) return false
        if( isset(
    $_SESSION["wt"]["access"][$attr]) && $_SESSION["wt"]["access"][$attr] == true ) return true
        else return 
    false

    this is just an sample...
    if u have time try it..
    cya
    pozdrav zagrepcanu u sloveniji od decka iz pule u veneciji

  8. #8
    SitePoint Zealot abstraktmedia's Avatar
    Join Date
    Feb 2004
    Location
    Ljubljana
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx guys ...

    I really appriciate your time and help....

    hyperimage> ta ti je dobra...rekli bi vi puljani..ba čoviče..zar ne!?
    exit(0);


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
  •