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 model
ThreatActorProposed mitigationResidual risk
Unapproved destinationNew code sending tagged fields to a third partySemgrep taint rules block the mergeUntagged fields are invisible
Consent driftService using a stale consent decisionProxy reads the consent store with short cache lifetimesA bounded propagation delay
Proxy bypassService calling the destination directlyEgress allowlist routes destinations through the proxyLegacy exceptions need review

Architecture

Proposed request flow
  1. Pull requestSemgrep scans for tagged-data flows
  2. Runtime proxyChecks consent and purpose
  3. DestinationReceives only permitted fields
The scanner moves most problems into code review. The proxy enforces the same policy at runtime for anything that slips through.

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.

proxy/consent.goIllustrative
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