【问题标题】:for xss attack prevention do i use prepared statement or callable statement对于 xss 攻击预防,我使用准备好的语句还是可调用的语句
【发布时间】:2014-04-09 11:41:43
【问题描述】:

String getDBUSERByUserIdSql = "{call getDBUSERByUserId(?,?,?,?)}";

    try {
        dbConnection = getDBConnection();
        callableStatement = dbConnection.prepareCall(getDBUSERByUserIdSql);

        callableStatement.setInt(1, 10);
        callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
        callableStatement.registerOutParameter(3, java.sql.Types.VARCHAR);
        callableStatement.registerOutParameter(4, java.sql.Types.DATE);

        // execute getDBUSERByUserId store procedure
        callableStatement.executeUpdate();

准备好的陈述

【问题讨论】:

  • XSS 与 SQL 注入无关;它需要数据库或其驱动程序不提供的完全不同的方法。

标签: java sql oracle jsp


【解决方案1】:

你会使用preparedStatement,虽然这是为了预防 SQLi 而不是 XSS

【讨论】:

    【解决方案2】:

    首先你需要了解preparedStatement和callableStatement的区别,

    PreparedStatement 当您计划多次使用 SQL 语句时使用。 PreparedStatement 接口在运行时接受输入参数。

    CallableStatement 当你想访问数据库存储过程时使用。 CallableStatement 接口也可以接受运行时输入参数。

    为了避免**XSS**,您可能更喜欢大卫所说的preparedStatement。参考here

    希望对你有帮助!!

    【讨论】:

    • XSS 仍然是错误的术语——跨站点脚本通常指的是浏览器中的攻击。您想防止的是 SQL 注入 - 使用 Bind-Variables 可以完全 100% 安全地避免这种情况!
    猜你喜欢
    • 2014-04-04
    • 2012-01-05
    • 2015-09-06
    • 2012-06-19
    • 2011-08-02
    • 1970-01-01
    • 2018-07-05
    相关资源
    最近更新 更多