Skip to content

sql 注入问题 #32

Open
Open

Description

@s-chance

UserMapper.xml

<select id="exportUser" resultType="org.springblade.system.excel.UserExcel">
        SELECT id, tenant_id, account, name, real_name, email, phone, birthday, role_id, dept_id, post_id FROM blade_user ${ew.customSqlSegment}
</select>

这段sql中使用 ${} 的方式拼接,是否存在 sql 注入问题?

过去有 issue 已提到过此问题,不过目前未做回复。想了解一下是否已经有其他措施针对此问题进行了处理?

Activity

  1. s-chance commented on Nov 22, 2024

    @s-chance
    Author
  2. s-chance commented on Nov 22, 2024

    @s-chance
    Author

    不过,为了保险起见以及统一编码,是否将 ${} 替换为 #{} 比较好?

  3. cx-suman-roy commented on Dec 9, 2024

    @cx-suman-roy

    is there a fix commit for this SQL injection?

  4. s-chance commented on Dec 11, 2024

    @s-chance
    Author

    is there a fix commit for this SQL injection?

    see this document.

    It seems to use a custom SQL injection filtering class(SqlKeyword.java) to prevent SQL injection.

    If you use code like

    QueryWrapper<User> queryWrapper = org.springblade.core.mp.support.Condition.getQueryWrapper(user, User.class);

    It will call the SqlKeyword.buildCondition(query, qw); to filter out some suspicious keywords.

    Source code snippet of the org.springblade.core.mp.support.Condition.java

    public static <T> QueryWrapper<T> getQueryWrapper(Map<String, Object> query, Map<String, Object> exclude, Class<T> clazz) {
    	exclude.forEach((k, v) -> query.remove(k));
    	QueryWrapper<T> qw = new QueryWrapper<>();
    	qw.setEntity(BeanUtil.newInstance(clazz));
    	SqlKeyword.buildCondition(query, qw);
    	return qw;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions