-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
The "previous" exception object can not be escaped #2447
Comments
@gmazzap Thanks for reporting this. I'm a bit in two minds about this (which is, I suspect, also why I implemented it like it currently is). The thing is, constructors for Exceptions can have any arguments. Exception constructors don't have to follow the same argument pattern as commonly used by the PHP native exceptions. So, blindly only checking the first parameter is not the right solution as it presumes use of the PHP native exceptions and/or of exceptions which have the same arguments as the PHP native exceptions for their constructor.... Here's the commit in which the escaping check for exceptions being thrown was added: 90f291c |
Thanks @jrfnl
I would need to look at data to agree with that, because if I stick to my personal experience, static constructors very rarely use all string parameters. When parameters are supposed to be used with Not to mention that, often, named constructors also support a That means:
Summing up the two, the total chance of this rule creating false positives with exceptions using more than one arg is extremely high. That, added to the fact that the use case for this rule is pretty narrow to begin with (basically it helps mitigate a server misconfiguration) makes me think that always escaping all arguments is definitively overkill. I want to ask: do you foresee the possibility of introducing configurations for:
If you agree to have these two configurations, I volunteer to write the code. |
Bug Description
We can only escape strings. Exception constructors accept a third argument "previous" which is an exception object and can not be escaped.
I would expect
EscapeOutputSniff
to only look at the first argument of exception constructors.Minimal Code Snippet
Error Code
All the
throw
statements above emit:WordPress.Security.EscapeOutput.ExceptionNotEscaped
Custom Ruleset
N/A
Environment
Additional Context (optional)
I saw that the
EscapeOutputSniff
class finds the parameter used to construct the exception, then it loops all of them to search for escaping tokens.I think this issue could be solved only looking at the 1st positional parameter or
message
, if named. And so replace usage of:with:
And then check the parameter, if found.
I'm glad to provide a PR that does this (and test), if wanted.
Tested Against
develop
Branch?develop
branch of WordPressCS.The text was updated successfully, but these errors were encountered: