Skip to content

CI4: Replacing xss_clean() #3345

Closed
Closed

Activity

  1. added this to the 4.0.0 milestone on Oct 28, 2021
  2. jekkos commented on Oct 28, 2021

    @jekkos
    Member

    Why escape output if we already filter input? Aren't we doing double work then?

    From experience I know that it's better to only escape the output. The xss filter method did some crazy things on input data breaks certain functionality if you use funky characters #2452

  3. jekkos commented on Oct 28, 2021

    @jekkos
    Member

    Might be one up @andriux1990 's alley?

  4. jekkos commented on Oct 28, 2021

    @jekkos
    Member

    We should release 3.3.6 btw, won't have much time the coming weeks to do it, so if someone can step in and tag the master, that would be great.

  5. objecttothis commented on Oct 28, 2021

    @objecttothis
    MemberAuthor

    Why escape output if we already filter input? Aren't we doing double work then?

    From experience I know that it's better to only escape the output. The xss filter method did some crazy things on input data breaks certain functionality if you use funky characters #2452

    I can tell you from my work trying to eek out every bit of optimization that I could out of the Items CSV import that xss_clean() is an absolute big fat pig (and that's putting it nicely). In my benchmarking, xss_clean() was 90% of that's function's speed! That said, I really am looking forward to ditching it for something more effective and light weight.

    Here is an long-winded, but fun article on why to filter input and escape output. http://terrychay.com/article/php-advent-security-filter-input-escape-output.shtml

    the tl;dr is "layers of security". I can tell you that if we only escape output, but we do no filtering of input then we are asking for SQL injection attacks.

  6. objecttothis commented on Oct 28, 2021

    @objecttothis
    MemberAuthor

    We should release 3.3.6 btw, won't have much time the coming weeks to do it, so if someone can step in and tag the master, that would be great.

    Next Tuesday is when I will be working on OSPOS again... hopefully someone can get to it beforehand.

  7. objecttothis commented on Oct 28, 2021

    @objecttothis
    MemberAuthor

    Might be one up @andriux1990 's alley?

    @andriux1990 if you do want to work on this, just make a branch from my CI 4 upgrade branch and then when we create the PR, we can merge it back into the CI4 upgrade branch.

    @jekkos filtering inputs is pretty straightforward in CI 4. Basically all the $this->request methods have a second parameter of the filter type and the function takes care of it for you. the Request class is what replaces the Input class from CI 3.

    Escaping the output is equally straightforward. You just pass the context (see link above) to the esc() or the setVar()/setData() functions on the view end.

    Testing will show, but I think even using both will be considerably faster than xss_clean().

  8. linked a pull request that will close this issueUpgrade CI to 4.1.3 (Old) #3271on Oct 28, 2021
  9. objecttothis commented on Nov 9, 2021

    @objecttothis
    MemberAuthor

    https://codeigniter4.github.io/userguide/installation/upgrade_views.html examples are showing using esc() which is the built-in escaping mechanism. I'm down to working on the views, so I'm just going to do what CodeIgniter is doing for now and then we can change it later if we want to implement something different.

  10. jekkos commented on Nov 10, 2021

    @jekkos
    Member

    Thanks for all the work here @objecttothis, I'll try to catch up at a later point, have been quite busy moving and settling in the new house the last week.

  11. objecttothis commented on Nov 11, 2021

    @objecttothis
    MemberAuthor

    Thanks for all the work here @objecttothis, I'll try to catch up at a later point, have been quite busy moving and settling in the new house the last week.

    No worries, moving can be a lot. I'm finding that these kinds of framework upgrades can be a little like moving. I really hope that CodeIgniter Foundation keeps their word that future upgrades should be nice and easy because this is anything but.

  12. jekkos commented on Nov 16, 2021

    @jekkos
    Member

    Why escape output if we already filter input? Aren't we doing double work then?
    From experience I know that it's better to only escape the output. The xss filter method did some crazy things on input data breaks certain functionality if you use funky characters #2452

    I can tell you from my work trying to eek out every bit of optimization that I could out of the Items CSV import that xss_clean() is an absolute big fat pig (and that's putting it nicely). In my benchmarking, xss_clean() was 90% of that's function's speed! That said, I really am looking forward to ditching it for something more effective and light weight.

    Here is an long-winded, but fun article on why to filter input and escape output. http://terrychay.com/article/php-advent-security-filter-input-escape-output.shtml

    the tl;dr is "layers of security". I can tell you that if we only escape output, but we do no filtering of input then we are asking for SQL injection attacks.

    Indeed for SQL we need to escape user input, if it's used in a query somehow. But for XSS I would just stick to escaping output only?

  13. changed the title [-]Replacing xss_clean() for CI4[/-] [+]CI4: Replacing xss_clean()[/+] on Apr 1, 2022
  14. self-assigned this
    on Apr 7, 2022
  15. modified the milestones: 4.0.0, 3.4.0 on Apr 7, 2022
  16. objecttothis commented on Apr 12, 2022

    @objecttothis
    MemberAuthor

    For now I've added filters to the input using the 2nd parameter of the request->getGet() and request->getPost() functions as well as escaping outputs using CI4 esc() in the view. Let's test it and make changes when necessary. One thing to note is that in PHP 8.1 FILTER_SANTIZE_STRING is deprecated in favor of htmlspecialchars(), so we may need to alter that in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions