【问题标题】:Kotlin Exposed: How to create prepared statement or avoid SQL Injection?Kotlin Exposed:如何创建准备好的语句或避免 SQL 注入?
【发布时间】:2018-05-05 02:06:13
【问题描述】:

我使用 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 注入传递参数?

【问题讨论】:

    标签: kotlin kotlin-exposed


    【解决方案1】:

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

    编辑:我相信 Exposed 中的 the source of Statement 显示了这一点。您只需委托PreparedStatement 即可在此处防止 SQL 注入攻击。

    【讨论】:

    • 是的,我检查了105 OR 1=1,在最终查询中看起来像WHERE account.email = '105 or 1=1'
    猜你喜欢
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    • 2014-10-14
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    相关资源
    最近更新 更多