-
-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WordPress.Security.EscapeOutput encourages bad practice wrt exceptions #2374
Comments
@anomiex I agree that would be the ideal solution, except WP does not do that. I suggest you open a Trac ticket to get WordPress fixed. I.e. implement callbacks to Once that fix is in place, I'd be very happy to remove sniffing for both those issues which annoy you. Until that time, however, the messages from the sniff are perfectly valid IMO and this bug report is not. |
@jrfnl From what I've seen I'm not terribly confident that a fix to WordPress would be quickly merged, but I'll give it a try on Monday if nothing else comes up. In the mean time, would you at least accept a PR (and then soon release a version 3.0.1 including it) to change this situation from |
🤞🏻
@anomiex Changing the error code would be a breaking change, then again this is a recent addition and there are not that many users on WPCS 3.0 yet. I'd be open to it, but would like to hear the opinions of the other maintainers. |
I am currently working on updating that sniff, so I'd be open to adding this. Although I wouldn't add this in 3.0.1, but 3.1.0 (which I thought my addition would be tagged under, as it contains extra checks, not just bug fixing). |
3.0.1 or 3.1.0 doesn't matter to me, as long as the option will get there soon to unblock our "update to WPCS 3" task without having to add 140 bogus escapings (possibly breaking other code) or 140 @dingo-d If you're going to work on it anyway I'm happy to leave it to you. I was just going to add a |
From a practical point of view, I'd rather have these as separate PRs as I wouldn't want one PR blocking the other from being merged and released. |
Yes, I'll work on the static one first, and then work on this one. |
Or we could take @anomiex up on their offer to submit a PR for this one ? |
This splits certain cases out of `OutputNotEscaped` to allow for ignoring certain cases that are looking at error strings at time of generation (where they may eventually be used in both HTML and non-HTML contexts) rather than at time of output. * `ExceptionNotEscaped` for unescaped strings in throws (cf. WordPress#2374). * `ErrorNotEscaped` for unescaped strings in `trigger_error` (cf. WordPress#1864).
Turned out to be slightly more work than I had thought since the code had to be passed through in another function and some recursive calls, but #2378. I went ahead and added a new code for |
Yeah, changing that really would be a bigger breaking change, which I'm not keen on making in a patch/minor version. It was also the reason I didn't add a separate error code for |
Filed https://core.trac.wordpress.org/ticket/59282 and a PR to go with it. Let's see where that goes. |
Closing as fixed via #2378 |
Bug Description
Escaping should normally be done close to the point of output (or at least the point where HTML is being generated). The
WordPress.Security.EscapeOutput
sniff instead encourages escaping at the point where exceptions are generated, without knowing if the exception is going to be caught, or output to a CLI, or logged to a text-based log, etc.Apparently this is because someone was worried about people having
display_errors
on (which is PHP's default) andhtml_errors
off (which is not the default). The sensible thing would have been to have WordPress useset_exception_handler()
to set a default exception handler early in the request, which could easily ensure any output of the exception message to the browser is escaped even on such misconfigured sites and which would also catch errors generated by PHP itself and errors generated by other libraries that don't use WPCS.I note a similar argument could be made for WPCS's insisting on
trigger_error()
having escaping rather than having WordPress useset_error_handler()
. Although in that casehtml_errors
being on doesn't prevent the problem.Minimal Code Snippet
The issue happens when running this command:
... over a file containing this code:
Error Code
WordPress.Security.EscapeOutput.OutputNotEscaped
Custom Ruleset
Use
--standard=WordPress-Extra
Environment
Additional Context (optional)
Tested Against
develop
Branch?develop
branch of WordPressCS.The text was updated successfully, but these errors were encountered: