By · Last updated 2026-06-05

返回博客技术

应用日志中的 GDPR 合规:JSON PII 脱敏实践

应用日志中包含客户邮箱地址、IP 地址和账户号码,GDPR 第 5 条第 1 款 (e) 项对此有明确的管理要求。

June 5, 20266 分钟阅读
API logsGDPR complianceJSON anonymizationobservabilitystorage limitation

日志系统中被忽视的 GDPR 风险

2026 年更新版

大多数团队会检查数据库中的个人信息,却很少对日志系统做同样的事。

GDPR 第 5 条第 1 款 (e) 项对个人信息的存储时限有明确要求。针对数据库,团队会制定策略并运行删除任务;针对日志文件,规则往往简单粗暴:调试需要,保留 90 天。

问题在于:这些记录包含个人信息。请求日志包含用户邮箱,错误日志包含原始输入值,访问日志包含 IP 地址。在 GDPR 框架下,这些都属于个人信息。您的团队需要为每一项提供合法依据和保留计划。

什么内容会进入您的日志文件

标准 Web 应用日志记录会抓取大量个人身份信息。

访问记录(nginx/Apache):

  • IP 地址——根据欧洲数据保护委员会指南属于个人信息
  • User-Agent 字符串——可能支持设备指纹识别
  • 会话令牌——如果写入输出的话

应用记录(结构化 JSON):

  • 用户 ID 和邮箱地址
  • 输入错误——通常包含原始无效值,而该值可能是真实用户信息
  • 业务事件——关联客户账户的订单 ID
  • 搜索查询——可能含有姓名或地址

API 网关记录:

  • 授权头——部分配置下会被截取
  • 查询参数——可能携带用户 ID、姓名或邮箱
  • 请求与响应体——在 debug 级别配置下存在

数据库审计条目:

  • 含有 email = 'user@example.com' 等 WHERE 子句的 SQL 查询
  • 查询参数中的个人信息字面量

这并非有意为之,而是为调试目的构建的日志系统的副作用,而非为 GDPR 而设计。

欧洲数据保护委员会关于 IP 地址的指南

欧洲数据保护委员会明确指出,IP 地址属于个人信息。互联网服务商可以将其与用户关联,在组织内部也可以识别具体用户。

这直接带来影响:包含 IP 地址的访问记录即为个人记录;将 nginx 输出保留 12 个月,意味着将个人信息保留 12 个月,需要第 6 条规定的合法依据,且保留期限必须与您声明的目的相匹配。

大多数团队忽略了这一步。「安全部门要求保留 90 天」是一条经验法则,而非 GDPR 第 5 条第 1 款 (e) 项意义上的合规审查。关于如何将此纳入完整合规方案,请参阅我们的法律合规概览

如何实现合规

对大多数团队而言,实用路径并非缩短保留窗口——运营和安全层面确实需要较长的保留期。更好的做法是在长期存储前对记录进行脱敏。

分层模型效果良好。

0 至 7 天: 完整原始记录,供主动调试使用。七天对大多数团队来说足够短。

7 至 90 天: 脱敏记录,用于趋势分析和安全审查。IP 地址被替换,用户邮箱变为稳定令牌,账户号码经过脱敏处理。时间戳、错误代码、延迟值、端点等关键字段保持不变。

90 天以上(如有需要): 仅保留聚合输出:事件计数、错误率、延迟范围。不保留任何用户级记录。

个人信息在七天后即停止存储;聚合输出可继续保留,且不会暴露任何人。更多详情请参阅安全与合规页面

保持结构完整以支持监控

良好的脱敏在保持 JSON 结构完整的同时,仅替换内容值。这样日志才能继续为调试和告警所用。

保持不变:

  • JSON 键名和嵌套结构
  • 时间戳和时序
  • 错误类型和 HTTP 状态码
  • HTTP 方法、路径和延迟值
  • 业务事件类型

