Opened 7 years ago
Last modified 7 years ago
#46329 new enhancement
sanitize_text_field after 5.1 update should account for __toString() methods
| Reported by: | fclaussen | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Formatting | Version: | 5.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
Since 5.1 the sanitize_text_field changed to check if the parameter is an object or array.
That broken one of my codes and possibly for other people too because I was passing a SimpleXMLElement Object. It has a magic __toString() method that gets called when you do that type conversion.
As @iCaleb suggested in #41450, we may want to add another check.
<?php if ( ( is_object( $str ) && ! method_exists( $str, '__toString' ) ) || is_array( $str ) ) { return ''; }
Attachments (1)
Change History (2)
#1
@
7 years ago
- Version → 5.1
Thank you for the bug report, @fclaussen!
This is a bit of a tricky problem. sanitize_text_field() usually has user input passed directly to it, which makes it a target for security issues. In particular, an attacker will try to instantiate a class that implements __toString(), but the content of that string isn't intended for the end user.
I'd love to hear more thoughts on whether we can make this check a little less restrictive in a safe manner.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Suggested enhancement to the _sanitize_text_fields function