Skip to content
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

[11.x] Fix resource not escaped correctly in substituteBindingsIntoRawSql() #53100

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

aedart
Copy link
Contributor

@aedart aedart commented Oct 10, 2024

I have encountered a small bug, inside Grammar::substituteBindingsIntoRawSql(). When $bindings contain a resource (e.g. file resource), then it is not escaped correctly. Furthermore, in an edge-case, when a resource is already closed, then that too leads to a PHP TypeError being thrown. This PR fixes that issue.

Additional Information

The reason why I came across this, was when using barryvdh/laravel-debugbar to log executed queries. In my situation, a small file (resource) was successfully written to the database, and its resource handler was closed. However, when the debugbar attempted to log the executed query, it failed and yielded the following TypeError:

str_contains(): Argument #1 ($haystack) must be of type string, resource given at [...]Database/Connection.php:1119

I have reviewed the source code of laravel debugbar, but it seems that substituteBindingsIntoRawSql() might be the more appropriate place to fix this issue.

When bindings contain a resource (e.g. file resource), then it is not escaped correctly. Additionally, the gettype() call is to ensure that a closed resource is also escaped correctly. The latter is an edge-case scenario, which can be encountered in situations when a file handler has already been closed, and one attempts to log the executed query, e.g. via using barryvdh/laravel-debugbar.
@taylorotwell taylorotwell merged commit eba8069 into laravel:11.x Oct 10, 2024
33 checks passed
timacdonald pushed a commit to timacdonald/framework that referenced this pull request Oct 15, 2024
When bindings contain a resource (e.g. file resource), then it is not escaped correctly. Additionally, the gettype() call is to ensure that a closed resource is also escaped correctly. The latter is an edge-case scenario, which can be encountered in situations when a file handler has already been closed, and one attempts to log the executed query, e.g. via using barryvdh/laravel-debugbar.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants