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

server: disallow VACUUM in SQL statements #28

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/tailsql/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ func TestCheckQuerySyntax(t *testing.T) {
// Basic disallowed stuff.
{`ATTACH DATABASE "foo" AS bar;`, false},
{`DETACH DATABASE bar;`, false},
{`VACUUM`, false},
{`VACUUM INTO '/dev/null';`, false},

// Things that should not be disallowed despite looking sus.
{`SELECT 'ATTACH DATABASE "foo" AS bar;' FROM hell;`, true},
{`-- attach database not really
select * from a join b using (uid); -- ok `, true},
{`-- vacuum into 'hell'`, true},

// Things that should be disallowed despite being sneaky.
{` -- hide me
Expand Down
5 changes: 3 additions & 2 deletions server/tailsql/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ func errorCode(err error) int {
// A read-only SQLite database will correctly report errors for operations that
// modify the database or its schema if it is opened read-only. However, the
// ATTACH and DETACH verbs modify only the connection, permitting the caller to
// mention any database accessible from the filesystem.
// mention any database accessible from the filesystem. Similarly, VACUUM INTO
// can be run even on a read-only database, so don't allow it in any form.
func checkQuerySyntax(query string) error {
for _, tok := range sqlTokens(query) {
switch tok {
case "ATTACH", "DETACH", "TEMP", "TEMPORARY":
case "ATTACH", "DETACH", "TEMP", "TEMPORARY", "VACUUM":
return fmt.Errorf("statement %q is not allowed", tok)
}
}
Expand Down