P-02 · Design doc
Privacy Flow Guard
A proposed two-layer control: a code scanner that blocks forbidden data flows before merge, and a runtime proxy that enforces each user’s consent settings.
Problem
Privacy rules usually live in documents and review meetings. Code changes faster than reviewers can read it, so a new analytics call can quietly send an email address somewhere it was never allowed to go. Enforcement has to happen in the merge pipeline and on the request path.
Goals and non-goals
Goals
- Tag personal-data fields and fail CI when tagged data flows to an unapproved destination.
- Check consent per user and per purpose on the request path.
- Log every denial with the rule and data category involved.
Non-goals
- Give a legal opinion on GDPR or CCPA compliance.
- Catch flows through code the scanner cannot see, such as dynamic reflection.
Threat model
Assume well-meaning engineers ship code that mishandles personal data. The guard trusts the field tags and the consent store, not the calling service.
| Threat | Actor | Proposed mitigation | Residual risk |
|---|---|---|---|
| Unapproved destination | New code sending tagged fields to a third party | Semgrep taint rules block the merge | Untagged fields are invisible |
| Consent drift | Service using a stale consent decision | Proxy reads the consent store with short cache lifetimes | A bounded propagation delay |
| Proxy bypass | Service calling the destination directly | Egress allowlist routes destinations through the proxy | Legacy exceptions need review |
Architecture
- Pull requestSemgrep scans for tagged-data flows
- Runtime proxyChecks consent and purpose
- DestinationReceives only permitted fields
Alternatives considered
Manual privacy review
Thoughtful, but slow, and it does not scale to every pull request.
Pattern-based data loss prevention
Catches things that look like emails but knows nothing about consent or purpose.
Tagged fields, scanner, and proxy
More setup, but one policy is enforced in both CI and production.
Implementation
Simplified proxy check. Field categories come from schema tags, and consent comes from the consent store.
func Allowed(c Consent, req FlowRequest, now time.Time) bool {
if c.Revoked || now.After(c.ExpiresAt) {
return false
}
for _, field := range req.Fields {
if !c.Permits(field.Category, req.Purpose) {
return false
}
}
return true
}Postmortem
No prototype failure has been recorded yet. This is the first failure scenario to test.
- Failure to test
- A field is renamed and loses its personal-data tag.
- Next test
- Rename a tagged field in a test service and verify CI still fails because the tag lives on the schema, not the variable name.
Results
No measurements yet. These are the proposed metrics.
- Forbidden flows caught in CINot yet measured
- False positives per 100 pull requestsNot yet measured
- Latency the proxy adds per requestNot yet measured