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

fix(ext/kv): don't request permissions for ":memory:" #18346

Merged
merged 1 commit into from
Mar 22, 2023

Conversation

nayeemrmn
Copy link
Collaborator

Currently Deno.openKv(":memory:") requests read+write permissions for ./:memory: even though no file is read or written. Also added some guards for special sqlite paths that were unintentionally opted into.

Comment on lines +119 to +121
if path.is_empty() {
return Err(type_error("Filename cannot be empty"));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.sqlite.org/c3ref/open.html

If the filename is an empty string, then a private, temporary on-disk database will be created. This private database will be automatically deleted as soon as the database connection is closed.

Comment on lines +122 to +126
if path.starts_with(':') {
return Err(type_error(
"Filename cannot start with ':' unless prefixed with './'",
));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.sqlite.org/c3ref/open.html

Future versions of SQLite might make use of additional special filenames that begin with the ":" character. It is recommended that when a database filename actually does begin with a ":" character you should prefix the filename with a pathname such as "./" to avoid ambiguity.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filename cannot start with ':' unless prefixed with './' may not be applicable to Windows though. Except for drive letters, : is completely out of league.

let path = Path::new(path);
{
let mut state = state.borrow_mut();
let permissions = state.borrow_mut::<P>();
permissions.check_read(path, "Deno.openKv")?;
permissions.check_write(path, "Deno.openKv")?;
}
rusqlite::Connection::open(path)?
let flags = OpenFlags::default().difference(OpenFlags::SQLITE_OPEN_URI);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled URI paths

Copy link
Member

@losfair losfair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ry ry merged commit 5804d74 into denoland:main Mar 22, 2023
@nayeemrmn nayeemrmn deleted the kv-memory-permissions branch March 22, 2023 19:23
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.

4 participants