-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Allow to specify SQLite URI filenames to PDO DSN #6610
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
Conversation
d259207
to
b2c6ff5
Compare
As implemented, this allows an open_basedir bypass by prefixing with Though this is actually a pre-existing problem, as one could manually specify SQLITE_OPEN_URI via PDO::SQLITE_ATTR_OPEN_FLAGS. We should probably explicitly filter out SQLITE_OPEN_URI under open_basedir. cc @cmb69 |
Ah no, that's not right. There's no problem right now, as we'd treat the |
6ad929f
to
2f06c40
Compare
2f06c40
to
260a304
Compare
Thank you for review.
I fixed, so it parse filename portion and validate it with |
I pushed an additional test for check the open_basedir part. @cmb69 Do you see any issues with this? |
Hm, would that really work with arbitrary file:// URIs? E.g. when there is %2f in the path component. |
If the filename or query parameter contains $db = new \PDO('sqlite:file:/Users/foo%20bar%2fexample.db');
// => Access to "/Users/foo bar/example.db" $db = new \PDO('sqlite:file:/Users/foo/example.db?mode=%2f');
// => Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1] no such access mode: / in ... But, I find my mistake that the current change on this PullRequest is not considered about |
Yes, but it is also correctly handled by |
I don't think we'll want to parse/decode the URL, as we could easily end up interpreting it differently than sqlite3 will. I think the path of least resistance here it to simply disable the SQLITE_OPEN_URI feature under open_basedir entirely. |
Thank you for your advice. |
This looks good to me. @cmb69 Any further concerns? |
Nope; should be okay. :) |
SQLITE_OPEN_URI introduced in #6610 is available from sqlite version 3.7.7.
SQLite allows to URI filenames to setup database configuration.
https://www.sqlite.org/uri.html
https://www.sqlite.org/c3ref/open.html#urifilenameexamples
With URI filename, we can specify query parameters to setup SQLite configuration, for example
mode=ro
disables write access,nolock=1
disables file locking.In current PHP implementation, we cannot specify URI filenames because of expanding filename process, so this PR resolve it.
Example usage: