Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:lock: Use parameterized queries in putStat to prevent SQL injection (#17658)

Qiaochu Hu3071ad22d4a2
diff --git a/kernel/sql/stat.go b/kernel/sql/stat.go
index a1caf3b606..7cec7af6b2 100644
--- a/kernel/sql/stat.go
+++ b/kernel/sql/stat.go
@@ -54,12 +54,12 @@ func setDatabaseVer() {
}
func putStat(tx *sql.Tx, key, value string) (err error) {
- stmt := "DELETE FROM stat WHERE `key` = '" + key + "'"
- if err = execStmtTx(tx, stmt); err != nil {
+ stmt := "DELETE FROM stat WHERE `key` = ?"
+ if err = execStmtTx(tx, stmt, key); err != nil {
return
}
- stmt = "INSERT INTO stat VALUES ('" + key + "', '" + value + "')"
- err = execStmtTx(tx, stmt)
+ stmt = "INSERT INTO stat VALUES (?, ?)"
+ err = execStmtTx(tx, stmt, key, value)
return
}