跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[分享创造] JSON-Threat-Protection: 检测非常规 JSON Payload 的高性能 Rust 库

发表于

GitHub: https://github.com/ADD-SP/json-threat-protection.rs

JSON 是目前 API 交互的常见数据格式,其灵活的特点也方便构造出一些非常规的数据来影响业务服务:

  • 高度嵌套的 JSON 可能会导致栈溢出
  • 巨大的 Object/Array/String 可能会消耗过多的内存。
  • 同一个 Object 里重复的 Key 可能会对一些敏感业务带来风险。

总之,即使是一个合法的 JSON 字符串,也可以精心构造出一些 Payload 来影响业务。

JSON-threat-protection.rs 是一个高性能的 Rust 库来处理不受信任的 JSON 输入并检查上述约束。

典型应用场景是作为部署在流量入口来提前拒绝非常规的请求。

测试覆盖

本项目除了常规的功能测试,还通过了长期的模糊测试( Fuzzing )以确保可以正确处理不受信任的输入。同时最大程度保持了和 serde_json 的行为一致性。

性能

Dataset Size serde_json + Validation json-threat-protection Faster Comment
kernel_stargazers.json 1.2M 12.996 ms 8.8530 ms 1.46x 1000 stargazers JSON information from torvalds/linux
kernel_stargazers_small.json 568K 5.8825 ms 3.7504 ms 1.56x 472 stargazers JSON information from torvalds/linux
kernel_commits.json 4.6M 45.059 ms 29.682 ms 1.51x 1000 commits JSON infomation from torvalds/linux
tokio_issues.json 5.1M 61.935 ms 33.959 ms 1.82x 1000 issues JSON information from tokio-rs/tokio
tokio_forks.json 6.1M 90.984 ms 45.686 ms 1.99x 1000 forks JSON information from tokio-rs/tokio
tokio_workflow_runs.json 15M 221.89 ms 103.65 ms 2.14x 1000 workflow runs JSON information from tokio-rs/tokio

更多细节见 GitHub 。

HackerNews

如果你觉得这个项目不错,欢迎也来 HackerNews 支持一下本项目。

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.