Kotlin Exposed:如何创建预处理语句或避免 SQL 注入?
Kotlin Exposed: How to create prepared statement or avoid SQL Injection?
我使用 Kotlin Exposed 创建查询。但是当我必须使用从客户端收到的参数时,我遇到了一个问题:
private fun accountInfo(msg: AccountInfoMsg) {
transaction {
val accountInfo = UserAccount.wrapRow(Account.innerJoin(Account_Banned).select {
Account.email.eq(msg.login.toLowerCase()) and (Account.id eq Account_Banned.accountId)
}.single())
}
}
那么如何创建准备好的语句或如何通过可能的 SQL 注入传递参数?
Exposed 在幕后为您做这件事。因为它将这项工作委派给 PreparedStatement
,所以它会为您处理。如果你想检查你的输入,你应该出于商业原因这样做,剩下的留给 Exposed。
编辑:我相信 the source of Statement
在 Exposed 中展示了这一点。委派给 PreparedStatement
是防止 SQL 注入攻击所需的全部。
我使用 Kotlin Exposed 创建查询。但是当我必须使用从客户端收到的参数时,我遇到了一个问题:
private fun accountInfo(msg: AccountInfoMsg) {
transaction {
val accountInfo = UserAccount.wrapRow(Account.innerJoin(Account_Banned).select {
Account.email.eq(msg.login.toLowerCase()) and (Account.id eq Account_Banned.accountId)
}.single())
}
}
那么如何创建准备好的语句或如何通过可能的 SQL 注入传递参数?
Exposed 在幕后为您做这件事。因为它将这项工作委派给 PreparedStatement
,所以它会为您处理。如果你想检查你的输入,你应该出于商业原因这样做,剩下的留给 Exposed。
编辑:我相信 the source of Statement
在 Exposed 中展示了这一点。委派给 PreparedStatement
是防止 SQL 注入攻击所需的全部。