Results 1 to 9 of 9

Thread: register_globals security risk?

  1. #1
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default register_globals security risk?

    I was thinking today, and realized that register_globals being set might cause a flaw in some security. Here are some situations... please let me know your thoughts--

    1. Your script has, for example, a log in function. It checks the session variables to see if the user and pass values match what is in the database and then sets $loggedin to 1.
    If register globals was on, could the user not just type ...?loggedin=1 and get around the security, claiming to be logged in?

    2. less of a security risk, but more of a problem-- what if you have a variable... any variable... in your script and the user put ?thatvar=something in the url? wouldn't that cause errors with execution?

    These are really the two examples I can think of, but they are big problems. It seems that just turning off register globals makes the most sense.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Yes indeed register_globals being on is a wide hole of a security risk. Until PHP version 4.2.0, this setting was on by default. The following is a example of exploitable source code

    Code:
    <?php
      // ex1.php
      if (some condition) {
          $loggedin = 1;
      }
      
      if ($loggedin == 1) {
          // allow access to something important
      }
    ?>
    If register_globals is on, a malicious users can pass a parameter, as follows:

    Code:
    www.site.com/ex1.php?loggedin=1.
    Since the variable $loggedin was never initialized, the user gains access where they shouldn't.

    Here's how the code can be secured.

    Code:
    <?php
      // ex2.php
      
      // first initialize the loggedin variable
      $loggedin = 0;
      
      if (some or other condition) {
          $loggedin = 1;
      }
      
      if ($loggedin == 1) {
          // allow access to something important
      }
    ?>
    If register_globals off, the first script would also be immune from that sort of attack. Rather, the variable would only be accessible as $_GET['loggedin'], where it can do much less harm.

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Right. That's what I thought. Interesting.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's safe with a decent coding style. All variables should be initialised before use anyway.

    However, it's just generally ugly to have request variables cluttering up the global namespace.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yeah, that is a pain.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    But i think there are (were) some big applications like osCommerce that works in the assumption that the register globals are on.

    But if it is possible to avoid security risks if it is on better turned it off

  7. #7
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Wouldnt a better form of login use a DB/txt file to store the users that are loged in, and their ips to distinguish the users? then once the login has been inactive for an hour or so, delete it?

    im seeing the flaw in using Get for logins, insead of post which hides the variables.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, but that was just an example. A real situation would probably be a lot more complex than that.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    A useful link that present top 10 PHP and the OWASP Top Ten Security Vulnerabilities

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
  •