替换内容:

  • 邮箱地址 → 按原始值生成的稳定令牌(如 user1@example.com
  • IP 地址 → RFC 5737 地址段(192.0.2.x
  • 账户号码 → ACCT_XXXXX
  • 电话号码 → +XX XXX XXX XXXX
  • 错误文本中的姓名 → [PERSON]

稳定令牌保证了追踪价值——user1@example.com 的 40 条跨记录追踪,与原始记录一样好用。聚合指标——错误率、延迟、吞吐量——根本不需要个人信息。关于「假名化」和「匿名化」的定义,请参阅术语表

三种集成方案

以下三种方案覆盖大多数工程团队的需求。

方案一——管道脱敏: Fluentd 或 Logstash 在每行发送前进行拦截,内联运行脱敏步骤。Elastic 或 Datadog 只收到经过清理的记录,无需修改应用代码。

方案二——夜间批处理: 原始记录落入本地存储,夜间任务对前一天的输出进行脱敏并删除原始版本,脱敏记录进入长期存储,原始输出仅保留七天。

方案三——分享前脱敏: 原始记录在严格访问控制下保留在内部,在与渗透测试人员或外部承包商分享前运行脱敏处理,外部人员始终只看到干净的版本。

对于 GDPR 文档而言,脱敏是第 32 条规定的「技术措施」。请在第 30 条规定的处理活动记录(RoPA)中记录工具、配置和保留策略。关于 RoPA 常见问题,请参阅 FAQ

想了解真实案例?请查看案例研究获取具体的实施细节。您也可以查看定价页面,了解哪个方案内置了脱敏管道。

参考资料

准备好保护您的数据了吗?

开始使用 285 种实体类型在 48 种语言中匿名化 PII。

About this page

We update this page when our platform or the law changes.

Read our founder note for how we work.

Each change shows up in the timestamp at the top.

Related reading

We follow these rules

  • GDPR (EU 2016/679).
  • ISO/IEC 27001:2022.
  • NIS2 (EU 2022/2555).
  • HIPAA safe harbor under 45 CFR § 164.514(b)(2).

Our promise

We do not sell your data.

We do not train models on your text.

We store your files in Germany.

You can delete your account at any time.

You own your work.

Where we run

Our servers live in Falkenstein, Germany.

We use Hetzner. They hold ISO 27001 certification.

All data stays in the EU.

Backups run every day.

Need help?

Email support@anonym.legal.

We reply within one business day.

How we test

We run a full check suite on every release.

Each surface gets its own sweep script and report.

Human reviewers spot-check the output each week.

We track recall and precision on a labelled set.

Bad runs block the deploy.

What we never do

  • We never sell your information to third parties.
  • We never train models on what you upload.
  • We never keep your work after you delete it.
  • We never share keys with any outside firm.
  • We never run ads inside the product.

Plans in plain words

We sell credits, not seats.

One credit covers one short job.

Long jobs use a few credits each.

You can top up at any time.

Unused credits roll over each month.

Read the plans page for current rates.

Who built this

A small team of engineers and lawyers built this.

We ship from Europe and work in the open.

Our founder note spells out why we started.

Where to start

How the parts fit

A browser add-on cleans text inside Chrome.

A Word plug-in handles drafts in Office.

A small desktop tool works on whole folders.

An agent protocol link feeds large models safely.

All four share one core engine and one rule set.

Words from our team

We started this work after a lunch about cookies.

One friend kept getting odd ads on her phone.

We asked why a court file leaked through a draft.

We sketched the first build on a napkin that week.

By month three we had a tiny demo for a friend.

She used it on her first case the next day.

Common questions we hear

Can the tool read scanned PDFs? Yes, with OCR.

Does it work on long files? Yes, in small chunks.

Can I roll my own rule set? Yes, save it as a preset.

Does it run offline? The desktop build runs offline.

Do you keep my files? No, the cloud build wipes after each run.

Will it learn from my work? No, we never train on inputs.

A short tour of the workflow

Upload a file or paste a snippet of prose.

Pick the entities you want gone from the draft.

Choose a method: replace, mask, hash, encrypt, or redact.

Press run and watch the side panel show each hit.

Skim the result and tweak any rule that misfired.

Save the cleaned file or send it to a teammate.