Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectByIds function sql injection #862

Open
sybb0743 opened this issue Jul 20, 2022 · 3 comments
Open

selectByIds function sql injection #862

sybb0743 opened this issue Jul 20, 2022 · 3 comments

Comments

@sybb0743
Copy link

Write the following test demo:
1、UserController.java:
@controller
public class UserController {

@Autowired
UserService userService;

@RequestMapping("gets")
@ResponseBody
public List<User> getUser(String ids) {
    List<String> idList = Arrays.asList(ids.split(","));

    return userService.gets(idList);
}

}
2、UserService.java:
@service
public interface UserService {

List<User> gets(Collection<String> ids);

}
3、UserServiceImpl.java:
@service
public class UserServiceImpl implements UserService {

@Autowired
UserMapper userMapper;

@Override
public List<User> gets(Collection<String> ids) {
    if (ids == null || ids.isEmpty())
        return new ArrayList<>();
    String concatIds = StringUtils.concat(ids, "'", ",");
    return (List<User>) userMapper.selectByIds(concatIds);
}

}
4、UserMapper.java:
@org.apache.ibatis.annotations.Mapper
public interface UserMapper extends Mapper, MySqlMapper, IdsMapper {

}
5、Access the /gets route in the above demo for sql injection attack:
(1)Under normal circumstances, when the ids parameter value is passed in 1, 2, the data with id 1 and 2 can be obtained:
image
(2)But when the ids parameter value is 1') or 1=1-- -, you can get all the data in the database:
image

@abel533
Copy link
Owner

abel533 commented Jul 20, 2022

At the business level, check according to the type of ID.

@sybb0743
Copy link
Author

sybb0743 commented Jul 20, 2022 via email

@abel533
Copy link
Owner

abel533 commented Jul 21, 2022

Guaranteed compatibility. Have a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants