deepflow icon indicating copy to clipboard operation
deepflow copied to clipboard

[FR] 支持对mongo请求的参数脱敏

Open letian0805 opened this issue 3 months ago • 2 comments

Search before asking

  • [x] I had searched in the issues and found no similar feature requirement.

Description

目前mongo请求还不支持脱敏,查询条件里如果带了敏感信息,会被存到 clickhouse 中,存在数据泄露风险。

Use case

No response

Related issues

No response

Are you willing to submit a PR?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

letian0805 avatar Sep 04 '26 03:09 letian0805

Hi! I'd like to work on this issue.

Reading the code, the query condition already reaches us parsed: agent/src/flow_generator/protocol_logs/sql/mongo.rs decodes the payload into a bson::Document and then calls .to_string() on it to fill request_resource. So an obfuscator can walk that document and replace values while keeping field names — no re-parsing and no regex over the serialized string. The obfuscate_enabled_protocols bitmap already accepts "MongoDB" as a config value, so this can follow the same opt-in model as the SQL and HTTP paths, defaulting to off.

Three things I'd like your call on before writing code:

  1. Placeholder for replaced values — ?, as the SQL obfuscator uses, or something else?
  2. Nesting — walk nested documents and arrays recursively, replacing leaf values only?
  3. Query operators ($gt, $in, ...) — leave them as-is, or treat them as ordinary field names?

If the direction is right, I'd add a mongo_obfuscate module alongside sql_obfuscate with unit tests covering the document walker, and wire it at the four places in mongo.rs that serialize a document. Happy to adjust the split if you'd prefer it elsewhere.

insuffer avatar Oct 22 '26 02:10 insuffer

Hi! I'd like to work on this issue.

Reading the code, the query condition already reaches us parsed: agent/src/flow_generator/protocol_logs/sql/mongo.rs decodes the payload into a bson::Document and then calls .to_string() on it to fill request_resource. So an obfuscator can walk that document and replace values while keeping field names — no re-parsing and no regex over the serialized string. The obfuscate_enabled_protocols bitmap already accepts "MongoDB" as a config value, so this can follow the same opt-in model as the SQL and HTTP paths, defaulting to off.

Three things I'd like your call on before writing code:

  1. Placeholder for replaced values — ?, as the SQL obfuscator uses, or something else?
  2. Nesting — walk nested documents and arrays recursively, replacing leaf values only?
  3. Query operators ($gt, $in, ...) — leave them as-is, or treat them as ordinary field names?

If the direction is right, I'd add a mongo_obfuscate module alongside sql_obfuscate with unit tests covering the document walker, and wire it at the four places in mongo.rs that serialize a document. Happy to adjust the split if you'd prefer it elsewhere.

  1. It is best to maintain consistency with SQL to keep the logic simpler.
  2. The implementation should incur minimal performance overhead, avoiding recursive traversal whenever possible. The data in the trace records should primarily indicate when an operation was performed on a specific piece of data within a document, what that operation was, and the outcome (success or failure, along with the time taken). Other information can be retrieved from logs or similar sources.
  3. Operators can remain as they are.

letian0805 avatar Oct 27 '26 09:10 letian0805