首页 > 解决方案 > Kotlin Exposed:如何创建准备好的语句或避免 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 注入传递参数?

标签: kotlinkotlin-exposed

解决方案


Exposed 在幕后为您做到这一点。因为它将这项工作委托给 a PreparedStatement,所以它会为您处理。如果您想彻底检查您的输入,您应该出于商业原因这样做,而将其余部分留给 Exposed。

编辑:我相信Exposed的来源显示了这一点。Statement在这里,您需要委托来PreparedStatement防止 SQL 注入攻击。


推荐阅读