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

[Bug] 扩展@combine,同一个key在筛选/数据体中可同时存在,两者非互斥逻辑 #698

Open
jettisonJava opened this issue Apr 1, 2024 · 4 comments
Labels
Document 文档 文档 Enhancement 增强 增强功能、提高性能等 Question 使用问题 使用问题

Comments

@jettisonJava
Copy link
Contributor

APIJSON Version/APIJSON 版本号

6.4.0

Database Type & Version/数据库类型及版本号

达梦8

Environment/环境信息

- JDK/基础库:11.0.16
- OS/系统:windows 10
- DB/达梦8

APIAuto Screenshots/APIAuto 请求与结果完整截屏

已提PR

Current Behavior/问题描述

不应该限制combine内的key只能作为条件。
1.(原有的方式)根据条件combine拼接数据体生成筛选条件,修数据:update Table set b='2' where a='2'
{"Table":{"a":"2","b":"2","@combine":"a"}}
2.(扩展)根据条件combine+数据生成筛选条件,修数据:update Table set a='2',b='2' where a='111'
{"Table":{"a":"2","b":"2","@combine":"a:a=111"}}
可使用table:{"a":"1","@combine":"a:a=3331"}的方式对a=3331的数据修改为a=1。同时兼容旧的combine格式

Expected Behavior/期望结果

update方法应该兼容通过条件参数修改指定内容例如:update table a='1' where a='2',不应该限制combine内的key只能作为条件。

Any additional comments?/其它补充说明?

No response

@TommyLemon
Copy link
Collaborator

感谢建议和提交 PR~

如果只是这种简单的 = > < >= <= 大小比较,可以直接改用:
"a{}":"=2" // 区间范围

"a{}":[2] // a IN(2) // 选项范围

"@combine":"a:a=111" 这种写法虽然能在兼容旧语法的情况下扩展同名 key 的条件,但不好防 SQL 注入,需要完整的复杂解析过程,才知道哪些字符是 key,哪些字符是 value,哪些字符是 比较条件,大中小括号 等,需要慎重考虑必要性和安全性等

@TommyLemon
Copy link
Collaborator

还可以用 SQL 函数或类似 SQL 函数(有括号但没有名称)的复杂条件表达式:
"sex2{}": "(sex)=1"

image

http://apijson.cn/api/?send=false&type=JSON&url=http%3A%2F%2Fapijson.cn%3A8080%2Fput%2FUser&json={%22id%22:82001,%22sex%22:0,%22sex2{}%22:%22(sex)%3D1%22,%22@explain%22:true}

@TommyLemon TommyLemon added Enhancement 增强 增强功能、提高性能等 Question 使用问题 使用问题 Document 文档 文档 labels Apr 5, 2024
@jettisonJava
Copy link
Contributor Author

测试了"sex2{}": "(sex)=1"的表达式,不适用于没有主键数据的更新。
另外pr的代码也测到确实存在sql注入问题。需要后续考虑一下怎么调整.

@TommyLemon
Copy link
Collaborator

强制传主键和以上问题无关,可以这样设置来放宽:
DemoSQLConfig.IS_MUST_HAVE_ID_CONDITION = false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Document 文档 文档 Enhancement 增强 增强功能、提高性能等 Question 使用问题 使用问题
Projects
None yet
Development

No branches or pull requests

2 participants