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

druid 1.2.21升级到1.2.22 报错:sql injection violation, dbType postgresql, druid-version 1.2.22, select alway true condition not allow #5882

Open
litao11046 opened this issue May 4, 2024 · 3 comments

Comments

@litao11046
Copy link

在springboot项目中,使用druid-spring-boot-3-starter组件,将该组件版本从1.2.21升级到1.2.22时,出现报错:sql injection violation, dbType postgresql, druid-version 1.2.22, select alway true condition not allow
配置为:

spring.datasource.druid.filter.wall.config.conditionAndAlwayTrueAllow=truedruid-spring-boot-3-starter

环境信息:
**dbtype: postgresql
**jdk: 21

@lizongbo
Copy link
Collaborator

lizongbo commented May 5, 2024

以前这个配置没有生效,1.2.22修复了bug,如果认为有误伤,发出具体的sql语句来。

@litao11046
Copy link
Author

sql如下:select sds1_0.id,sds1_0.buildIn,sds1_0.config,sds1_0.dsVersion,sds1_0.failDateTime,sds1_0.failLog,sds1_0.insertDateTime,sds1_0.jpa,sds1_0.jpaAutoUpdateTableSchema,sds1_0.jpaManagedClassNames,sds1_0.jpaPackagesToScan,sds1_0.jpaProperties,sds1_0.lastModDateTime,sds1_0.main,sds1_0.name,sds1_0.notes,sds1_0.status,sds1_0.tenant,sds1_0.type,sds1_0.useConnectionPool from tao_datasource sds1_0 where 1=1 order by sds1_0.insertDateTime offset ? rows fetch first ? rows only] [select sds1_0.id,sds1_0.buildIn,sds1_0.config,sds1_0.dsVersion,sds1_0.failDateTime,sds1_0.failLog,sds1_0.insertDateTime,sds1_0.jpa,sds1_0.jpaAutoUpdateTableSchema,sds1_0.jpaManagedClassNames,sds1_0.jpaPackagesToScan,sds1_0.jpaProperties,sds1_0.lastModDateTime,sds1_0.main,sds1_0.name,sds1_0.notes,sds1_0.status,sds1_0.tenant,sds1_0.type,sds1_0.useConnectionPool from tao_datasource sds1_0 where 1=1 order by sds1_0.insertDateTime offset ? rows fetch first ? rows only

@ice2shell
Copy link
Contributor

这个我想应该和com.alibaba.druid.wall.WallProvider#checkInternal函数中 endOfComment 这个变量赋值改变有关系。
#5698 中将 endOfComment 从 parser.getLexer().isEndOfComment() 改为了 parser.getLexer().isEOF() 。如果 SQL 结尾带注释,这两个函数返回结果均为true,如果SQL 结尾不带注释,isEOF 返回 true,isEndOfComment会返回false。在这个函数中 endOfComment 接下来会赋值到 WallVisitor ,而在后续的com.alibaba.druid.wall.spi.WallVisitorUtils#checkSelelct 的校验逻辑中是这样使用的:config.isSelectWhereAlwayTrueCheck() && visitor.isSqlEndOfComment() && isSimpleConstExpr(where) 。所以针对 select * from t where 1=1 这类SQL,1.2.22之前的版本由于 visitor.isSqlEndOfComment() 为false,会直接通过;1.2.22版本则会报错。

这里我也有个疑问:conditionAndAlwayTrueAllow 是只用于校验 and 1=1 这类恒真条件吗?因为这个配置只在com.alibaba.druid.wall.spi.WallVisitorUtils#getConditionValue 这里用到了。看起来是用于对部分条件恒真的校验。

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

3 participants