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

序列化和反序列化能否增加对防御XSS攻击的支持? #964

Closed
XuJincai opened this issue Nov 25, 2022 · 8 comments
Closed

序列化和反序列化能否增加对防御XSS攻击的支持? #964

XuJincai opened this issue Nov 25, 2022 · 8 comments
Labels
enhancement New feature or request fixed
Milestone

Comments

@XuJincai
Copy link

请描述您的需求或者改进建议

序列化和反序列化能否增加对防御XSS攻击的支持?

请描述你建议的实现方案

建议在JSONReader.Feature和JSONWriter.Feature增加防御XSS攻击的配置
转义方法可参考org.springframework.web.util.HtmlUtils类

描述您考虑过的替代方案

对您考虑过的任何替代解决方案或功能的描述。

附加信息

2022-11-25_105609

@XuJincai XuJincai added the enhancement New feature or request label Nov 25, 2022
@wenshao wenshao added this to the 2.0.21 milestone Nov 25, 2022
@wenshao wenshao added the fixed label Nov 30, 2022
@wenshao
Copy link
Member

wenshao commented Nov 30, 2022

已经补上类似FASTJSON 1.x SerializeFeature.BrowserSecure一样的功能,用法同样了类似:

Model model = new Model();
model.name = "<>";
String str = JSON.toJSONString(model, JSONWriter.Feature.BrowserSecure);
assertEquals("{\"name\":\"\\u003c\\u003e\"}", str);

 public static class Model {
        public String name;
}

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.21-SNAPSHOT/
请帮用快照版本验证

@XuJincai
Copy link
Author

XuJincai commented Dec 1, 2022

好像跟我的期望有出入

  • 前端给后端传数据
    image
    我是想在上面配置里加上配置
    image
    发送json请求后
    image
    这里接收到的数据是转义后的数据
    image

  • 后端返回给前端数据
    image
    这里返回给前端变成正常的数据 {"username":"<script></script>","password":"123456"}

@wenshao
Copy link
Member

wenshao commented Dec 2, 2022

通过\uXXXX转义也是安全的

@XuJincai
Copy link
Author

XuJincai commented Dec 5, 2022

image
JSONReader.Feature中好像没有相关配置

@wenshao
Copy link
Member

wenshao commented Dec 10, 2022

Reader不需要做额外配置吧

@wenshao
Copy link
Member

wenshao commented Dec 10, 2022

@wenshao wenshao closed this as completed Dec 10, 2022
@XuJincai
Copy link
Author

XuJincai commented Dec 12, 2022

Reader不需要做额外配置吧

前端给后端传json数据,后端用对象接收,怎么接收转义后的数据?
image

按我的理解,JSONWriter是处理后台给前端的数据,JSONReader是处理前端传给后端的数据,不知道我是否理解错误?

我想要的是前端传给后端,后端接收到的是转义后的数据,然后存入数据库。

@WilliamHWM
Copy link

我前端post的json对象为
{
"password": "test123",
"username": "<script>test666"
}
为什么接收解析完是username 为 test666的,我怎么能接收到& lt; test& gt;666 这样的数据?
JSONReader.Feature应该设置什么

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed
Projects
None yet
Development

No branches or pull requests

3 participants