Properly Escaping Output in PHP to Prevent XSS Attacks

Поділитися
Вставка
  • Опубліковано 3 жов 2024
  • Want more? Explore the library at www.codecourse...
    Official site
    www.codecourse...
    Twitter
    / teamcodecourse

КОМЕНТАРІ • 41

  • @sujonlondon
    @sujonlondon 7 місяців тому

    That brilliant explanation to the point KP it up

  • @ajomehri
    @ajomehri 9 років тому +1

    Preventing XSS attacks would be a nice title for this vid
    tnx
    keep it up

  • @JLP25
    @JLP25 3 роки тому +1

    nicely explained!

  • @AmrSubZero
    @AmrSubZero 9 років тому +1

    This is really helpful for security!

  • @elmastermaestr
    @elmastermaestr 9 років тому

    A humble suggestion based on this is making a function, like 'goodecho($str)' or 'eecho($str)' like this:
    echo htmlspecialchars($str)
    And use it to make output the same way you would use echo

  • @ArnoldsKtm
    @ArnoldsKtm 9 років тому +2

    Using plain functions. Ahh, so nostalgic!

    • @codecourse
      @codecourse  9 років тому +1

      Arnolds Kļavenieks Absolutely, and there's nothing wrong with a function for helpers like this. You wouldn't want to do something like Helper::escape() or (new Helper)->escape() :)

  • @AimeeKatherine
    @AimeeKatherine 6 років тому

    Great. Thanks!

  • @taulava693
    @taulava693 8 років тому

    thanks!!.. great tut..

  • @HishamHadraoui
    @HishamHadraoui 9 років тому +1

    Thnx for the video alex

    • @codecourse
      @codecourse  9 років тому

      Hicham Hadraoui You're welcome.

  • @ethanlaven
    @ethanlaven 9 років тому +5

    can you please do more PHP Security.

    • @codecourse
      @codecourse  9 років тому

      Blitz Yup!

    • @ethanlaven
      @ethanlaven 9 років тому

      yay! Hey *****, im a big fan of your work and i was wondering do you want to start a project together. im a front-end developer but not realy good at back end, seems though your a back-end / php dev i think we would make an awesome team. thank you for the AWESOME vids and keep up the good work man!!!!

    • @ManMadeToons
      @ManMadeToons 9 років тому

      Blitz I really like your page banner and profile pic logo, can you link me to some of your work; just so I can appreciate it, as I love looking and inspecting quality things so I can learn from them.

    • @ethanlaven
      @ethanlaven 9 років тому

      Thanks! ill think about it :) depends if im busy

    • @ManMadeToons
      @ManMadeToons 9 років тому

      Blitz You'll think about it i.e. you don't want to link me to your work.
      It's fine I respect your privacy

  • @MathiasJoergensen
    @MathiasJoergensen 9 років тому

    There should probably be a minor validation such as:
    if(!function_exists('escape')) {
    // function here
    }
    In case the user has pulled a package in that already has that helper function implemented. :)

    • @codecourse
      @codecourse  9 років тому

      ***** Good point. Didn't want to complicate the video by introducing this, but an excellent point.

  • @eastern815
    @eastern815 6 років тому

    very good man

  • @muthuhari8875
    @muthuhari8875 8 років тому

    thanks

  • @Zalovskii
    @Zalovskii 9 років тому

    nice. can you make such wideo about properly escaping user's input?

    • @codecourse
      @codecourse  9 років тому +1

      Иван Чоботар Sure, that's called 'sanitizing', you do this on input, and 'escape' on output. I'll be adding more security videos, and this is one of them :)

  • @Videocu
    @Videocu 9 років тому

    there is problem with require and include to as rfi ot lfi..

  • @Wiejeben
    @Wiejeben 9 років тому

    I usually create a function called e() instead of escape(), way shorter!

    • @ArnoldsKtm
      @ArnoldsKtm 9 років тому

      Did you actually listen to the video?

    • @codecourse
      @codecourse  9 років тому

      Wiejeben Me too! I mentioned this in the video, since it's shorter and easier to write and has become a pretty standard name for escaping now.

  • @Rodbravo1
    @Rodbravo1 9 років тому

    Please, can you tell me what is the difference between "htmlspecialchars" and "htmlentities"? From what I understand, both functions return the same results.

    • @yosoX
      @yosoX 9 років тому +1

      Rodrigo Bravo htmlspecialchars only converts characters into html entities, that are used by html, htmlentities converts every character into the corresponding html entitiy (for example, htmlentities converts © to © but htmlspecialchars does not).

  • @yattsu8660
    @yattsu8660 9 років тому

    What text editor do you use?

  • @firepants20
    @firepants20 9 років тому

    What would I do if my user was to use a CMS that allows for adding underlie, bold, font size, ect code. Like a forum does. How would I make sure no scripting is sent through?

    • @yosoX
      @yosoX 9 років тому

      Firepants20 look up BBCode. it's a simple markup language that uses [] instead of , but other than that it's similar to html. You just need to parse them before outputting

    • @firepants20
      @firepants20 9 років тому

      yosoAMW Ah yes! I completely forgot about BBCode

    • @MathiasJoergensen
      @MathiasJoergensen 9 років тому +1

      Firepants20 Or you can pass the input through a Markdown parser such as: parsedown.org/

    • @codecourse
      @codecourse  9 років тому

      Firepants20 Use Markdown :)

  • @CristianAlexandruRadu
    @CristianAlexandruRadu 9 років тому

    Alex, what's the difference between htmlspecialchars() and htmlentities()?

    • @ArnoldsKtm
      @ArnoldsKtm 9 років тому

      There are tons of answers for this in stack overflow. Just use Google. You're a programmer or what?

    • @Peshyy
      @Peshyy 9 років тому

      Edit: You can see at 4:17 when he opens the PHP article there is some information in the first paragraph :)
      Cristi Alexandru htmlspecialchars only converts characters into html entities, that are used by html, htmlentities converts every character into the corresponding html entitiy (for example, htmlentities converts © to © but htmlspecialchars does not).
      - came from ua-cam.com/video/GPAO5yiCbNk/v-deo.html&lc=z13oglk4wuyyipwye04cfpxqjqauzd3igws0k give him a thumbs up :)

    • @codecourse
      @codecourse  9 років тому +1

      Cristi Alexandru Hi Cristi, htmlentities is pretty much the same, but converts more entities. This isn't needed on the security side, so you can use htmlspecialchars to only convert the required entities. No point converting more than you need (unless you actually need to)!

  • @ManMadeToons
    @ManMadeToons 9 років тому

    Woah, I never thought of XSS coming from an output, but it's so obvious, just a little misguided thought.