Skip to content

Commit

Permalink
webui: Improved error message when someone tries to modify a standard…
Browse files Browse the repository at this point in the history
… database with SQL

We're still seeing people try to do this occasionally, so this
error message will hopefully guide them in the right direction.
  • Loading branch information
justinclift committed May 3, 2023
1 parent 06c4b7d commit 2454233
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions common/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"
"sort"
"strconv"
"strings"
"time"

sqlite "github.com/gwenn/gosqlite"
Expand Down Expand Up @@ -1606,8 +1607,13 @@ func SQLiteRunQueryDefensive(w http.ResponseWriter, r *http.Request, querySource
var memUsed, memHighWater int64
memUsed, memHighWater, dataRows, err = SQLiteRunQuery(sdb, querySource, query, false, false)
if err != nil {
log.Printf("Error when running query by '%s' for database (%s/%s): '%s'", SanitiseLogString(loggedInUser),
SanitiseLogString(dbOwner), SanitiseLogString(dbName), SanitiseLogString(err.Error()))
e := err.Error()
if strings.HasPrefix(e, "not authorized") {
err = errors.New("SQL that modifies a database can only be used on Live databases")
} else {
log.Printf("Error when running query by '%s' for database (%s/%s): '%s'", SanitiseLogString(loggedInUser),
SanitiseLogString(dbOwner), SanitiseLogString(dbName), SanitiseLogString(e))
}
return SQLiteRecordSet{}, err
}

Expand Down

0 comments on commit 2454233

Please sign in to comment.