You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CI4 no longer has $this->security->xss_clean(). Best practice dictates that we need to filter input and escape output. Does anyone want to take this part of the CI4 conversion?
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
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.
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.
@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().
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.
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.
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.
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?
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.
Activity
jekkos commentedon Oct 28, 2021
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
jekkos commentedon Oct 28, 2021
Might be one up @andriux1990 's alley?
jekkos commentedon Oct 28, 2021
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.
objecttothis commentedon Oct 28, 2021
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.
objecttothis commentedon Oct 28, 2021
Next Tuesday is when I will be working on OSPOS again... hopefully someone can get to it beforehand.
objecttothis commentedon Oct 28, 2021
@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().
objecttothis commentedon Nov 9, 2021
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.
objecttothis commentedon Nov 9, 2021
Found this today: https://codeigniter.com/user_guide/concepts/security.html
bhojkamal commentedon Nov 10, 2021
good
jekkos commentedon Nov 10, 2021
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.
objecttothis commentedon Nov 11, 2021
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.
jekkos commentedon Nov 16, 2021
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?
[-]Replacing xss_clean() for CI4[/-][+]CI4: Replacing xss_clean()[/+]objecttothis commentedon Apr 12, 2022
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.