PHP security

Discussion in 'PHP' started by Karon, Feb 28, 2008.

  1. #1
    What kind of malicious attacks is my web application (PHP) vulnerable
    to? Can someone describe them briefly, and point out what countermeasures you may develope in the code to prevent such attacks?
     
    Karon, Feb 28, 2008 IP
  2. able

    able Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    XSS - use htmlentities() on inputs
    CSRF - don't use get requests/links to perform important actions, include one time tokens in forms
    Session Hijacking - where possible disable query string session handling, ensure the session is tied to user agent/partial ip
    Session fixation - ensure you regenerate session id after succesful login

    I think thats the main 4 for any web app, you can google the names for loads more info.
     
    able, Feb 28, 2008 IP
  3. Karon

    Karon Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks alot :) will look into it :)
     
    Karon, Feb 28, 2008 IP
  4. Karon

    Karon Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    But why should I use htmlentities instead of strip_tags() ?

    and btw im using mysqli_real_escape_string() aswell , is that safe?

    I have heard rumours about a line that removes all SQLInjections known.. Some guy I know got it from astalavista.com but refuses to share it..
     
    Karon, Feb 28, 2008 IP
  5. bpasc95

    bpasc95 Active Member

    Messages:
    196
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    70
    #5
    htmlentities is one step to use. Because XSS can take on more than standard HTML, you will likely need more than that:
    http://ha.ckers.org/xss.html

    You should always validate information from forms. If you are using a database, be sure the data you are getting is what is expected to avoid SQL injection issues.

    -Bing
     
    bpasc95, Feb 28, 2008 IP
  6. Karon

    Karon Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks alot :)
     
    Karon, Feb 28, 2008 IP
  7. able

    able Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    mysqli_real_escape_string() should be fine assuming proper usage.

    All of the examples the url given are thwarted by htmlentites(). strip_tags() alone will let some past. Personally I use both, as it stops the tags showing up even if they don't do anything harmful.
     
    able, Feb 28, 2008 IP
  8. Karon

    Karon Guest

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thank you all for quick and good help :)
     
    Karon, Feb 28, 2008 IP
  9. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #9
    Check some of these links out: http://phpsec.org/library/

    Some of these are really good resources on keeping php applications secure.
     
    jestep, Feb 28, 2008 IP