Skip to content
New issue

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

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

Already on GitHub? # to your account

PostgreSql中JSON类型,防火墙BUG? #1592

Closed
yuanych opened this issue Jan 24, 2017 · 5 comments
Closed

PostgreSql中JSON类型,防火墙BUG? #1592

yuanych opened this issue Jan 24, 2017 · 5 comments
Labels
Milestone

Comments

@yuanych
Copy link

yuanych commented Jan 24, 2017

PostgreSql中使用JSON类型,查询的时候需要对?转义为??,但是会被druid的防火墙拦截掉,求解决方案。
相关操作符参照:
https://www.postgresql.org/docs/9.6/static/functions-json.html
https://jdbc.postgresql.org/documentation/head/statement.html

例如SQL:SELECT count(1) FROM t_user WHERE property ?? 'name'

相关日志:
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT count(1) FROM t_user WHERE property ?? ?]; SQL state [null]; error code [0]; sql injection violation, syntax error: syntax error, error in :'HERE property ?? ?',expect QUES, actual QUES property : SELECT count(1) FROM t_user WHERE property ?? ?; nested exception is java.sql.SQLException: sql injection violation, syntax error: syntax error, error in :'HERE property ?? ?',expect QUES, actual QUES property : SELECT count(1) FROM t_user WHERE property ?? ?

Caused by: java.sql.SQLException: sql injection violation, syntax error: syntax error, error in :'HERE property ?? ?',expect QUES, actual QUES property : SELECT count(1) FROM t_user WHERE property ?? ?
at com.alibaba.druid.wall.WallFilter.check(WallFilter.java:724) ~[druid-1.0.24.jar:1.0.24]
at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:252) ~[druid-1.0.24.jar:1.0.24]
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448) ~[druid-1.0.24.jar:1.0.24]
at com.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:928) ~[druid-1.0.24.jar:1.0.24]
at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:122) ~[druid-1.0.24.jar:1.0.24]
at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448) ~[druid-1.0.24.jar:1.0.24]

@yuanych yuanych changed the title PostgreSql中JSON类型,防火墙BUG PostgreSql中JSON类型,防火墙BUG? Jan 24, 2017
@wenshao wenshao added the Bug label Jan 26, 2017
@wenshao wenshao added this to the 1.0.27 milestone Jan 26, 2017
@wenshao
Copy link
Member

wenshao commented Jan 26, 2017

如下四个操作符号都是支持的

->
->>
#>
#>>

你提供的??这个操作符,文档中没找到

@yuanych
Copy link
Author

yuanych commented Jan 26, 2017

在进行JSON类型查询时,有几个操作符 :
?
?|
?&
参照:https://www.postgresql.org/docs/9.6/static/functions-json.html

但是JDBC的prepareStatement中?是占位符,正好和PostgreSql中的带问号的操作符冲突。如果上面的三个操作符在PostgreSql中使用prepareStatement,就需要进行转义处理,转以后的符号为:?? ??| ??&
这样druid的防火墙就过不去了。
转义的官方说明:
https://jdbc.postgresql.org/documentation/head/statement.html

相关SQL:
Statement: SELECT count(1) FROM t_user WHERE property ? 'name'
PreparedStatement: SELECT count(1) FROM t_user WHERE property ?? ?

wenshao added a commit to wenshao/druid that referenced this issue Jan 26, 2017
@wenshao
Copy link
Member

wenshao commented Jan 27, 2017

问题重现并且解决,将会尽快发布新版本

@yuanych
Copy link
Author

yuanych commented Feb 4, 2017

src/main/java/com/alibaba/druid/sql/parser/Token.java
309行 QUESQUES("??"),

为何第二个问号是中文全角的?

@wenshao wenshao modified the milestones: 1.0.28, 1.0.27 Feb 5, 2017
@wenshao
Copy link
Member

wenshao commented Feb 5, 2017

问题已经修复,全角问题不影响使用,下个版本修复。请使用1.0.28版本

@wenshao wenshao closed this as completed Feb 5, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants